Format JavaScript Array of Strings to Oxford Comma
const toOxfordComma = (array) =>
array.length === 2
? array.join(' and ')
: array.length > 2
? array
.slice(0, array.length - 1)
.concat(`and ${array.slice(-1)}`)
const isAsyncFunction = fn => typeof fn === 'function' && fn.constructor.name === 'AsyncFunction'; |
const isPromiseLike = obj => | |
obj !== null && | |
(typeof obj === 'object' || typeof obj === 'function') && | |
typeof obj.then === 'function'; |
const toOxfordComma = (array) =>
array.length === 2
? array.join(' and ')
: array.length > 2
? array
.slice(0, array.length - 1)
.concat(`and ${array.slice(-1)}`)
// Generally Expected Flow (actions and implementation are missing) | |
// | |
// 1 renderNode runs logic which inspects this hard-coded rootNode | |
// 2 transtions to renderBranch because it has children | |
// 3 there are two children so the UI would display them | |
// 4 user chooses the first child | |
// 5 fetchNode finds no children property, so there is nothing more to load | |
// 6 fetchNode resolves success with the node | |
// 7 renderNode runs logic which inspects the node | |
// 8 transtions to renderLeaf because it has no children |
export default function transformer(file, api) { | |
const j = api.jscodeshift; | |
const toPascalCase = str => | |
`${str}` | |
.replace(new RegExp(/[-_]+/, 'g'), ' ') | |
.replace(new RegExp(/[^\w\s]/, 'g'), '') | |
.replace( | |
new RegExp(/\s+(.)(\w+)/, 'g'), | |
($1, $2, $3) => `${$2.toUpperCase() + $3.toLowerCase()}` |
Work in progress sketch based on following along with the video course at https://egghead.io/courses/quickly-transform-data-with-transducers.
const id = (value) => value;
const isArray = (value) => Array.isArray(value);
const isNumber = (value) => typeof value === 'number';