@uzelux/string

JS String Extension

Usage no npm install needed!

<script type="module">
  import uzeluxString from 'https://cdn.skypack.dev/@uzelux/string';
</script>

README

String Plus

An extension to the build-in String object


USAGE

// At your entry point (index.js || app.js)
require('@uzelux/string');

Capitalize

Capitalize the first character

'the quick brown fox jumps over lazy dog'.capitalize();
// 'A quick brown fox jumps over lazy dog'

ToCamelCase

Returns the calling string value converted to camelCase.

'the quick brown fox jumps over lazy dog'.toCamelCase();
// 'theQuickBrownFoxJumpsOverLazyDog'

ToPascalCase

Returns the calling string value converted to PascalCase.

'the quick brown fox jumps over lazy dog'.toPascalCase();
// 'TheQuickBrownFoxJumpsOverLazyDog'

ToSnakeCase

Returns the calling string value converted to snake_case.

'the quick brown fox jumps over lazy dog'.toSnakeCase();
// 'the_quick_brown_fox_jumps_over_lazy_dog'

ToKebabCase

Returns the calling string value converted to kebab-case.

'the quick brown fox jumps over lazy dog'.toKebabCase();
// 'the-quick-brown-fox-jumps-over-lazy-dog'

ToBinary

Returns the calling string value converted to binary string.

'the quick brown fox jumps over lazy dog'.toBinary();
// '1110100 1101000 1100101 100000 1110001 1110101 1101001 1100011 1101011 100000 1100010 1110010 1101111 1110111 1101110 100000 1100110 1101111 1111000 100000 1101010 1110101 1101101 1110000 1110011 100000 1101111 1110110 1100101 1110010 100000 1101100 1100001 1111010 1111001 100000 1100100 1101111 1100111'

Truncate

Extract a string to specified length and returns it as a new string, without modifying the original string.

'the quick brown fox jumps over lazy dog'.truncate(5);
// 'the q'

Reverse

Reverse a string and returns it as a new string, without modifying the original string.

'the quick brown fox jumps over lazy dog'.reverse();
// 'god yzal revo spmuj xof nworb kciuq eht'

IsString

Check if an variable is a String object instance or a string

String.isString('the quick brown fox jumps over lazy dog');
// true
String.isString({})
// false