View parse-csv-and-iterate-with-delay.js
/* | |
"csv-parse": "^4.15.3", | |
"follow-redirects": "^1.13.3", | |
*/ | |
const path = require('path') | |
const fs = require('fs').promises | |
const parse = require('csv-parse') | |
const { https } = require('follow-redirects') | |
const parseFullName = require('./src/utils/parse-name') |
View random-true-false.js
function randomFromRange(start, end) { | |
return Math.round(Math.random() * (end - start) + start); | |
} | |
function randomTrueFalse() { | |
return randomFromRange(0, 1) ? true : false; | |
} |
View compose-functions.js
// Compose function from right to left. a.k.a. normal 'compose' in functional programming | |
function composeFromRight(...fns) { | |
return (initialVal) => fns.reduceRight((val, fn) => fn(val), initialVal) | |
} | |
// Compose functions from left to right. a.k.a. normal 'pipe' in functional programming | |
function composeFromLeft(...fns) { | |
return (initialVal) => fns.reduce((val, fn) => fn(val), initialVal) | |
} | |
// Functions to compose |
View cache-manager-fs-hash.js
const path = require('path') | |
const cacheManager = require('cache-manager') | |
// storage for the cachemanager | |
const fsStore = require('cache-manager-fs') | |
const fsStoreHash = require('cache-manager-fs-hash'); | |
// initialize caching on disk | |
const mbOfStorage = 512 |
View string-to-boolean.js
function cleanBooleanParam(value) { | |
switch(value.toString().toLowerCase()) { | |
case "true": | |
case "on": | |
case "yes": | |
case "1": | |
return true; | |
case "false": | |
case "off": | |
case "no": |
View _force-sync.js
const forceSync = require('sync-rpc') | |
const syncFunction = forceSync(require.resolve('./async-thing')) | |
console.log('before') | |
const paramOne = 'foo' | |
const paramTwo = 'bar' | |
const syncReturnValue = syncFunction(paramOne, paramTwo) | |
console.log('syncReturn', syncReturnValue) |
View _config.js
/* Base Ava test config */ | |
module.exports = { | |
tap: false, | |
verbose: true, | |
cache: true, | |
failFast: true, | |
failWithoutAssertions: false, | |
} |
View custom-oclif-help-class.js
const { Help } = require('@oclif/plugin-help') | |
const chalk = require('chalk') | |
// https://github.com/oclif/plugin-help/blob/master/src/index.ts | |
module.exports = class MyHelpClass extends Help { | |
constructor(config, opts) { | |
super(config, opts) | |
const commandSlice = process.argv | |
console.log('commandSlice', commandSlice) | |
// Show all commands at root help |
View command-with-listr.js
const execa = require('execa') | |
const Listr = require('listr') | |
const { Observable } = require('rxjs') | |
const { Command, flags } = require('@oclif/command') | |
const timeout = ms => new Promise(res => setTimeout(res, ms)) | |
class AddCommand extends Command { | |
async run() { |
View extend-segment-plugin.js
import Analytics from 'analytics' | |
import segmentPlugin from '@analytics/segment' | |
const originalSegmentInstance = segmentPlugin({ | |
writeKey: '123-xyz' | |
}) | |
// Extend originalSegmentInstance with custom methods | |
const enchancedSegmentInstance = Object.assign({}, originalSegmentInstance, { | |
methods: { |
NewerOlder