Merge branch 'master' into pipeAsyncFunctions
This commit is contained in:
@ -5095,8 +5095,6 @@ UUIDGeneratorNode(); // '79c7c136-60ee-40a2-beb2-856f1feabefc'
|
||||
|
||||
### bindAll
|
||||
|
||||
Explain briefly what the snippet does.
|
||||
|
||||
Use `Array.forEach()` to return a `function` that uses `Function.apply()` to apply the given context (`obj`) to `fn` for each function specified.
|
||||
|
||||
```js
|
||||
|
||||
@ -1137,7 +1137,7 @@ console<span class="token punctuation">.</span><span class="token function">log<
|
||||
<span class="token punctuation">(</span>c <span class="token operator">^</span> <span class="token punctuation">(</span>crypto<span class="token punctuation">.</span><span class="token function">randomBytes</span><span class="token punctuation">(</span><span class="token number">1</span><span class="token punctuation">)[</span><span class="token number">0</span><span class="token punctuation">]</span> <span class="token operator">&</span> <span class="token punctuation">(</span><span class="token number">15</span> <span class="token operator">>></span> <span class="token punctuation">(</span>c <span class="token operator">/</span> <span class="token number">4</span><span class="token punctuation">)))).</span><span class="token function">toString</span><span class="token punctuation">(</span><span class="token number">16</span><span class="token punctuation">)
|
||||
);</span>
|
||||
</pre><label class="collapse">Show examples</label><pre class="language-js"><span class="token function">UUIDGeneratorNode</span><span class="token punctuation">();</span> <span class="token comment">// '79c7c136-60ee-40a2-beb2-856f1feabefc'</span>
|
||||
</pre><button class="primary clipboard-copy">📋 Copy to clipboard</button></div></div><h2 style="text-align:center">Object</h2><div class="card fluid"><h3 id="bindall" class="section double-padded">bindAll</h3><div class="section double-padded"><p>Explain briefly what the snippet does.</p><p>Use <code>Array.forEach()</code> to return a <code>function</code> that uses <code>Function.apply()</code> to apply the given context (<code>obj</code>) to <code>fn</code> for each function specified.</p><pre class="language-js"><span class="token keyword">const</span> <span class="token function-variable function">bindAll</span> <span class="token operator">=</span> <span class="token punctuation">(</span>obj<span class="token punctuation">,</span> <span class="token operator">...</span>fns<span class="token punctuation">)</span> <span class="token operator">=></span>
|
||||
</pre><button class="primary clipboard-copy">📋 Copy to clipboard</button></div></div><h2 style="text-align:center">Object</h2><div class="card fluid"><h3 id="bindall" class="section double-padded">bindAll</h3><div class="section double-padded"><p>Use <code>Array.forEach()</code> to return a <code>function</code> that uses <code>Function.apply()</code> to apply the given context (<code>obj</code>) to <code>fn</code> for each function specified.</p><pre class="language-js"><span class="token keyword">const</span> <span class="token function-variable function">bindAll</span> <span class="token operator">=</span> <span class="token punctuation">(</span>obj<span class="token punctuation">,</span> <span class="token operator">...</span>fns<span class="token punctuation">)</span> <span class="token operator">=></span>
|
||||
fns<span class="token punctuation">.</span><span class="token function">forEach</span><span class="token punctuation">(</span>
|
||||
fn <span class="token operator">=></span>
|
||||
<span class="token punctuation">(</span>obj<span class="token punctuation">[</span>fn<span class="token punctuation">]</span> <span class="token operator">=</span> <span class="token keyword">function</span><span class="token punctuation">() {</span>
|
||||
|
||||
@ -1,7 +1,5 @@
|
||||
### bindAll
|
||||
|
||||
Explain briefly what the snippet does.
|
||||
|
||||
Use `Array.forEach()` to return a `function` that uses `Function.apply()` to apply the given context (`obj`) to `fn` for each function specified.
|
||||
|
||||
```js
|
||||
|
||||
@ -5,9 +5,19 @@ test('Testing round', (t) => {
|
||||
//For more information on all the methods supported by tape
|
||||
//Please go to https://github.com/substack/tape
|
||||
t.true(typeof round === 'function', 'round is a Function');
|
||||
t.equal(round(1.005, 2), 1.01, "Rounds a number to a specified amount of digits.");
|
||||
//t.equal(round(args..), 'Expected');
|
||||
//t.false(round(args..), 'Expected');
|
||||
//t.throws(round(args..), 'Expected');
|
||||
t.equal(round(1.005, 2), 1.01, "round(1.005, 2) returns 1.01");
|
||||
t.equal(round(123.3423345345345345344, 11), 123.34233453453, "round(123.3423345345345345344, 11) returns 123.34233453453");
|
||||
t.equal(round(3.342, 11), 3.342, "round(3.342, 11) returns 3.342");
|
||||
t.equal(round(1.005), 1, "round(1.005) returns 1");
|
||||
t.true(isNaN(round([1.005, 2])), 'round([1.005, 2]) returns NaN');
|
||||
t.true(isNaN(round('string')), 'round(string) returns NaN');
|
||||
t.true(isNaN(round()), 'round() returns NaN');
|
||||
t.true(isNaN(round(132, 413, 4134)), 'round(132, 413, 4134) returns NaN');
|
||||
t.true(isNaN(round({a: 132}, 413)), 'round({a: 132}, 413) returns NaN');
|
||||
|
||||
let start = new Date().getTime();
|
||||
round(123.3423345345345345344, 11);
|
||||
let end = new Date().getTime();
|
||||
t.true((end - start) < 2000, 'round(123.3423345345345345344, 11) takes less than 2s to run');
|
||||
t.end();
|
||||
});
|
||||
@ -5,13 +5,18 @@ test('Testing toCamelCase', (t) => {
|
||||
//For more information on all the methods supported by tape
|
||||
//Please go to https://github.com/substack/tape
|
||||
t.true(typeof toCamelCase === 'function', 'toCamelCase is a Function');
|
||||
t.equal(toCamelCase('some_database_field_name'), 'someDatabaseFieldName', "Converts a string to camelCase");
|
||||
t.equal(toCamelCase('Some label that needs to be camelized'), 'someLabelThatNeedsToBeCamelized', "Converts a string to camelCase");
|
||||
t.equal(toCamelCase('some-javascript-property'), 'someJavascriptProperty', "Converts a string to camelCase");
|
||||
t.equal(toCamelCase('some-mixed_string with spaces_underscores-and-hyphens'), 'someMixedStringWithSpacesUnderscoresAndHyphens', "Converts a string to camelCase");
|
||||
//t.deepEqual(toCamelCase(args..), 'Expected');
|
||||
//t.equal(toCamelCase(args..), 'Expected');
|
||||
//t.false(toCamelCase(args..), 'Expected');
|
||||
//t.throws(toCamelCase(args..), 'Expected');
|
||||
t.equal(toCamelCase('some_database_field_name'), 'someDatabaseFieldName', "toCamelCase('some_database_field_name') returns someDatabaseFieldName");
|
||||
t.equal(toCamelCase('Some label that needs to be camelized'), 'someLabelThatNeedsToBeCamelized', "toCamelCase('Some label that needs to be camelized') returns someLabelThatNeedsToBeCamelized");
|
||||
t.equal(toCamelCase('some-javascript-property'), 'someJavascriptProperty', "toCamelCase('some-javascript-property') return someJavascriptProperty");
|
||||
t.equal(toCamelCase('some-mixed_string with spaces_underscores-and-hyphens'), 'someMixedStringWithSpacesUnderscoresAndHyphens', "toCamelCase('some-mixed_string with spaces_underscores-and-hyphens') returns someMixedStringWithSpacesUnderscoresAndHyphens");
|
||||
t.throws(() => toCamelCase(), 'toCamelCase() throws a error');
|
||||
t.throws(() => toCamelCase([]), 'toCamelCase([]) throws a error');
|
||||
t.throws(() => toCamelCase({}), 'toCamelCase({}) throws a error');
|
||||
t.throws(() => toCamelCase(123), 'toCamelCase(123) throws a error');
|
||||
|
||||
let start = new Date().getTime();
|
||||
toCamelCase('some-mixed_string with spaces_underscores-and-hyphens');
|
||||
let end = new Date().getTime();
|
||||
t.true((end - start) < 2000, 'toCamelCase(some-mixed_string with spaces_underscores-and-hyphens) takes less than 2s to run');
|
||||
t.end();
|
||||
});
|
||||
@ -5,13 +5,18 @@ test('Testing toKebabCase', (t) => {
|
||||
//For more information on all the methods supported by tape
|
||||
//Please go to https://github.com/substack/tape
|
||||
t.true(typeof toKebabCase === 'function', 'toKebabCase is a Function');
|
||||
t.equal(toKebabCase('camelCase'), 'camel-case', "string converts to snake case");
|
||||
t.equal(toKebabCase('some text'), 'some-text', "string converts to snake case");
|
||||
t.equal(toKebabCase('some-mixed-string With spaces-underscores-and-hyphens'), 'some-mixed-string-with-spaces-underscores-and-hyphens', "string converts to snake case");
|
||||
t.equal(toKebabCase('IAmListeningToFMWhileLoadingDifferentURLOnMyBrowserAndAlsoEditingSomeXMLAndHTML'), 'i-am-listening-to-fm-while-loading-different-url-on-my-browser-and-also-editing-some-xml-and-html', "string converts to snake case");
|
||||
//t.deepEqual(toKebabCase(args..), 'Expected');
|
||||
//t.equal(toKebabCase(args..), 'Expected');
|
||||
//t.false(toKebabCase(args..), 'Expected');
|
||||
//t.throws(toKebabCase(args..), 'Expected');
|
||||
t.equal(toKebabCase('camelCase'), 'camel-case', "toKebabCase('camelCase') returns camel-case");
|
||||
t.equal(toKebabCase('some text'), 'some-text', "toKebabCase('some text') returns some-text");
|
||||
t.equal(toKebabCase('some-mixed-string With spaces-underscores-and-hyphens'), 'some-mixed-string-with-spaces-underscores-and-hyphens', "toKebabCase('some-mixed-string With spaces-underscores-and-hyphens') returns some-mixed-string-with-spaces-underscores-and-hyphens");
|
||||
t.equal(toKebabCase('IAmListeningToFMWhileLoadingDifferentURLOnMyBrowserAndAlsoEditingSomeXMLAndHTML'), 'i-am-listening-to-fm-while-loading-different-url-on-my-browser-and-also-editing-some-xml-and-html', "toKebabCase('IAmListeningToFMWhileLoadingDifferentURLOnMyBrowserAndAlsoEditingSomeXMLAndHTML') returns i-am-listening-to-fm-while-loading-different-url-on-my-browser-and-also-editing-some-xml-and-html");
|
||||
t.equal(toKebabCase(), undefined, 'toKebabCase() return undefined');
|
||||
t.throws(() => toKebabCase([]), 'toKebabCase([]) throws an error');
|
||||
t.throws(() => toKebabCase({}), 'toKebabCase({}) throws an error');
|
||||
t.throws(() => toKebabCase(123), 'toKebabCase(123) throws an error');
|
||||
|
||||
let start = new Date().getTime();
|
||||
toKebabCase('IAmListeningToFMWhileLoadingDifferentURLOnMyBrowserAndAlsoEditingSomeXMLAndHTML')
|
||||
let end = new Date().getTime();
|
||||
t.true((end - start) < 2000, 'toKebabCase(IAmListeningToFMWhileLoadingDifferentURLOnMyBrowserAndAlsoEditingSomeXMLAndHTML) takes less than 2s to run');
|
||||
t.end();
|
||||
});
|
||||
@ -5,14 +5,20 @@ test('Testing toSafeInteger', (t) => {
|
||||
//For more information on all the methods supported by tape
|
||||
//Please go to https://github.com/substack/tape
|
||||
t.true(typeof toSafeInteger === 'function', 'toSafeInteger is a Function');
|
||||
t.true(Number(toSafeInteger(3.2)), 'Number(toSafeInteger(3.2)) is a number');
|
||||
t.equal(toSafeInteger(3.2), 3, "Converts a value to a safe integer");
|
||||
t.equal(toSafeInteger('4.2'), 4, "Converts a value to a safe integer");
|
||||
t.equal(toSafeInteger(4.6), 5, "Converts a value to a safe integer");
|
||||
t.equal(toSafeInteger(1.5), 2, "Converts a value to a safe integer");
|
||||
t.equal(toSafeInteger(Infinity), 9007199254740991, "Converts a value to a safe integer");
|
||||
//t.deepEqual(toSafeInteger(args..), 'Expected');
|
||||
//t.equal(toSafeInteger(args..), 'Expected');
|
||||
//t.false(toSafeInteger(args..), 'Expected');
|
||||
//t.throws(toSafeInteger(args..), 'Expected');
|
||||
t.equal(toSafeInteger('4.2'), 4, "toSafeInteger('4.2') returns 4");
|
||||
t.equal(toSafeInteger(4.6), 5, "toSafeInteger(4.6) returns 5");
|
||||
t.equal(toSafeInteger([]), 0, "toSafeInteger([]) returns 0");
|
||||
t.true(isNaN(toSafeInteger([1.5, 3124])), "isNaN(toSafeInteger([1.5, 3124])) is true");
|
||||
t.true(isNaN(toSafeInteger('string')), "isNaN(toSafeInteger('string')) is true");
|
||||
t.true(isNaN(toSafeInteger({})), "isNaN(toSafeInteger({})) is true");
|
||||
t.true(isNaN(toSafeInteger()), "isNaN(toSafeInteger()) is true");
|
||||
t.equal(toSafeInteger(Infinity), 9007199254740991, "toSafeInteger(Infinity) returns 9007199254740991");
|
||||
|
||||
let start = new Date().getTime();
|
||||
toSafeInteger(3.2);
|
||||
let end = new Date().getTime();
|
||||
t.true((end - start) < 2000, 'toSafeInteger(3.2) takes less than 2s to run');
|
||||
t.end();
|
||||
});
|
||||
@ -5,14 +5,18 @@ test('Testing toSnakeCase', (t) => {
|
||||
//For more information on all the methods supported by tape
|
||||
//Please go to https://github.com/substack/tape
|
||||
t.true(typeof toSnakeCase === 'function', 'toSnakeCase is a Function');
|
||||
t.equal(toSnakeCase('camelCase'), 'camel_case', "string converts to snake case");
|
||||
t.equal(toSnakeCase('some text'), 'some_text', "string converts to snake case");
|
||||
t.equal(toSnakeCase('some-mixed_string With spaces_underscores-and-hyphens'), 'some_mixed_string_with_spaces_underscores_and_hyphens', "string converts to snake case");
|
||||
t.equal(toSnakeCase('IAmListeningToFMWhileLoadingDifferentURLOnMyBrowserAndAlsoEditingSomeXMLAndHTML'), 'i_am_listening_to_fm_while_loading_different_url_on_my_browser_and_also_editing_some_xml_and_html', "string converts to snake case");
|
||||
t.equal(toSnakeCase('camelCase'), 'camel_case', "toSnakeCase('camelCase') returns camel_case");
|
||||
t.equal(toSnakeCase('some text'), 'some_text', "toSnakeCase('some text') returns some_text");
|
||||
t.equal(toSnakeCase('some-mixed_string With spaces_underscores-and-hyphens'), 'some_mixed_string_with_spaces_underscores_and_hyphens', "toSnakeCase('some-mixed_string With spaces_underscores-and-hyphens') returns some_mixed_string_with_spaces_underscores_and_hyphens");
|
||||
t.equal(toSnakeCase('IAmListeningToFMWhileLoadingDifferentURLOnMyBrowserAndAlsoEditingSomeXMLAndHTML'), 'i_am_listening_to_fm_while_loading_different_url_on_my_browser_and_also_editing_some_xml_and_html', "toSnakeCase('IAmListeningToFMWhileLoadingDifferentURLOnMyBrowserAndAlsoEditingSomeXMLAndHTML') returns i_am_listening_to_fm_while_loading_different_url_on_my_browser_and_also_editing_some_xml_and_html");
|
||||
t.equal(toSnakeCase(), undefined, 'toSnakeCase() returns undefined');
|
||||
t.throws(() => toSnakeCase([]), 'toSnakeCase([]) throws an error');
|
||||
t.throws(() => toSnakeCase({}), 'toSnakeCase({}) throws an error');
|
||||
t.throws(() => toSnakeCase(123), 'toSnakeCase(123) throws an error');
|
||||
|
||||
//t.deepEqual(toSnakeCase(args..), 'Expected');
|
||||
//t.equal(toSnakeCase(args..), 'Expected');
|
||||
//t.false(toSnakeCase(args..), 'Expected');
|
||||
//t.throws(toSnakeCase(args..), 'Expected');
|
||||
let start = new Date().getTime();
|
||||
toSnakeCase('IAmListeningToFMWhileLoadingDifferentURLOnMyBrowserAndAlsoEditingSomeXMLAndHTML');
|
||||
let end = new Date().getTime();
|
||||
t.true((end - start) < 2000, 'toSnakeCase(IAmListeningToFMWhileLoadingDifferentURLOnMyBrowserAndAlsoEditingSomeXMLAndHTML) takes less than 2s to run');
|
||||
t.end();
|
||||
});
|
||||
@ -5,10 +5,20 @@ test('Testing union', (t) => {
|
||||
//For more information on all the methods supported by tape
|
||||
//Please go to https://github.com/substack/tape
|
||||
t.true(typeof union === 'function', 'union is a Function');
|
||||
t.deepEqual(union([1, 2, 3], [4, 3, 2]), [1, 2, 3, 4], "Returns every element that exists in any of the two arrays once");
|
||||
//t.deepEqual(union(args..), 'Expected');
|
||||
//t.equal(union(args..), 'Expected');
|
||||
//t.false(union(args..), 'Expected');
|
||||
//t.throws(union(args..), 'Expected');
|
||||
t.deepEqual(union([1, 2, 3], [4, 3, 2]), [1, 2, 3, 4], "union([1, 2, 3], [4, 3, 2]) returns [1, 2, 3, 4]");
|
||||
t.deepEqual(union('str', 'asd'), [ 's', 't', 'r', 'a', 'd' ], "union('str', 'asd') returns [ 's', 't', 'r', 'a', 'd' ]");
|
||||
t.deepEqual(union([[], {}], [1, 2, 3]), [[], {}, 1, 2, 3], "union([[], {}], [1, 2, 3]) returns [[], {}, 1, 2, 3]");
|
||||
t.deepEqual(union([], []), [], "union([], []) returns []");
|
||||
t.throws(() => union(), 'union() throws an error');
|
||||
t.throws(() => union(true, 'str'), 'union(true, str) throws an error');
|
||||
t.throws(() => union('false', true), 'union(false, true) throws an error');
|
||||
t.throws(() => union(123, {}), 'union(123, {}) throws an error');
|
||||
t.throws(() => union([], {}), 'union([], {}) throws an error');
|
||||
t.throws(() => union(undefined, null), 'union(undefined, null) throws an error');
|
||||
|
||||
let start = new Date().getTime();
|
||||
union([1, 2, 3], [4, 3, 2]);
|
||||
let end = new Date().getTime();
|
||||
t.true((end - start) < 2000, 'union([1, 2, 3], [4, 3, 2]) takes less than 2s to run');
|
||||
t.end();
|
||||
});
|
||||
@ -5,10 +5,24 @@ test('Testing uniqueElements', (t) => {
|
||||
//For more information on all the methods supported by tape
|
||||
//Please go to https://github.com/substack/tape
|
||||
t.true(typeof uniqueElements === 'function', 'uniqueElements is a Function');
|
||||
t.deepEqual(uniqueElements([1, 2, 2, 3, 4, 4, 5]), [1,2,3,4,5], "Returns all unique values of an array");
|
||||
//t.deepEqual(uniqueElements(args..), 'Expected');
|
||||
//t.equal(uniqueElements(args..), 'Expected');
|
||||
//t.false(uniqueElements(args..), 'Expected');
|
||||
//t.throws(uniqueElements(args..), 'Expected');
|
||||
t.deepEqual(uniqueElements([1, 2, 2, 3, 4, 4, 5]), [1,2,3,4,5], "uniqueElements([1, 2, 2, 3, 4, 4, 5]) returns [1,2,3,4,5]");
|
||||
t.deepEqual(uniqueElements([1, 23, 53]), [1, 23, 53], "uniqueElements([1, 23, 53]) returns [1, 23, 53]");
|
||||
t.deepEqual(uniqueElements([true, 0, 1, false, false, undefined, null, '']), [true, 0, 1, false, undefined, null, ''], "uniqueElements([true, 0, 1, false, false, undefined, null, '']) returns [true, 0, 1, false, false, undefined, null, '']");
|
||||
t.deepEqual(uniqueElements(), [], "uniqueElements() returns []");
|
||||
t.deepEqual(uniqueElements(null), [], "uniqueElements(null) returns []");
|
||||
t.deepEqual(uniqueElements(undefined), [], "uniqueElements(undefined) returns []");
|
||||
t.deepEqual(uniqueElements('strt'), ['s', 't', 'r'], "uniqueElements('strt') returns ['s', 't', 'r']");
|
||||
t.throws(() => uniqueElements(1, 1, 2543, 534, 5), 'uniqueElements(1, 1, 2543, 534, 5) throws an error');
|
||||
t.throws(() => uniqueElements({}), 'uniqueElements({}) throws an error');
|
||||
t.throws(() => uniqueElements(true), 'uniqueElements(true) throws an error');
|
||||
t.throws(() => uniqueElements(false), 'uniqueElements(false) throws an error');
|
||||
|
||||
let start = new Date().getTime();
|
||||
uniqueElements([true, 0, 1, false, false, undefined, null, ''])
|
||||
let end = new Date().getTime();
|
||||
t.true((end - start) < 2000, 'uniqueElements([true, 0, 1, false, false, undefined, null]) takes less than 2s to run');
|
||||
|
||||
t.end();
|
||||
});
|
||||
|
||||
uniqueElements([1, 2, 2, '1', 4, 4, 4, 5, true]); // [1,2,3,4,5]
|
||||
|
||||
Reference in New Issue
Block a user