string
import { toDotNotation, toDashedNotation } from '@bbc/front-end-kit/js/utils/string';
Utility functions for transforming strings.
toDotNotation(input)
Converts a string to lowercase dot-separated notation. Non-alphanumeric characters (except spaces) are removed; spaces are replaced with dots.
Parameters
input(string): The string to transform.
Returns
string
Example
import { toDotNotation } from '@bbc/front-end-kit/js/utils/string';
toDotNotation('Hello World'); // 'hello.world'
toDotNotation('Foo & Bar'); // 'foo.bar'
toDotNotation('My Key Here'); // 'my.key.here'
toDashedNotation(input)
Converts a string to lowercase dash-separated notation. Non-alphanumeric characters (except spaces) are removed; spaces are replaced with dashes.
Parameters
input(string): The string to transform.
Returns
string
Example
import { toDashedNotation } from '@bbc/front-end-kit/js/utils/string';
toDashedNotation('Hello World'); // 'hello-world'
toDashedNotation('Foo & Bar'); // 'foo-bar'
toDashedNotation('My Key Here'); // 'my-key-here'