diff --git a/README.md b/README.md index 33b2821fd..940c508a5 100644 --- a/README.md +++ b/README.md @@ -214,6 +214,7 @@ View contents * [`anagrams`](#anagrams) +* [`byteSize`](#bytesize) * [`capitalize`](#capitalize) * [`capitalizeEveryWord`](#capitalizeeveryword) * [`countVowels`](#countvowels) @@ -259,15 +260,6 @@ -### _Uncategorized_ - -
-View contents - -* [`byteSize`](#bytesize) - -
- ## Adapter ### call @@ -3249,6 +3241,29 @@ anagrams('abc'); // ['abc','acb','bac','bca','cab','cba']
[⬆ Back to top](#table-of-contents) +### byteSize + +Returns the length of string. + +Convert a given string to a [`Blob` Object](https://developer.mozilla.org/en-US/docs/Web/API/Blob) and find its `size`. + +```js +const byteSize = str => new Blob([str]).size; +``` + +
+Examples + +```js +byteSize('😀'); // 4 +byteSize('Hello World'); // 11 +``` + +
+ +
[⬆ Back to top](#table-of-contents) + + ### Capitalize Capitalizes the first letter of a string. @@ -4143,25 +4158,6 @@ validateNumber('10'); // true
[⬆ Back to top](#table-of-contents) -## _Uncategorized_ - -### byteSize - -Returns the length of string. - -Convert a given string to a [`Blob` Object](https://developer.mozilla.org/en-US/docs/Web/API/Blob) and find its `size`. - -```js -const byteSize = str => new Blob([str]).size; -``` - -```js -byteSize('😀'); // 4 -byteSize('Hello World'); // 11 -``` - -
[⬆ back to top](#table-of-contents) - ## Credits diff --git a/docs/index.html b/docs/index.html index c02a63d29..a5cbe91de 100644 --- a/docs/index.html +++ b/docs/index.html @@ -59,7 +59,7 @@ wrapper.appendChild(box); box.appendChild(el); }); - }

 30 seconds of code Curated collection of useful JavaScript snippets that you can understand in 30 seconds or less.

 

Adapter

call

Given a key and a set of arguments, call them when given a context. Primarily useful in composition.

Use a closure to call a stored key with stored arguments.

const call = (key, ...args) => context => context[key](...args);
+    }

 30 seconds of code Curated collection of useful JavaScript snippets that you can understand in 30 seconds or less.

 

Adapter

call

Given a key and a set of arguments, call them when given a context. Primarily useful in composition.

Use a closure to call a stored key with stored arguments.

const call = (key, ...args) => context => context[key](...args);
 
Promise.resolve([1, 2, 3])
   .then(call('map', x => 2 * x))
   .then(console.log); //[ 2, 4, 6 ]
@@ -636,6 +636,9 @@ a === b; // false
     );
 };
 
anagrams('abc'); // ['abc','acb','bac','bca','cab','cba']
+

byteSize

Returns the length of string.

Convert a given string to a Blob Object and find its size.

const byteSize = str => new Blob([str]).size;
+
byteSize('😀'); // 4
+byteSize('Hello World'); // 11
 

Capitalize

Capitalizes the first letter of a string.

Use destructuring and toUpperCase() to capitalize first letter, ...rest to get array of characters after first letter and then Array.join('') to make it a string again. Omit the lowerRest parameter to keep the rest of the string intact, or set it to true to convert to lowercase.

const capitalize = ([first, ...rest], lowerRest = false) =>
   first.toUpperCase() + (lowerRest ? rest.join('').toLowerCase() : rest.join(''));
 
capitalize('fooBar'); // 'FooBar'
@@ -842,7 +845,4 @@ console.log(sdbm('age')); // 808122783
 
toOrdinalSuffix('123'); // "123rd"
 

validateNumber

Returns true if the given value is a number, false otherwise.

Use !isNaN in combination with parseFloat() to check if the argument is a number. Use isFinite() to check if the number is finite. Use Number() to check if the coercion holds.

const validateNumber = n => !isNaN(parseFloat(n)) && isFinite(n) && Number(n) == n;
 
validateNumber('10'); // true
-

Uncategorized

byteSize

Returns the length of string.

Convert a given string to a Blob Object and find its size.

const byteSize = str => new Blob([str]).size;
-
byteSize('😀'); // 4
-byteSize('Hello World'); // 11
 

\ No newline at end of file