diff --git a/README.md b/README.md index 112aa68c6..33b2821fd 100644 --- a/README.md +++ b/README.md @@ -259,6 +259,15 @@ +### _Uncategorized_ + +
+View contents + +* [`byteSize`](#bytesize) + +
+ ## Adapter ### call @@ -4134,6 +4143,25 @@ 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 a45295e6e..c02a63d29 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 ]
@@ -842,4 +842,7 @@ 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 diff --git a/snippets/byteSize.md b/snippets/byteSize.md index f55fcb931..5693da1ab 100644 --- a/snippets/byteSize.md +++ b/snippets/byteSize.md @@ -9,6 +9,6 @@ const byteSize = str => new Blob([str]).size; ``` ```js -byteSize("😀"); // 4 -byteSize("Hello World"); // 11 +byteSize('😀'); // 4 +byteSize('Hello World'); // 11 ``` diff --git a/tag_database b/tag_database index f5633a5fa..27aeb2dfd 100644 --- a/tag_database +++ b/tag_database @@ -2,6 +2,7 @@ anagrams:string arrayToHtmlList:browser average:math bottomVisible:browser +byteSize:uncategorized call:adapter capitalize:string capitalizeEveryWord:string