Skip to content

Instantly share code, notes, and snippets.

@wazazaby
Last active April 23, 2021 19:11
Show Gist options
  • Save wazazaby/69e600a11f240ed653416c5c5f7ff6be to your computer and use it in GitHub Desktop.
Save wazazaby/69e600a11f240ed653416c5c5f7ff6be to your computer and use it in GitHub Desktop.
// From snapshot to a simple JS object
const getObjFromDocumentSnapshot = snapshot => snapshot.data();
// From an object like this -> { 'RIP Code': { en: { '8274': 'My english value' } } }
// To this -> 'My english value'
const getter = propName => either(pipe(path([propName, 'en']), values, head), always(''));
const ripCodeGetter = getter('RIP Code');
// Check if the RIP Code property of the given object matchs ripCode
const ripCodeExistsInObj = ripCode => pipe(ripCodeGetter, equals(ripCode));
// Same, but on a snapshot instead of an object
const ripCodeExistsInSnapshot = ripCode => pipe(getObjFromDocumentSnapshot, ripCodeExistsInObj(ripCode));
// Same, but on a list of snapshots instead of a single one
const ripCodeExistsInSnapshots = curry((ripCode, querySnapshots) => any(ripCodeExistsInSnapshot(ripCode))(querySnapshots));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment