This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function camelize(val) { | |
return val.replace (/(?:^|[-_]|\s)(\w)/g, function (_, c, i) { | |
return i === 0 ? c.toLowerCase() : c.toUpperCase (); | |
}) | |
} | |
camelize('I like to develop') === 'iLikeToDevelop'; // separate words | |
camelize('i_like_to_develop') === 'iLikeToDevelop'; // underscore case | |
camelize('ILikeToDevelop') === 'iLikeToDevelop'; // pascal case | |
camelize('i_like ToDevelop') === 'iLikeToDevelop'; // mixed |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Ultra slim flat func | |
const flat = ( a=[] ) => a.reduce( ( a, v ) => a.concat( v.map ? flat(v) : v ), [] ); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function isObject(item) { | |
return (item && typeof item === 'object' && !Array.isArray(item)); | |
} | |
function mergeDeep(target, ...sources) { | |
if (!sources.length) return target; | |
const source = sources.shift(); | |
if (isObject(target) && isObject(source)) { | |
for (const key in source) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function serialize(obj, prefix) { | |
var props = []; | |
for (var p in obj){ | |
if (obj.hasOwnProperty(p)) { | |
if (Object.prototype.toString.call(obj[p]) === '[object Object]'){ | |
props.push(serialize(obj[p], (prefix ? prefix : '') + p + '.')); | |
}else{ | |
props.push((prefix ? prefix : '') + encodeURIComponent(p) + '=' + encodeURIComponent(obj[p])); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
p = new Promise((r) => {r()}); | |
setImmediate(console.log, 'I1') | |
process.nextTick(() =>console.log('T1')); | |
p.then(() => console.log('P1')); | |
process.nextTick(() =>console.log('T2')); | |
// Output: | |
// T1 | |
// T2 | |
// P1 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const setSym = Symbol( 'operations' ); | |
module.exports = class AtomikPipeline { | |
constructor( operationsSet ) { | |
this[setSym] = operationsSet; | |
} | |
async run( _param ) { | |
const rollback = []; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Option one | |
// All setters | |
XYZ.title = 'My cool test'; | |
XYZ.before = () => { | |
}; | |
XYZ.do = () => { | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module.exports = interval => { | |
let count = 0; | |
return { | |
do( fn ) { | |
return { | |
async times( amount ) { | |
const jobs = []; | |
await new Promise( ( resolve, reject ) => { | |
const loop = setInterval( async () => { | |
count++; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function deepFetch( object, path ) { | |
return path.split( '.' ).reduce( ( value, part ) => { | |
if ( Array.isArray( value ) ) { | |
return value.reduce( (arr, v) => arr.concat( deepFetch( v, part ) ), [] ); | |
} else if ( part === '*' ) { | |
return Object.keys( value ).map( p => value[p] ); | |
} | |
return value[part]; | |
}, object ); | |
} |