This file contains 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 RemoveAccents(strAccents) { | |
var strAccents = strAccents.split(''); | |
var strAccentsOut = new Array(); | |
var strAccentsLen = strAccents.length; | |
var accents = 'ÀÁÂÃÄÅàáâãäåÒÓÔÕÕÖØòóôõöøÈÉÊËèéêëðÇçÐÌÍÎÏìíîïÙÚÛÜùúûüÑñŠšŸÿýŽž'; | |
var accentsOut = "AAAAAAaaaaaaOOOOOOOooooooEEEEeeeeeCcDIIIIiiiiUUUUuuuuNnSsYyyZz"; | |
for (var y = 0; y < strAccentsLen; y++) { | |
if (accents.indexOf(strAccents[y]) != -1) { | |
strAccentsOut[y] = accentsOut.substr(accents.indexOf(strAccents[y]), 1); | |
} else |
This file contains 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 fs = require('fs'); | |
// Paths functions from | |
// https://lowrey.me/getting-all-paths-of-an-javascript-object/ | |
function getPaths(root) { | |
let paths = []; | |
let nodes = [{ | |
obj: root, | |
path: [] |
This file contains 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
// From https://stackoverflow.com/questions/286141/remove-blank-attributes-from-an-object-in-javascript | |
const removeEmpty = (obj) => { | |
return Object.keys(obj) | |
.filter(k => obj[k] !== null && obj[k] !== undefined && obj[k] !== '') | |
.reduce((newObj, k) => { | |
return typeof obj[k] === 'object' ? | |
Object.assign(newObj, {[k]: removeEmpty(obj[k])}) : // Recurse. | |
Object.assign(newObj, {[k]: obj[k]}); // Copy value. | |
}, {}); | |
} |
This file contains 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
export const composePromise = (...fns) => initialValue => | |
fns.reduceRight((res, fn) => Promise.resolve(res).then(fn), initialValue); | |
// Individual Promises | |
const saveAppFee = () => saveFees(a, b, c); | |
const saveLnpFee = () => saveFees(x, y, z); | |
// Composed Promises | |
const saveAppAndLnp = composePromise(saveAppFee, saveLnpFee); | |
const saveApp = composePromise(saveAppFee); |
This file contains 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 toDollar(n) { | |
const numWithCommas = n.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ","); | |
return `$${numWithCommas}`; | |
} |
This file contains 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 keyBy = (arr, objKey) => arr.reduce( | |
(acc, cur) => ( | |
{ ...acc, [cur[objKey]]: cur } | |
), {}); |
This file contains 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 groupBy = (array, groupKey) => { | |
return array.reduce((acc, cur) => { | |
if (acc[cur[groupKey]]) { | |
acc[cur[groupKey]].push(cur); | |
} else { | |
acc[cur[groupKey]] = [cur]; | |
} | |
return acc; | |
}, {}); | |
}; |
This file contains 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 valuesMatch = (sourceObj, matchObj) => { | |
let matches = true; | |
Object.keys(matchObj).forEach(matchKey => { | |
if (sourceObj[matchKey] !== matchObj[matchKey]) { | |
matches = false; | |
} | |
}); | |
return matches; | |
}; |
This file contains 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 scream = str => str.toUpperCase() | |
const exclaim = str => `${str}!` | |
const repeat = str => `${str} ${str}` | |
const string = 'Egghead.io is awesome' | |
// Nested | |
const result2 = repeat(exclaim(scream(string))) | |
// EGGHEAD.IO IS AWESOME! EGGHEAD.IO IS AWESOME! |
This file contains 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 toConstant = (str: string): string => str.replace(/\s+/g, '_').toUpperCase(); |