Skip to content

Instantly share code, notes, and snippets.

View jebarjonet's full-sized avatar
👋

Jean-Elie Barjonet jebarjonet

👋
View GitHub Profile
@jebarjonet
jebarjonet / README.md
Created May 4, 2020 08:24
[Old] Soundex FR

Soundex FR Javascript

This script provides a Soundex FR integration for a Javascript project. Original Soundex FR by Édouard BERGÉ.

Usage

@jebarjonet
jebarjonet / lodashMissing.ts
Last active August 16, 2022 23:06
Lodash FP missing functions
/**
* 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
@jebarjonet
jebarjonet / makeCallback.js
Last active June 4, 2018 14:33
Memoized function accepting arguments (prevents React rerendering)
import memoize from 'memoizee'
/**
* Returns memoized function accepting arguments (prevents React rerendering)
*/
export const makeCallback = memoize(
(func, ...args) => (...additionalArgs) => func(...args, ...additionalArgs),
{ length: false },
)
@jebarjonet
jebarjonet / codeToFlag.js
Last active February 6, 2023 15:57
Transforms a country code (ISO 3166-1 alpha-2) into corresponding flag emoji
import { toUpper } from 'lodash'
export const codeToFlag = (code: string): string =>
String.fromCodePoint(
...toUpper(code)
.split('')
.map(c => 127397 + c.charCodeAt(0)),
)
// codeToFlag('fr') => 🇫🇷
@jebarjonet
jebarjonet / readingTime.js
Last active October 9, 2023 04:34
Time needed for a human to read a text (in ms)
import { max, words } from 'lodash'
export const readingTime = (text) => {
const wordsPerMinute = 280
const computedTime = (words(text).length * 60000) / wordsPerMinute
return max([2000, computedTime])
}