UNPKG

atriusmaps-node-sdk

Version:

This project provides an API to Atrius Personal Wayfinder maps within a Node environment. See the README.md for more information

34 lines (28 loc) 970 B
'use strict'; require('ramda'); require('zousan'); // Ensures only a single asynchronous function wrapped in this function runs at a time. let lastFn = null; const singleFile = fn => function () { if (lastFn) lastFn = lastFn.then(() => fn.apply(null, arguments)); else lastFn = fn.apply(null, arguments); return lastFn; }; /** * returns a copy of an object with any (top-level) properties that do not * return truthy from the specified function stripped. So it works just like * the Array.filter, but for objects. * @param {function} fn A filter predicate - will be passed (key,object) * @param {object} ob The object to filter (top level properties only) * @returns (object) The newly created object with filtered properties */ function filterOb(fn, ob) { const ret = {}; Object.keys(ob).forEach(key => { if (fn(key, ob[key])) ret[key] = ob[key]; }); return ret; } exports.filterOb = filterOb; exports.singleFile = singleFile;