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 ] @@ -551,15 +551,6 @@ document.body📋 Copy to clipboardgetDaysDiffBetweenDates
Returns the difference (in days) between two dates.
Calculate the difference (in days) between two
Dateobjects.const getDaysDiffBetweenDates = (dateInitial, dateFinal) => (dateFinal - dateInitial) / (1000 * 3600 * 24);getDaysDiffBetweenDates(new Date('2017-12-13'), new Date('2017-12-22')); // 9 -toEnglishDate
Converts a date from American format to English format.
Use
Date.toISOString(),split('T')andreplace()to convert a date from American format to the English format. Throws an error if the passed time cannot be converted to a date.const toEnglishDate = time => { - try { - return new Date(time) - .toISOString() - .split('T')[0] - .replace(/-/g, '/'); - } catch (e) {} -}; -toEnglishDate('09/21/2010'); // '21/09/2010'tomorrow
Results in a string representation of tomorrow's date. Use
new Date()to get today's date, adding86400000of seconds to it(24 hours), usingDate.toISOString()to convert Date object to string.const tomorrow = () => new Date(new Date().getTime() + 86400000).toISOString().split('T')[0];tomorrow(); // 2017-12-27 (if current date is 2017-12-26)Function
chainAsync
Chains asynchronous functions.
Loop through an array of functions containing asynchronous events, calling
nextwhen each asynchronous event has completed.const chainAsync = fns => { @@ -1168,6 +1159,7 @@ Logs: { + const newPost = { "userId": 1, "id": 1337, diff --git a/snippets/httpPost.md b/snippets/httpPost.md index 4777f624a..7a52fa2d3 100644 --- a/snippets/httpPost.md +++ b/snippets/httpPost.md @@ -25,6 +25,7 @@ const httpPost = (url, callback, data = null, err = console.error) => { + const newPost = { "userId": 1, "id": 1337, diff --git a/tag_database b/tag_database index 8487312ed..7eccbefc8 100644 --- a/tag_database +++ b/tag_database @@ -165,7 +165,6 @@ takeRight:array timeTaken:utility toCamelCase:string,regexp toDecimalMark:utility,math -toEnglishDate:date,string toggleClass:browser toKebabCase:string,regexp tomorrow:date