This script provides a Soundex FR integration for a Javascript project. Original Soundex FR by Édouard BERGÉ.
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
import { max, words } from 'lodash' | |
export const readingTime = (text) => { | |
const wordsPerMinute = 280 | |
const computedTime = (words(text).length * 60000) / wordsPerMinute | |
return max([2000, computedTime]) | |
} |
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
import { toUpper } from 'lodash' | |
export const codeToFlag = (code: string): string => | |
String.fromCodePoint( | |
...toUpper(code) | |
.split('') | |
.map(c => 127397 + c.charCodeAt(0)), | |
) | |
// codeToFlag('fr') => 🇫🇷 |
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
import memoize from 'memoizee' | |
/** | |
* Returns memoized function accepting arguments (prevents React rerendering) | |
*/ | |
export const makeCallback = memoize( | |
(func, ...args) => (...additionalArgs) => func(...args, ...additionalArgs), | |
{ length: false }, | |
) |
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
/** | |
* Returns true if item is defined | |
* @example | |
* isDefined('something') => true | |
*/ | |
export const isDefined = (item: any): boolean => !isNil(item) | |
/** | |
* Scales a value from a range to another range | |
* @example |