diff --git a/README.md b/README.md index 666bfe2b9..b3ae419a1 100644 --- a/README.md +++ b/README.md @@ -88,7 +88,6 @@ * [`compose`](#compose) * [`curry`](#curry) * [`functionName`](#functionname) -* [`pipe`](#pipe) * [`runPromisesInSeries`](#runpromisesinseries) * [`sleep`](#sleep) @@ -168,7 +167,6 @@ * [`isNumber`](#isnumber) * [`isString`](#isstring) * [`isSymbol`](#issymbol) -* [`randomHexColorCode`](#randomhexcolorcode) * [`RGBToHex`](#rgbtohex) * [`timeTaken`](#timetaken) * [`toDecimalMark`](#todecimalmark) @@ -176,6 +174,10 @@ * [`UUIDGenerator`](#uuidgenerator) * [`validateNumber`](#validatenumber) +### _Uncategorized_ +* [`pipeFunctions`](#pipefunctions) +* [`randomHexColor`](#randomhexcolor) + ## Adapter ### call @@ -1239,25 +1241,6 @@ const functionName = fn => (console.debug(fn.name), fn); [⬆ back to top](#table-of-contents) -### pipe - -Performs left-to-right function composition. - -Use `Array.reduce()` with the spread operator (`...`) to perform left-to-right function composition. -The first (leftmost) function can accept one or more arguments; the remaining functions must be unary. - -```js -const pipeFunctions = (...fns) => fns.reduce((f, g) => (...args) => g(f(...args))); -/* -const add5 = x => x + 5 -const multiply = (x, y) => x * y -const multiplyAndAdd5 = pipeFunctions(multiply, add5) -multiplyAndAdd5(5, 2) -> 15 -*/ -``` - -[⬆ back to top](#table-of-contents) - ### runPromisesInSeries Runs an array of promises in series. @@ -2321,25 +2304,6 @@ const isSymbol = val => typeof val === 'symbol'; [⬆ back to top](#table-of-contents) -### randomHexColorCode - -Generates a random hexadecimal color code. - -Use `Math.random` to generate a random 24-bit(6x4bits) hexadecimal number. Use bit shifting and then convert it to an hexadecimal String using `toString(16)`. - -```js -const randomHexColor = () => { - let n = (Math.random()*0xfffff|0).toString(16); - return '#' + (n.length !== 6 - ? (Math.random()*0xf|0).toString(16) + n : n); -} -// randomHexColorCode() -> "#e34155" -// randomHexColorCode() -> "#fd73a6" -// randomHexColorCode() -> "#4144c6" -``` - -[⬆ back to top](#table-of-contents) - ### RGBToHex Converts the values of RGB components to a color code. @@ -2430,6 +2394,45 @@ const validateNumber = n => !isNaN(parseFloat(n)) && isFinite(n) && Number(n) == // validateNumber('10') -> true ``` +[⬆ back to top](#table-of-contents) +## _Uncategorized_ + +### pipeFunctions + +Performs left-to-right function composition. + +Use `Array.reduce()` with the spread operator (`...`) to perform left-to-right function composition. +The first (leftmost) function can accept one or more arguments; the remaining functions must be unary. + +```js +const pipeFunctions = (...fns) => fns.reduce((f, g) => (...args) => g(f(...args))); +/* +const add5 = x => x + 5 +const multiply = (x, y) => x * y +const multiplyAndAdd5 = pipeFunctions(multiply, add5) +multiplyAndAdd5(5, 2) -> 15 +*/ +``` + +[⬆ back to top](#table-of-contents) + +### randomHexColor + +Generates a random hexadecimal color code. + +Use `Math.random` to generate a random 24-bit(6x4bits) hexadecimal number. Use bit shifting and then convert it to an hexadecimal String using `toString(16)`. + +```js +const randomHexColor = () => { + let n = (Math.random()*0xfffff|0).toString(16); + return '#' + (n.length !== 6 + ? (Math.random()*0xf|0).toString(16) + n : n); +} +// randomHexColorCode() -> "#e34155" +// randomHexColorCode() -> "#fd73a6" +// randomHexColorCode() -> "#4144c6" +``` + [⬆ back to top](#table-of-contents) ## Credits diff --git a/docs/index.html b/docs/index.html index be1b00279..d1d0d6820 100644 --- a/docs/index.html +++ b/docs/index.html @@ -149,7 +149,6 @@ compose curry functionName -pipe runPromisesInSeries sleep @@ -229,7 +228,6 @@ isNumber isString isSymbol -randomHexColorCode RGBToHex timeTaken toDecimalMark @@ -237,6 +235,10 @@ UUIDGenerator validateNumber +

Uncategorized +

pipeFunctions +randomHexColor +
 

Adapter

call

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

@@ -835,18 +837,6 @@ If you want to curry a function that accepts a variable number of arguments (a v
const functionName = fn => (console.debug(fn.name), fn);
 // functionName(Math.max) -> max (logged in debug channel of console)
 
-

pipe

-

Performs left-to-right function composition.

-

Use Array.reduce() with the spread operator (...) to perform left-to-right function composition. -The first (leftmost) function can accept one or more arguments; the remaining functions must be unary.

-
const pipeFunctions = (...fns) => fns.reduce((f, g) => (...args) => g(f(...args)));
-/*
-const add5 = x => x + 5
-const multiply = (x, y) => x * y
-const multiplyAndAdd5 = pipeFunctions(multiply, add5)
-multiplyAndAdd5(5, 2) -> 15
-*/
-

runPromisesInSeries

Runs an array of promises in series.

Use Array.reduce() to create a promise chain, where each promise returns the next promise when resolved.

@@ -1455,18 +1445,6 @@ Omit the second argument to use the default regex.

// isSymbol('x') -> false // isSymbol(Symbol('x')) -> true -

randomHexColorCode

-

Generates a random hexadecimal color code.

-

Use Math.random to generate a random 24-bit(6x4bits) hexadecimal number. Use bit shifting and then convert it to an hexadecimal String using toString(16).

-
const randomHexColor = () => {
-    let n = (Math.random()*0xfffff|0).toString(16);
-    return '#' + (n.length !== 6
-        ? (Math.random()*0xf|0).toString(16) + n : n);
-}
-// randomHexColorCode() -> "#e34155"
-// randomHexColorCode() -> "#fd73a6"
-// randomHexColorCode() -> "#4144c6"
-

RGBToHex

Converts the values of RGB components to a color code.

Convert given RGB parameters to hexadecimal string using bitwise left-shift operator (<<) and toString(16), then padStart(6,'0') to get a 6-digit hexadecimal value.

@@ -1518,6 +1496,31 @@ Use Number() to check if the coercion holds.

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

Uncategorized

+

pipeFunctions

+

Performs left-to-right function composition.

+

Use Array.reduce() with the spread operator (...) to perform left-to-right function composition. +The first (leftmost) function can accept one or more arguments; the remaining functions must be unary.

+
const pipeFunctions = (...fns) => fns.reduce((f, g) => (...args) => g(f(...args)));
+/*
+const add5 = x => x + 5
+const multiply = (x, y) => x * y
+const multiplyAndAdd5 = pipeFunctions(multiply, add5)
+multiplyAndAdd5(5, 2) -> 15
+*/
+
+

randomHexColor

+

Generates a random hexadecimal color code.

+

Use Math.random to generate a random 24-bit(6x4bits) hexadecimal number. Use bit shifting and then convert it to an hexadecimal String using toString(16).

+
const randomHexColor = () => {
+    let n = (Math.random()*0xfffff|0).toString(16);
+    return '#' + (n.length !== 6
+        ? (Math.random()*0xf|0).toString(16) + n : n);
+}
+// randomHexColorCode() -> "#e34155"
+// randomHexColorCode() -> "#fd73a6"
+// randomHexColorCode() -> "#4144c6"
+