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
    
  
  
    
  | /** | |
| * @param {Array<T>} list | |
| * @param {(T):Promise<Boolean>} filter | |
| * @returns {Promise<T[]>} | |
| */ | |
| function filterAsync(list, filter) { | |
| return Promise | |
| .all( | |
| list.map(item => filter(item) | |
| .then(filterRes => ({ filterRes, item })) | 
  
    
      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 * as stream from 'stream'; | |
| function pipe(readStream:stream.Readable, writeStream: NodeJS.WritableStream):Promise<void> { | |
| return new Promise<void>((onRes, onErr) => { | |
| readStream | |
| .on('error', onErr) | |
| .pipe(writeStream) | |
| .on('error', onErr) | |
| .on('finish', () => onRes()) | |
| }); | 
  
    
      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
    
  
  
    
  | function assertMatch(actual:string, regex: string | RegExp, msg?:string):void { | |
| const regexNorml:RegExp = _.isString(regex) ? new RegExp(regex as string) : regex; | |
| const isMatch = regexNorml.test(actual); | |
| if (!isMatch) { | |
| assert.fail(actual, regexNorml.toString(), msg, 'matches'); | |
| } | |
| } | 
  
    
      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 _ = require('lodash'); | |
| function flattenObj(obj, prefix) { | |
| prefix || (prefix = ''); | |
| return Object.keys(obj) | |
| .reduce((flat, key) => ( | |
| _.isObject(obj[key]) ? | |
| // Recursively flatten objects | |
| Object.assign(flat, flattenObj(obj[key], `${prefix}${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
    
  
  
    
  | import * as _ from 'lodash'; | |
| async function mapAsync<TVal, TRes>(items:TVal[], iter:(val:TVal, i:(number | string)) => Promise<TRes>):Promise<TRes[]> { | |
| return Promise.all(_.map(items, iter)); | |
| } | |
| export default mapAsync; | 
  
    
      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
    
  
  
    
  | // https://gist.github.com/eschwartz/70a15f12e6ef90f377d5d51fba9c86d8 | |
| import mapAsync from './mapAsync'; | |
| interface Dict<TVal> { | |
| [key: string]: TVal | |
| } | |
| async function mapValuesAsync<TVal, TRes>(obj:Dict<TVal>, iter:(val:TVal, key:string) => Promise<TRes>):Promise<Dict<TRes>> { | |
| const keyResPairs:[string, TRes][] = await mapAsync<string, [string, TRes]>(Object.keys(obj), | |
| async (key: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
    
  
  
    
  | import * as assert from 'assert'; | |
| function assertMatches(actual:string, regex:RegExp, msg?:string) { | |
| if (regex.test(actual)) { | |
| assert(false, `${msg}: expected "${actual}" to match regex "${regex.toString()}"`) | |
| } | |
| } | |
| export default assertMatches; | 
  
    
      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
    
  
  
    
  | // Track the equation as a string | |
| let equation = ''; | |
| // 🤯 🤯 🤯 🤯 🤯 🤯 🤯 | |
| // This regular expression defines a set of "rules" for | |
| // how our equation string should look | |
| // It also tells us how to break apart the different sections of the | |
| // string into "groups" | |
| // These are super powerful, though not always so easy to use 😉 | |
| let equationRegEx = /^([0-9]+(\.[0-9]+)?)?([\+\-\/\*])?([0-9]+(\.[0-9]+)?)?$/ | 
OlderNewer