diff --git a/README.md b/README.md index 9b8048e10..3203b69a1 100644 --- a/README.md +++ b/README.md @@ -3658,7 +3658,7 @@ Replaces all but the last `num` of characters with the specified mask character. Use `String.slice()` to grab the portion of the characters that need to be masked and use `String.replace()` with a regex to replace every character with the mask character. Concatenate the masked characters with the remaining unmasked portion of the string. -Omit the second argument, `num`, to keep a default of `4` characters unmasked. +Omit the second argument, `num`, to keep a default of `4` characters unmasked. If `num` is negative, the unmasked characters will be at the start of the string. Omit the third argument, `mask`, to use a default character of `'*'` for the mask. ```js @@ -4186,15 +4186,14 @@ isArray([1]); // true Checks if the provided argument is array-like (i.e. is iterable). -Check that the object is not a function or `null` and that its `length` property is a non-negative integer below `Number.MAX_SAFE_INTEGER`. +Use the spread operator (`...`) to check if the provided argument is iterable inside a `try... catch` block and the comma operator (`,`) to return the appropriate value. ```js + const isArrayLike = val => - val != null && - typeof val != 'function' && - val.length > -1 && - val.length % 1 == 0 && - val.length <= Number.MAX_SAFE_INTEGER; + try {return [...val], true; } + catch (e) { return false; } +}; ```
diff --git a/docs/index.html b/docs/index.html index c1a7a5fc3..6951935aa 100644 --- a/docs/index.html +++ b/docs/index.html @@ -740,7 +740,7 @@ fromCamelCase('someJavascriptProperty', '_'); // 'some_javascript_property'
isAbsoluteURL('https://google.com'); // true
 isAbsoluteURL('ftp://www.myserver.net'); // true
 isAbsoluteURL('/foo/bar'); // false
-

mask

Replaces all but the last num of characters with the specified mask character.

Use String.slice() to grab the portion of the characters that need to be masked and use String.replace() with a regex to replace every character with the mask character. Concatenate the masked characters with the remaining unmasked portion of the string. Omit the second argument, num, to keep a default of 4 characters unmasked. Omit the third argument, mask, to use a default character of '*' for the mask.

const mask = (cc, num = 4, mask = '*') =>
+

mask

Replaces all but the last num of characters with the specified mask character.

Use String.slice() to grab the portion of the characters that need to be masked and use String.replace() with a regex to replace every character with the mask character. Concatenate the masked characters with the remaining unmasked portion of the string. Omit the second argument, num, to keep a default of 4 characters unmasked. If num is negative, the unmasked characters will be at the start of the string. Omit the third argument, mask, to use a default character of '*' for the mask.

const mask = (cc, num = 4, mask = '*') =>
   ('' + cc).slice(0, -num).replace(/./g, mask) + ('' + cc).slice(-num);
 
mask(1234567890); // '******7890'
 mask(1234567890, 3); // '*******890'
@@ -878,12 +878,11 @@ hexToRGB('#fff'); // 'rgb(255, 255, 255)'
 

isArray

Checks if the given argument is an array.

Use Array.isArray() to check if a value is classified as an array.

const isArray = val => !!val && Array.isArray(val);
 
isArray(null); // false
 isArray([1]); // true
-

isArrayLike

Checks if the provided argument is array-like (i.e. is iterable).

Check that the object is not a function or null and that its length property is a non-negative integer below Number.MAX_SAFE_INTEGER.

const isArrayLike = val =>
-  val != null &&
-  typeof val != 'function' &&
-  val.length > -1 &&
-  val.length % 1 == 0 &&
-  val.length <= Number.MAX_SAFE_INTEGER;
+

isArrayLike

Checks if the provided argument is array-like (i.e. is iterable).

Use the spread operator (...) to check if the provided argument is iterable inside a try... catch block and the comma operator (,) to return the appropriate value.


+const isArrayLike = val =>
+  try {return [...val], true; }
+  catch (e)  { return false; }
+};
 
isArrayLike(document.querySelectorAll('.className')); // true
 isArrayLike('abc'); // true
 isArrayLike(null); // false
diff --git a/snippets/isArrayLike.md b/snippets/isArrayLike.md
index b5fe545e8..47a3fe158 100644
--- a/snippets/isArrayLike.md
+++ b/snippets/isArrayLike.md
@@ -5,6 +5,7 @@ Checks if the provided argument is array-like (i.e. is iterable).
 Use the spread operator (`...`) to check if the provided argument is iterable inside a `try... catch` block and the comma operator (`,`) to return the appropriate value.
 
 ```js
+
 const isArrayLike = val =>
   try {return [...val], true; }
   catch (e)  { return false; }