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
/* | |
+-----------------------------------------------------------------+ | |
| Created by Chirag Mehta - http://chir.ag/projects/ntc | | |
|-----------------------------------------------------------------| | |
| ntc js (Name that Color JavaScript) | | |
+-----------------------------------------------------------------+ | |
All the functions, code, lists etc. have been written specifically | |
for the Name that Color JavaScript by Chirag Mehta unless otherwise |
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 randomInteger = (min, max) => | |
Math.floor(Math.random() * (max - min + 1)) + min; | |
const randomBoolean = () => Math.random() >= 0.5; | |
const defaultTime = () => randomInteger(1000, 3000); | |
/** | |
* Tool for simulating http requests | |
* |
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
/** | |
* Checking equality between two arrays ignoring order. | |
* | |
* Source: https://www.30secondsofcode.org/blog/s/javascript-array-comparison | |
* | |
* Limitations: | |
* - primitive values only | |
* - first level only | |
* - can't compare objects | |
* |
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
/** | |
* Clear object from empty values (recursively) | |
* Source: https://stackoverflow.com/a/38340374 | |
* | |
* @param {object} obj | |
* @returns {object} | |
*/ | |
const objectRemoveEmpty = (obj) => { | |
const newObj = {}; | |
Object.keys(obj).forEach((key) => { |
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
/** | |
* Get value from object by path (ex. parent.child.id) | |
* Source: https://stackoverflow.com/questions/8817394/javascript-get-deep-value-from-object-by-passing-path-to-it-as-string | |
* | |
* @param {object} obj | |
* @param {string} path | |
* @returns {undefined|*} | |
*/ | |
const deepFind = (obj, path) => { | |
const paths = path.split('.'); |
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
/** | |
* Filter a list of expressions to final string. | |
* | |
* @param args | |
* @returns {string} | |
*/ | |
const classNames = (...args) => | |
args | |
.reduce((accumulator, itm) => { | |
if (itm) { |
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
/** | |
* Decode URL-ified object | |
* | |
* @param {string} urlifiedObj | |
* @returns {any} | |
*/ | |
const decodeUrlifiedObject = (urlifiedObj) => JSON.parse(decodeURI(string)); |
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
// Bootstrap utilities | |
@import '~bootstrap/scss/functions'; | |
@import '~bootstrap/scss/variables'; | |
@import '~bootstrap/scss/mixins'; | |
@import '~bootstrap/scss/utilities'; | |
@import '~bootstrap/scss/reboot'; | |
@import '~bootstrap/scss/containers'; | |
@import '~bootstrap/scss/grid'; | |
@import '~bootstrap/scss/helpers'; | |
@import '~bootstrap/scss/utilities/api'; |
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
/** | |
* getBase64 | |
* Source: https://ant.design/components/upload/#components-upload-demo-picture-card | |
* | |
* @param file | |
* @returns {Promise<unknown>} | |
*/ | |
const getBase64 = (file) => | |
new Promise((resolve, reject) => { | |
const reader = new FileReader(); |
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
/** | |
* Source: https://react-dropzone.js.org/ | |
*/ | |
const onDrop = () => (acceptedFiles) => { | |
acceptedFiles.forEach((file) => { | |
const reader = new FileReader() | |
reader.onabort = () => console.log('file reading was aborted') | |
reader.onerror = () => console.log('file reading has failed') | |
reader.onload = () => { |