From 8bd99f2c881e2e27a74541ec1da65e30d50be69d Mon Sep 17 00:00:00 2001 From: Travis CI Date: Mon, 1 Jan 2018 12:42:53 +0000 Subject: [PATCH] Travis build: 768 [ci skip] --- README.md | 25 +++++++++++++++++++++++++ docs/index.html | 8 +++++++- snippets/mask.md | 12 ++++++------ tag_database | 1 + 4 files changed, 39 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index de52ae0c2..f7bd918b7 100644 --- a/README.md +++ b/README.md @@ -273,6 +273,7 @@ View contents * [`join`](#join) +* [`mask`](#mask) * [`sortedIndex`](#sortedindex) @@ -4619,6 +4620,30 @@ join(['pen', 'pineapple', 'apple', 'pen']); //"pen,pineapple,apple,pen"
[⬆ back to top](#table-of-contents) +### 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. + +```js +const mask = (cc, num = 4, mask = '*') => + ('' + cc).slice(0, -num).replace(/./g, mask) + ('' + cc).slice(-num); +``` + +```js +mask(1234567890); // '******7890' +mask(1234567890, 3); // '*******890' +mask(1234567890, 4, '$'); // '$$$$$$7890' +mask(1234567890, -4, '$'); // '1234$$$$$$' +``` + +
[⬆ back to top](#table-of-contents) + + ### sortedIndex Returns the lowest index at which value should be inserted into array in order to maintain its sort order. diff --git a/docs/index.html b/docs/index.html index 5f00a7d48..3f4346954 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 ]
@@ -978,6 +978,12 @@ yesNo('Foo', true); // true
 join(['pen', 'pineapple', 'apple', 'pen'], ',', '&'); //"pen,pineapple,apple&pen"
 join(['pen', 'pineapple', 'apple', 'pen'], ','); //"pen,pineapple,apple,pen"
 join(['pen', 'pineapple', 'apple', 'pen']); //"pen,pineapple,apple,pen"
+

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 = '*') =>
+  ('' + cc).slice(0, -num).replace(/./g, mask) + ('' + cc).slice(-num);
+
mask(1234567890); // '******7890'
+mask(1234567890, 3); // '*******890'
+mask(1234567890, 4, '$'); // '$$$$$$7890'
+mask(1234567890, -4, '$'); // '1234$$$$$$'
 

sortedIndex

Returns the lowest index at which value should be inserted into array in order to maintain its sort order.

Check if the array is sorted in descending order (loosely). Use Array.findIndex() to find the appropriate index where the element should be inserted.

const sortedIndex = (arr, n) => {
   const isDescending = arr[0] > arr[arr.length - 1];
   const index = arr.findIndex(el => (isDescending ? n >= el : n <= el));
diff --git a/snippets/mask.md b/snippets/mask.md
index c030d0828..11983e0af 100644
--- a/snippets/mask.md
+++ b/snippets/mask.md
@@ -8,13 +8,13 @@ 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.
 
 ```js
-const mask = (cc,num = 4,mask = '*') =>
-   ('' + cc).slice(0, -num).replace(/./g, mask) + ('' + cc).slice(-num);
+const mask = (cc, num = 4, mask = '*') =>
+  ('' + cc).slice(0, -num).replace(/./g, mask) + ('' + cc).slice(-num);
 ```
 
 ```js
-mask(1234567890) // '******7890'
-mask(1234567890,3) // '*******890'
-mask(1234567890,4,'$') // '$$$$$$7890'
-mask(1234567890,-4,'$') // '1234$$$$$$'
+mask(1234567890); // '******7890'
+mask(1234567890, 3); // '*******890'
+mask(1234567890, 4, '$'); // '$$$$$$7890'
+mask(1234567890, -4, '$'); // '1234$$$$$$'
 ```
diff --git a/tag_database b/tag_database
index 6943467cc..ff8253483 100644
--- a/tag_database
+++ b/tag_database
@@ -88,6 +88,7 @@ last:array
 lcm:math
 lowercaseKeys:object
 mapObject:array
+mask:uncategorized
 max:math
 median:math
 memoize:function