Skip to content

Instantly share code, notes, and snippets.

Avatar
🍺
Drunk

南小北 nanxiaobei

🍺
Drunk
View GitHub Profile
@nanxiaobei
nanxiaobei / chain.js
Last active Feb 25, 2020
Inspired by optional chaining
View chain.js
const isObj = (val) => Object.prototype.toString.call(val) === '[object Object]';
const isArr = (val) => Array.isArray(val);
const isNum = (val) => val === `${+val}`;
const strToNum = (str) => (isNum(str) ? +str : str);
/**
* Used to change undefined keys to object or array, similar effect to the 'optional chaining'.
* Received an object and an array of keys, returns a formatted object.
*
* e.g.
You can’t perform that action at this time.