@contrast/agent 4.16.0 → 4.17.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/VERSION +1 -1
- package/bin/linux/contrast-service +0 -0
- package/bin/mac/contrast-service +0 -0
- package/bin/windows/contrast-service.exe +0 -0
- package/esm.mjs +21 -11
- package/lib/assess/policy/propagators.json +4 -0
- package/lib/assess/policy/signatures.json +5 -0
- package/lib/assess/propagators/fastify-static/allowed-path.js +85 -0
- package/lib/contrast.js +1 -1
- package/lib/core/rewrite/index.js +2 -2
- package/lib/protect/rules/cmd-injection/cmdinjection-rule.js +1 -1
- package/node_modules/@colors/colors/LICENSE +26 -0
- package/node_modules/@colors/colors/README.md +219 -0
- package/node_modules/@colors/colors/examples/normal-usage.js +83 -0
- package/node_modules/@colors/colors/examples/safe-string.js +80 -0
- package/node_modules/@colors/colors/index.d.ts +136 -0
- package/node_modules/@colors/colors/lib/colors.js +211 -0
- package/node_modules/@colors/colors/lib/custom/trap.js +46 -0
- package/node_modules/@colors/colors/lib/custom/zalgo.js +110 -0
- package/node_modules/@colors/colors/lib/extendStringPrototype.js +110 -0
- package/node_modules/@colors/colors/lib/index.js +13 -0
- package/node_modules/@colors/colors/lib/maps/america.js +10 -0
- package/node_modules/@colors/colors/lib/maps/rainbow.js +12 -0
- package/node_modules/@colors/colors/lib/maps/random.js +11 -0
- package/node_modules/@colors/colors/lib/maps/zebra.js +5 -0
- package/node_modules/@colors/colors/lib/styles.js +95 -0
- package/node_modules/@colors/colors/lib/system/has-flag.js +35 -0
- package/node_modules/@colors/colors/lib/system/supports-colors.js +151 -0
- package/node_modules/@colors/colors/package.json +49 -0
- package/node_modules/@colors/colors/safe.d.ts +48 -0
- package/node_modules/@colors/colors/safe.js +10 -0
- package/node_modules/@colors/colors/themes/generic-logging.js +12 -0
- package/node_modules/@dabh/diagnostics/README.md +16 -16
- package/node_modules/@dabh/diagnostics/package.json +9 -9
- package/node_modules/async/CHANGELOG.md +13 -0
- package/node_modules/async/all.js +74 -9
- package/node_modules/async/allLimit.js +3 -3
- package/node_modules/async/allSeries.js +3 -3
- package/node_modules/async/any.js +75 -9
- package/node_modules/async/anyLimit.js +3 -3
- package/node_modules/async/anySeries.js +3 -3
- package/node_modules/async/applyEach.js +2 -2
- package/node_modules/async/applyEachSeries.js +2 -2
- package/node_modules/async/asyncify.js +3 -3
- package/node_modules/async/auto.js +81 -15
- package/node_modules/async/autoInject.js +30 -4
- package/node_modules/async/cargo.js +1 -1
- package/node_modules/async/cargoQueue.js +1 -1
- package/node_modules/async/compose.js +1 -1
- package/node_modules/async/concat.js +72 -4
- package/node_modules/async/concatLimit.js +3 -3
- package/node_modules/async/concatSeries.js +2 -2
- package/node_modules/async/detect.js +43 -8
- package/node_modules/async/detectLimit.js +3 -3
- package/node_modules/async/detectSeries.js +3 -3
- package/node_modules/async/dir.js +1 -1
- package/node_modules/async/dist/async.js +1379 -168
- package/node_modules/async/dist/async.min.js +1 -1
- package/node_modules/async/dist/async.mjs +1372 -161
- package/node_modules/async/doDuring.js +3 -3
- package/node_modules/async/doUntil.js +2 -2
- package/node_modules/async/doWhilst.js +3 -3
- package/node_modules/async/during.js +3 -3
- package/node_modules/async/each.js +69 -28
- package/node_modules/async/eachLimit.js +4 -4
- package/node_modules/async/eachOf.js +85 -16
- package/node_modules/async/eachOfLimit.js +3 -3
- package/node_modules/async/eachOfSeries.js +2 -2
- package/node_modules/async/eachSeries.js +2 -2
- package/node_modules/async/ensureAsync.js +2 -2
- package/node_modules/async/every.js +74 -9
- package/node_modules/async/everyLimit.js +3 -3
- package/node_modules/async/everySeries.js +3 -3
- package/node_modules/async/filter.js +49 -9
- package/node_modules/async/filterLimit.js +3 -3
- package/node_modules/async/filterSeries.js +3 -3
- package/node_modules/async/find.js +43 -8
- package/node_modules/async/findLimit.js +3 -3
- package/node_modules/async/findSeries.js +3 -3
- package/node_modules/async/flatMap.js +72 -4
- package/node_modules/async/flatMapLimit.js +3 -3
- package/node_modules/async/flatMapSeries.js +2 -2
- package/node_modules/async/foldl.js +87 -11
- package/node_modules/async/foldr.js +2 -2
- package/node_modules/async/forEach.js +69 -28
- package/node_modules/async/forEachLimit.js +4 -4
- package/node_modules/async/forEachOf.js +85 -16
- package/node_modules/async/forEachOfLimit.js +3 -3
- package/node_modules/async/forEachOfSeries.js +2 -2
- package/node_modules/async/forEachSeries.js +2 -2
- package/node_modules/async/forever.js +4 -4
- package/node_modules/async/groupBy.js +62 -8
- package/node_modules/async/groupByLimit.js +3 -3
- package/node_modules/async/groupBySeries.js +2 -2
- package/node_modules/async/inject.js +87 -11
- package/node_modules/async/internal/applyEach.js +2 -2
- package/node_modules/async/internal/asyncEachOfLimit.js +1 -1
- package/node_modules/async/internal/consoleFunc.js +5 -1
- package/node_modules/async/internal/createTester.js +2 -2
- package/node_modules/async/internal/eachOfLimit.js +6 -6
- package/node_modules/async/internal/filter.js +2 -2
- package/node_modules/async/internal/iterator.js +5 -2
- package/node_modules/async/internal/map.js +1 -1
- package/node_modules/async/internal/parallel.js +3 -3
- package/node_modules/async/internal/queue.js +4 -4
- package/node_modules/async/internal/reject.js +2 -2
- package/node_modules/async/internal/setImmediate.js +6 -2
- package/node_modules/async/internal/wrapAsync.js +1 -1
- package/node_modules/async/log.js +1 -1
- package/node_modules/async/map.js +86 -6
- package/node_modules/async/mapLimit.js +3 -3
- package/node_modules/async/mapSeries.js +3 -3
- package/node_modules/async/mapValues.js +102 -12
- package/node_modules/async/mapValuesLimit.js +4 -4
- package/node_modules/async/mapValuesSeries.js +1 -1
- package/node_modules/async/memoize.js +3 -3
- package/node_modules/async/nextTick.js +3 -3
- package/node_modules/async/package.json +4 -6
- package/node_modules/async/parallel.js +96 -7
- package/node_modules/async/parallelLimit.js +2 -2
- package/node_modules/async/priorityQueue.js +11 -4
- package/node_modules/async/queue.js +4 -4
- package/node_modules/async/race.js +3 -3
- package/node_modules/async/reduce.js +87 -11
- package/node_modules/async/reduceRight.js +2 -2
- package/node_modules/async/reflect.js +2 -2
- package/node_modules/async/reflectAll.js +1 -1
- package/node_modules/async/reject.js +44 -10
- package/node_modules/async/rejectLimit.js +3 -3
- package/node_modules/async/rejectSeries.js +3 -3
- package/node_modules/async/retry.js +2 -2
- package/node_modules/async/retryable.js +4 -4
- package/node_modules/async/select.js +49 -9
- package/node_modules/async/selectLimit.js +3 -3
- package/node_modules/async/selectSeries.js +3 -3
- package/node_modules/async/seq.js +4 -4
- package/node_modules/async/series.js +112 -12
- package/node_modules/async/setImmediate.js +1 -1
- package/node_modules/async/some.js +75 -9
- package/node_modules/async/someLimit.js +3 -3
- package/node_modules/async/someSeries.js +3 -3
- package/node_modules/async/sortBy.js +121 -19
- package/node_modules/async/timeout.js +2 -2
- package/node_modules/async/times.js +1 -1
- package/node_modules/async/timesLimit.js +3 -3
- package/node_modules/async/timesSeries.js +1 -1
- package/node_modules/async/transform.js +111 -19
- package/node_modules/async/tryEach.js +3 -3
- package/node_modules/async/until.js +3 -3
- package/node_modules/async/waterfall.js +4 -4
- package/node_modules/async/whilst.js +3 -3
- package/node_modules/async/wrapSync.js +3 -3
- package/node_modules/color/README.md +9 -0
- package/node_modules/color/index.js +4 -1
- package/node_modules/color/package.json +8 -8
- package/node_modules/color-string/README.md +6 -2
- package/node_modules/color-string/index.js +21 -13
- package/node_modules/color-string/package.json +4 -4
- package/node_modules/colorspace/package.json +5 -5
- package/node_modules/fecha/dist/fecha.min.js +1 -1
- package/node_modules/fecha/dist/fecha.min.js.map +1 -0
- package/node_modules/fecha/lib/fecha.d.ts +2 -2
- package/node_modules/fecha/lib/fecha.js +35 -18
- package/node_modules/fecha/lib/fecha.js.map +1 -0
- package/node_modules/fecha/lib/fecha.umd.js +35 -18
- package/node_modules/fecha/lib/fecha.umd.js.map +1 -0
- package/node_modules/fecha/package.json +9 -10
- package/node_modules/fecha/src/fecha.ts +524 -0
- package/node_modules/logform/.eslintrc +1 -1
- package/node_modules/logform/CHANGELOG.md +24 -0
- package/node_modules/logform/README.md +15 -17
- package/node_modules/logform/browser.js +3 -1
- package/node_modules/logform/cli.js +1 -1
- package/node_modules/logform/colorize.js +2 -2
- package/node_modules/logform/dist/browser.js +8 -2
- package/node_modules/logform/dist/cli.js +2 -2
- package/node_modules/logform/dist/colorize.js +5 -5
- package/node_modules/logform/dist/errors.js +1 -1
- package/node_modules/logform/dist/format.js +9 -5
- package/node_modules/logform/dist/index.js +53 -20
- package/node_modules/logform/dist/json.js +7 -6
- package/node_modules/logform/dist/logstash.js +1 -1
- package/node_modules/logform/dist/pad-levels.js +4 -4
- package/node_modules/logform/dist/printf.js +1 -1
- package/node_modules/logform/dist/simple.js +1 -1
- package/node_modules/logform/dist/splat.js +2 -2
- package/node_modules/logform/dist/uncolorize.js +1 -1
- package/node_modules/logform/errors.js +1 -1
- package/node_modules/logform/index.d.ts +36 -0
- package/node_modules/logform/index.js +19 -20
- package/node_modules/logform/json.js +7 -7
- package/node_modules/logform/logstash.js +1 -1
- package/node_modules/logform/package.json +10 -9
- package/node_modules/logform/simple.js +1 -1
- package/node_modules/logform/uncolorize.js +1 -1
- package/node_modules/moment/CHANGELOG.md +6 -0
- package/node_modules/moment/dist/locale/ar-kw.js +4 -3
- package/node_modules/moment/dist/locale/ar-ly.js +1 -1
- package/node_modules/moment/dist/locale/ar-ma.js +4 -3
- package/node_modules/moment/dist/locale/ar-sa.js +4 -3
- package/node_modules/moment/dist/locale/ar-tn.js +4 -3
- package/node_modules/moment/dist/locale/az.js +4 -3
- package/node_modules/moment/dist/locale/be.js +10 -9
- package/node_modules/moment/dist/locale/bn-bd.js +4 -3
- package/node_modules/moment/dist/locale/bn.js +4 -3
- package/node_modules/moment/dist/locale/bo.js +8 -6
- package/node_modules/moment/dist/locale/br.js +6 -3
- package/node_modules/moment/dist/locale/bs.js +4 -3
- package/node_modules/moment/dist/locale/ca.js +12 -9
- package/node_modules/moment/dist/locale/cs.js +15 -6
- package/node_modules/moment/dist/locale/cv.js +4 -3
- package/node_modules/moment/dist/locale/cy.js +4 -3
- package/node_modules/moment/dist/locale/de-at.js +6 -6
- package/node_modules/moment/dist/locale/de-ch.js +6 -6
- package/node_modules/moment/dist/locale/de.js +6 -6
- package/node_modules/moment/dist/locale/el.js +8 -6
- package/node_modules/moment/dist/locale/es-do.js +10 -6
- package/node_modules/moment/dist/locale/es-mx.js +10 -6
- package/node_modules/moment/dist/locale/es-us.js +10 -6
- package/node_modules/moment/dist/locale/es.js +10 -6
- package/node_modules/moment/dist/locale/et.js +6 -6
- package/node_modules/moment/dist/locale/eu.js +8 -6
- package/node_modules/moment/dist/locale/fa.js +12 -9
- package/node_modules/moment/dist/locale/fi.js +12 -9
- package/node_modules/moment/dist/locale/fo.js +4 -3
- package/node_modules/moment/dist/locale/fr-ca.js +4 -3
- package/node_modules/moment/dist/locale/fr-ch.js +4 -3
- package/node_modules/moment/dist/locale/fr.js +10 -6
- package/node_modules/moment/dist/locale/fy.js +4 -6
- package/node_modules/moment/dist/locale/gl.js +4 -3
- package/node_modules/moment/dist/locale/gom-deva.js +8 -6
- package/node_modules/moment/dist/locale/gom-latn.js +6 -6
- package/node_modules/moment/dist/locale/gu.js +4 -3
- package/node_modules/moment/dist/locale/he.js +4 -4
- package/node_modules/moment/dist/locale/hi.js +14 -10
- package/node_modules/moment/dist/locale/hr.js +7 -5
- package/node_modules/moment/dist/locale/hu.js +6 -6
- package/node_modules/moment/dist/locale/hy-am.js +8 -6
- package/node_modules/moment/dist/locale/is.js +4 -3
- package/node_modules/moment/dist/locale/ka.js +10 -10
- package/node_modules/moment/dist/locale/km.js +4 -3
- package/node_modules/moment/dist/locale/kn.js +4 -3
- package/node_modules/moment/dist/locale/ku.js +6 -6
- package/node_modules/moment/dist/locale/lb.js +8 -6
- package/node_modules/moment/dist/locale/lo.js +4 -3
- package/node_modules/moment/dist/locale/lt.js +8 -6
- package/node_modules/moment/dist/locale/lv.js +4 -3
- package/node_modules/moment/dist/locale/me.js +2 -3
- package/node_modules/moment/dist/locale/mi.js +4 -3
- package/node_modules/moment/dist/locale/ml.js +8 -6
- package/node_modules/moment/dist/locale/mn.js +4 -3
- package/node_modules/moment/dist/locale/mr.js +4 -3
- package/node_modules/moment/dist/locale/mt.js +4 -3
- package/node_modules/moment/dist/locale/nb.js +2 -3
- package/node_modules/moment/dist/locale/ne.js +4 -3
- package/node_modules/moment/dist/locale/nl-be.js +12 -12
- package/node_modules/moment/dist/locale/nl.js +12 -12
- package/node_modules/moment/dist/locale/nn.js +2 -3
- package/node_modules/moment/dist/locale/oc-lnc.js +8 -6
- package/node_modules/moment/dist/locale/pa-in.js +4 -3
- package/node_modules/moment/dist/locale/pl.js +10 -9
- package/node_modules/moment/dist/locale/pt-br.js +4 -3
- package/node_modules/moment/dist/locale/pt.js +4 -3
- package/node_modules/moment/dist/locale/ro.js +4 -3
- package/node_modules/moment/dist/locale/ru.js +20 -13
- package/node_modules/moment/dist/locale/se.js +6 -6
- package/node_modules/moment/dist/locale/si.js +4 -3
- package/node_modules/moment/dist/locale/sk.js +4 -3
- package/node_modules/moment/dist/locale/sl.js +4 -3
- package/node_modules/moment/dist/locale/sr-cyrl.js +32 -22
- package/node_modules/moment/dist/locale/sr.js +32 -22
- package/node_modules/moment/dist/locale/ss.js +4 -3
- package/node_modules/moment/dist/locale/sw.js +4 -3
- package/node_modules/moment/dist/locale/ta.js +8 -6
- package/node_modules/moment/dist/locale/te.js +8 -6
- package/node_modules/moment/dist/locale/tg.js +4 -3
- package/node_modules/moment/dist/locale/th.js +4 -3
- package/node_modules/moment/dist/locale/tlh.js +8 -9
- package/node_modules/moment/dist/locale/tr.js +1 -1
- package/node_modules/moment/dist/locale/tzm-latn.js +4 -3
- package/node_modules/moment/dist/locale/tzm.js +4 -3
- package/node_modules/moment/dist/locale/ug-cn.js +4 -3
- package/node_modules/moment/dist/locale/uk.js +16 -12
- package/node_modules/moment/dist/locale/uz-latn.js +4 -3
- package/node_modules/moment/dist/locale/vi.js +4 -3
- package/node_modules/moment/dist/locale/x-pseudo.js +8 -6
- package/node_modules/moment/dist/moment.js +95 -80
- package/node_modules/moment/locale/ar-kw.js +4 -3
- package/node_modules/moment/locale/ar-ly.js +1 -1
- package/node_modules/moment/locale/ar-ma.js +4 -3
- package/node_modules/moment/locale/ar-sa.js +4 -3
- package/node_modules/moment/locale/ar-tn.js +4 -3
- package/node_modules/moment/locale/az.js +4 -3
- package/node_modules/moment/locale/be.js +10 -9
- package/node_modules/moment/locale/bn-bd.js +4 -3
- package/node_modules/moment/locale/bn.js +4 -3
- package/node_modules/moment/locale/bo.js +8 -6
- package/node_modules/moment/locale/br.js +6 -3
- package/node_modules/moment/locale/bs.js +4 -3
- package/node_modules/moment/locale/ca.js +12 -9
- package/node_modules/moment/locale/cs.js +15 -6
- package/node_modules/moment/locale/cv.js +4 -3
- package/node_modules/moment/locale/cy.js +4 -3
- package/node_modules/moment/locale/de-at.js +6 -6
- package/node_modules/moment/locale/de-ch.js +6 -6
- package/node_modules/moment/locale/de.js +6 -6
- package/node_modules/moment/locale/el.js +8 -6
- package/node_modules/moment/locale/es-do.js +10 -6
- package/node_modules/moment/locale/es-mx.js +10 -6
- package/node_modules/moment/locale/es-us.js +10 -6
- package/node_modules/moment/locale/es.js +10 -6
- package/node_modules/moment/locale/et.js +6 -6
- package/node_modules/moment/locale/eu.js +8 -6
- package/node_modules/moment/locale/fa.js +12 -9
- package/node_modules/moment/locale/fi.js +12 -9
- package/node_modules/moment/locale/fo.js +4 -3
- package/node_modules/moment/locale/fr-ca.js +4 -3
- package/node_modules/moment/locale/fr-ch.js +4 -3
- package/node_modules/moment/locale/fr.js +10 -6
- package/node_modules/moment/locale/fy.js +4 -6
- package/node_modules/moment/locale/gl.js +4 -3
- package/node_modules/moment/locale/gom-deva.js +8 -6
- package/node_modules/moment/locale/gom-latn.js +6 -6
- package/node_modules/moment/locale/gu.js +4 -3
- package/node_modules/moment/locale/he.js +4 -4
- package/node_modules/moment/locale/hi.js +14 -10
- package/node_modules/moment/locale/hr.js +7 -5
- package/node_modules/moment/locale/hu.js +6 -6
- package/node_modules/moment/locale/hy-am.js +8 -6
- package/node_modules/moment/locale/is.js +4 -3
- package/node_modules/moment/locale/ka.js +10 -10
- package/node_modules/moment/locale/km.js +4 -3
- package/node_modules/moment/locale/kn.js +4 -3
- package/node_modules/moment/locale/ku.js +6 -6
- package/node_modules/moment/locale/lb.js +8 -6
- package/node_modules/moment/locale/lo.js +4 -3
- package/node_modules/moment/locale/lt.js +8 -6
- package/node_modules/moment/locale/lv.js +4 -3
- package/node_modules/moment/locale/me.js +2 -3
- package/node_modules/moment/locale/mi.js +4 -3
- package/node_modules/moment/locale/ml.js +8 -6
- package/node_modules/moment/locale/mn.js +4 -3
- package/node_modules/moment/locale/mr.js +4 -3
- package/node_modules/moment/locale/mt.js +4 -3
- package/node_modules/moment/locale/nb.js +2 -3
- package/node_modules/moment/locale/ne.js +4 -3
- package/node_modules/moment/locale/nl-be.js +12 -12
- package/node_modules/moment/locale/nl.js +12 -12
- package/node_modules/moment/locale/nn.js +2 -3
- package/node_modules/moment/locale/oc-lnc.js +8 -6
- package/node_modules/moment/locale/pa-in.js +4 -3
- package/node_modules/moment/locale/pl.js +10 -9
- package/node_modules/moment/locale/pt-br.js +4 -3
- package/node_modules/moment/locale/pt.js +4 -3
- package/node_modules/moment/locale/ro.js +4 -3
- package/node_modules/moment/locale/ru.js +20 -13
- package/node_modules/moment/locale/se.js +6 -6
- package/node_modules/moment/locale/si.js +4 -3
- package/node_modules/moment/locale/sk.js +4 -3
- package/node_modules/moment/locale/sl.js +4 -3
- package/node_modules/moment/locale/sr-cyrl.js +32 -22
- package/node_modules/moment/locale/sr.js +32 -22
- package/node_modules/moment/locale/ss.js +4 -3
- package/node_modules/moment/locale/sw.js +4 -3
- package/node_modules/moment/locale/ta.js +8 -6
- package/node_modules/moment/locale/te.js +8 -6
- package/node_modules/moment/locale/tg.js +4 -3
- package/node_modules/moment/locale/th.js +4 -3
- package/node_modules/moment/locale/tlh.js +8 -9
- package/node_modules/moment/locale/tr.js +1 -1
- package/node_modules/moment/locale/tzm-latn.js +4 -3
- package/node_modules/moment/locale/tzm.js +4 -3
- package/node_modules/moment/locale/ug-cn.js +4 -3
- package/node_modules/moment/locale/uk.js +16 -12
- package/node_modules/moment/locale/uz-latn.js +4 -3
- package/node_modules/moment/locale/vi.js +4 -3
- package/node_modules/moment/locale/x-pseudo.js +8 -6
- package/node_modules/moment/min/locales.js +613 -474
- package/node_modules/moment/min/locales.min.js +1 -1
- package/node_modules/moment/min/locales.min.js.map +1 -1
- package/node_modules/moment/min/moment-with-locales.js +707 -553
- package/node_modules/moment/min/moment-with-locales.min.js +1 -1
- package/node_modules/moment/min/moment-with-locales.min.js.map +1 -1
- package/node_modules/moment/min/moment.min.js +1 -1
- package/node_modules/moment/min/moment.min.js.map +1 -1
- package/node_modules/moment/moment.js +95 -80
- package/node_modules/moment/package.json +4 -4
- package/node_modules/moment/src/lib/create/from-string-and-array.js +4 -3
- package/node_modules/moment/src/lib/create/from-string-and-format.js +4 -3
- package/node_modules/moment/src/lib/create/from-string.js +11 -7
- package/node_modules/moment/src/lib/duration/create.js +2 -1
- package/node_modules/moment/src/lib/duration/valid.js +3 -2
- package/node_modules/moment/src/lib/format/format.js +2 -1
- package/node_modules/moment/src/lib/locale/locales.js +7 -1
- package/node_modules/moment/src/lib/moment/constructor.js +6 -3
- package/node_modules/moment/src/lib/moment/get-set.js +3 -2
- package/node_modules/moment/src/lib/parse/regex.js +8 -10
- package/node_modules/moment/src/lib/parse/token.js +4 -2
- package/node_modules/moment/src/lib/units/day-of-week.js +2 -3
- package/node_modules/moment/src/lib/units/era.js +10 -12
- package/node_modules/moment/src/lib/units/month.js +6 -6
- package/node_modules/moment/src/lib/units/week-year.js +6 -8
- package/node_modules/moment/src/lib/units/week.js +6 -8
- package/node_modules/moment/src/lib/utils/deprecate.js +3 -2
- package/node_modules/moment/src/lib/utils/is-moment-input.js +3 -2
- package/node_modules/moment/src/lib/utils/map.js +3 -2
- package/node_modules/moment/src/locale/ar-kw.js +4 -3
- package/node_modules/moment/src/locale/ar-ly.js +1 -1
- package/node_modules/moment/src/locale/ar-ma.js +4 -3
- package/node_modules/moment/src/locale/ar-sa.js +4 -3
- package/node_modules/moment/src/locale/ar-tn.js +4 -3
- package/node_modules/moment/src/locale/az.js +4 -3
- package/node_modules/moment/src/locale/be.js +10 -9
- package/node_modules/moment/src/locale/bn-bd.js +4 -3
- package/node_modules/moment/src/locale/bn.js +4 -3
- package/node_modules/moment/src/locale/bo.js +8 -6
- package/node_modules/moment/src/locale/br.js +6 -3
- package/node_modules/moment/src/locale/bs.js +4 -3
- package/node_modules/moment/src/locale/ca.js +12 -9
- package/node_modules/moment/src/locale/cs.js +15 -6
- package/node_modules/moment/src/locale/cv.js +4 -3
- package/node_modules/moment/src/locale/cy.js +4 -3
- package/node_modules/moment/src/locale/de-at.js +6 -6
- package/node_modules/moment/src/locale/de-ch.js +6 -6
- package/node_modules/moment/src/locale/de.js +6 -6
- package/node_modules/moment/src/locale/el.js +8 -6
- package/node_modules/moment/src/locale/es-do.js +10 -6
- package/node_modules/moment/src/locale/es-mx.js +10 -6
- package/node_modules/moment/src/locale/es-us.js +10 -6
- package/node_modules/moment/src/locale/es.js +10 -6
- package/node_modules/moment/src/locale/et.js +6 -6
- package/node_modules/moment/src/locale/eu.js +8 -6
- package/node_modules/moment/src/locale/fa.js +12 -9
- package/node_modules/moment/src/locale/fi.js +12 -9
- package/node_modules/moment/src/locale/fo.js +4 -3
- package/node_modules/moment/src/locale/fr-ca.js +4 -3
- package/node_modules/moment/src/locale/fr-ch.js +4 -3
- package/node_modules/moment/src/locale/fr.js +10 -6
- package/node_modules/moment/src/locale/fy.js +4 -6
- package/node_modules/moment/src/locale/gl.js +4 -3
- package/node_modules/moment/src/locale/gom-deva.js +8 -6
- package/node_modules/moment/src/locale/gom-latn.js +6 -6
- package/node_modules/moment/src/locale/gu.js +4 -3
- package/node_modules/moment/src/locale/he.js +4 -4
- package/node_modules/moment/src/locale/hi.js +14 -10
- package/node_modules/moment/src/locale/hr.js +7 -5
- package/node_modules/moment/src/locale/hu.js +6 -6
- package/node_modules/moment/src/locale/hy-am.js +8 -6
- package/node_modules/moment/src/locale/is.js +4 -3
- package/node_modules/moment/src/locale/ka.js +10 -10
- package/node_modules/moment/src/locale/km.js +4 -3
- package/node_modules/moment/src/locale/kn.js +4 -3
- package/node_modules/moment/src/locale/ku.js +6 -6
- package/node_modules/moment/src/locale/lb.js +8 -6
- package/node_modules/moment/src/locale/lo.js +4 -3
- package/node_modules/moment/src/locale/lt.js +8 -6
- package/node_modules/moment/src/locale/lv.js +4 -3
- package/node_modules/moment/src/locale/me.js +2 -3
- package/node_modules/moment/src/locale/mi.js +4 -3
- package/node_modules/moment/src/locale/ml.js +8 -6
- package/node_modules/moment/src/locale/mn.js +4 -3
- package/node_modules/moment/src/locale/mr.js +4 -3
- package/node_modules/moment/src/locale/mt.js +4 -3
- package/node_modules/moment/src/locale/nb.js +2 -3
- package/node_modules/moment/src/locale/ne.js +4 -3
- package/node_modules/moment/src/locale/nl-be.js +12 -12
- package/node_modules/moment/src/locale/nl.js +12 -12
- package/node_modules/moment/src/locale/nn.js +2 -3
- package/node_modules/moment/src/locale/oc-lnc.js +8 -6
- package/node_modules/moment/src/locale/pa-in.js +4 -3
- package/node_modules/moment/src/locale/pl.js +10 -9
- package/node_modules/moment/src/locale/pt-br.js +4 -3
- package/node_modules/moment/src/locale/pt.js +4 -3
- package/node_modules/moment/src/locale/ro.js +4 -3
- package/node_modules/moment/src/locale/ru.js +20 -13
- package/node_modules/moment/src/locale/se.js +6 -6
- package/node_modules/moment/src/locale/si.js +4 -3
- package/node_modules/moment/src/locale/sk.js +4 -3
- package/node_modules/moment/src/locale/sl.js +4 -3
- package/node_modules/moment/src/locale/sr-cyrl.js +32 -22
- package/node_modules/moment/src/locale/sr.js +32 -22
- package/node_modules/moment/src/locale/ss.js +4 -3
- package/node_modules/moment/src/locale/sw.js +4 -3
- package/node_modules/moment/src/locale/ta.js +8 -6
- package/node_modules/moment/src/locale/te.js +8 -6
- package/node_modules/moment/src/locale/tg.js +4 -3
- package/node_modules/moment/src/locale/th.js +4 -3
- package/node_modules/moment/src/locale/tlh.js +8 -9
- package/node_modules/moment/src/locale/tr.js +1 -1
- package/node_modules/moment/src/locale/tzm-latn.js +4 -3
- package/node_modules/moment/src/locale/tzm.js +4 -3
- package/node_modules/moment/src/locale/ug-cn.js +4 -3
- package/node_modules/moment/src/locale/uk.js +16 -12
- package/node_modules/moment/src/locale/uz-latn.js +4 -3
- package/node_modules/moment/src/locale/vi.js +4 -3
- package/node_modules/moment/src/locale/x-pseudo.js +8 -6
- package/node_modules/moment/src/moment.js +2 -2
- package/node_modules/moment/ts3.1-typings/moment.d.ts +1 -1
- package/node_modules/safe-stable-stringify/CHANGELOG.md +75 -0
- package/node_modules/safe-stable-stringify/LICENSE +21 -0
- package/node_modules/safe-stable-stringify/esm/package.json +4 -0
- package/node_modules/safe-stable-stringify/esm/wrapper.js +6 -0
- package/node_modules/safe-stable-stringify/index.d.ts +18 -0
- package/node_modules/safe-stable-stringify/index.js +618 -0
- package/node_modules/safe-stable-stringify/package.json +69 -0
- package/node_modules/safe-stable-stringify/readme.md +170 -0
- package/node_modules/safe-stable-stringify/tsconfig.json +22 -0
- package/node_modules/winston/LICENSE +18 -18
- package/node_modules/winston/README.md +1231 -1230
- package/node_modules/winston/dist/winston/common.js +10 -10
- package/node_modules/winston/dist/winston/config/index.js +17 -17
- package/node_modules/winston/dist/winston/container.js +46 -46
- package/node_modules/winston/dist/winston/create-logger.js +28 -24
- package/node_modules/winston/dist/winston/exception-handler.js +49 -49
- package/node_modules/winston/dist/winston/exception-stream.js +27 -27
- package/node_modules/winston/dist/winston/logger.js +152 -138
- package/node_modules/winston/dist/winston/profiler.js +22 -22
- package/node_modules/winston/dist/winston/rejection-handler.js +54 -54
- package/node_modules/winston/dist/winston/tail-file.js +14 -14
- package/node_modules/winston/dist/winston/transports/console.js +31 -31
- package/node_modules/winston/dist/winston/transports/file.js +101 -101
- package/node_modules/winston/dist/winston/transports/http.js +119 -41
- package/node_modules/winston/dist/winston/transports/index.js +17 -17
- package/node_modules/winston/dist/winston/transports/stream.js +24 -24
- package/node_modules/winston/dist/winston.js +91 -97
- package/node_modules/winston/index.d.ts +213 -193
- package/node_modules/winston/lib/winston/common.js +61 -61
- package/node_modules/winston/lib/winston/config/index.d.ts +99 -98
- package/node_modules/winston/lib/winston/config/index.js +35 -35
- package/node_modules/winston/lib/winston/container.js +114 -114
- package/node_modules/winston/lib/winston/create-logger.js +104 -104
- package/node_modules/winston/lib/winston/exception-handler.js +245 -245
- package/node_modules/winston/lib/winston/exception-stream.js +54 -54
- package/node_modules/winston/lib/winston/logger.js +676 -667
- package/node_modules/winston/lib/winston/profiler.js +51 -51
- package/node_modules/winston/lib/winston/rejection-handler.js +251 -251
- package/node_modules/winston/lib/winston/tail-file.js +124 -124
- package/node_modules/winston/lib/winston/transports/console.js +117 -117
- package/node_modules/winston/lib/winston/transports/file.js +695 -695
- package/node_modules/winston/lib/winston/transports/http.js +267 -202
- package/node_modules/winston/lib/winston/transports/index.d.ts +103 -100
- package/node_modules/winston/lib/winston/transports/index.js +56 -56
- package/node_modules/winston/lib/winston/transports/stream.js +63 -63
- package/node_modules/winston/lib/winston.js +176 -182
- package/node_modules/winston/node_modules/winston-transport/.babelrc +3 -0
- package/node_modules/winston/node_modules/winston-transport/.eslintrc +7 -0
- package/node_modules/winston/node_modules/winston-transport/.gitattributes +1 -0
- package/node_modules/winston/node_modules/winston-transport/.nyc_output/c3d7ddb9-cc26-466b-a4f6-993ad69e86f6.json +1 -0
- package/node_modules/winston/node_modules/winston-transport/.nyc_output/processinfo/c3d7ddb9-cc26-466b-a4f6-993ad69e86f6.json +1 -0
- package/node_modules/winston/node_modules/winston-transport/.nyc_output/processinfo/index.json +1 -0
- package/node_modules/winston/node_modules/winston-transport/CHANGELOG.md +126 -0
- package/node_modules/winston/node_modules/winston-transport/LICENSE +22 -0
- package/node_modules/winston/node_modules/winston-transport/README.md +50 -0
- package/node_modules/winston/node_modules/winston-transport/dist/index.js +215 -0
- package/node_modules/winston/node_modules/winston-transport/dist/legacy.js +116 -0
- package/node_modules/winston/node_modules/winston-transport/index.d.ts +39 -0
- package/node_modules/winston/node_modules/winston-transport/index.js +215 -0
- package/node_modules/winston/node_modules/winston-transport/legacy.js +119 -0
- package/node_modules/winston/node_modules/winston-transport/package.json +56 -0
- package/node_modules/winston/package.json +76 -75
- package/package.json +6 -4
- package/node_modules/@dabh/diagnostics/example.png +0 -0
- package/node_modules/color-string/CHANGELOG.md +0 -18
- package/node_modules/colorspace/test.js +0 -14
- package/node_modules/fecha/CHANGELOG.md +0 -67
- package/node_modules/logform/.travis.yml +0 -17
- package/node_modules/winston/CHANGELOG.md +0 -560
|
@@ -56,6 +56,7 @@ function initialParams (fn) {
|
|
|
56
56
|
|
|
57
57
|
/* istanbul ignore file */
|
|
58
58
|
|
|
59
|
+
var hasQueueMicrotask = typeof queueMicrotask === 'function' && queueMicrotask;
|
|
59
60
|
var hasSetImmediate = typeof setImmediate === 'function' && setImmediate;
|
|
60
61
|
var hasNextTick = typeof process === 'object' && typeof process.nextTick === 'function';
|
|
61
62
|
|
|
@@ -69,7 +70,9 @@ function wrap(defer) {
|
|
|
69
70
|
|
|
70
71
|
var _defer;
|
|
71
72
|
|
|
72
|
-
if (
|
|
73
|
+
if (hasQueueMicrotask) {
|
|
74
|
+
_defer = queueMicrotask;
|
|
75
|
+
} else if (hasSetImmediate) {
|
|
73
76
|
_defer = setImmediate;
|
|
74
77
|
} else if (hasNextTick) {
|
|
75
78
|
_defer = process.nextTick;
|
|
@@ -294,6 +297,9 @@ function createObjectIterator(obj) {
|
|
|
294
297
|
var len = okeys.length;
|
|
295
298
|
return function next() {
|
|
296
299
|
var key = okeys[++i];
|
|
300
|
+
if (key === '__proto__') {
|
|
301
|
+
return next();
|
|
302
|
+
}
|
|
297
303
|
return i < len ? {value: obj[key], key} : null;
|
|
298
304
|
};
|
|
299
305
|
}
|
|
@@ -521,12 +527,19 @@ function eachOfGeneric (coll, iteratee, callback) {
|
|
|
521
527
|
* @returns {Promise} a promise, if a callback is omitted
|
|
522
528
|
* @example
|
|
523
529
|
*
|
|
524
|
-
*
|
|
525
|
-
*
|
|
530
|
+
* // dev.json is a file containing a valid json object config for dev environment
|
|
531
|
+
* // dev.json is a file containing a valid json object config for test environment
|
|
532
|
+
* // prod.json is a file containing a valid json object config for prod environment
|
|
533
|
+
* // invalid.json is a file with a malformed json object
|
|
526
534
|
*
|
|
527
|
-
*
|
|
528
|
-
*
|
|
529
|
-
*
|
|
535
|
+
* let configs = {}; //global variable
|
|
536
|
+
* let validConfigFileMap = {dev: 'dev.json', test: 'test.json', prod: 'prod.json'};
|
|
537
|
+
* let invalidConfigFileMap = {dev: 'dev.json', test: 'test.json', invalid: 'invalid.json'};
|
|
538
|
+
*
|
|
539
|
+
* // asynchronous function that reads a json file and parses the contents as json object
|
|
540
|
+
* function parseFile(file, key, callback) {
|
|
541
|
+
* fs.readFile(file, "utf8", function(err, data) {
|
|
542
|
+
* if (err) return calback(err);
|
|
530
543
|
* try {
|
|
531
544
|
* configs[key] = JSON.parse(data);
|
|
532
545
|
* } catch (e) {
|
|
@@ -534,11 +547,73 @@ function eachOfGeneric (coll, iteratee, callback) {
|
|
|
534
547
|
* }
|
|
535
548
|
* callback();
|
|
536
549
|
* });
|
|
537
|
-
* }
|
|
538
|
-
*
|
|
539
|
-
*
|
|
540
|
-
*
|
|
550
|
+
* }
|
|
551
|
+
*
|
|
552
|
+
* // Using callbacks
|
|
553
|
+
* async.forEachOf(validConfigFileMap, parseFile, function (err) {
|
|
554
|
+
* if (err) {
|
|
555
|
+
* console.error(err);
|
|
556
|
+
* } else {
|
|
557
|
+
* console.log(configs);
|
|
558
|
+
* // configs is now a map of JSON data, e.g.
|
|
559
|
+
* // { dev: //parsed dev.json, test: //parsed test.json, prod: //parsed prod.json}
|
|
560
|
+
* }
|
|
541
561
|
* });
|
|
562
|
+
*
|
|
563
|
+
* //Error handing
|
|
564
|
+
* async.forEachOf(invalidConfigFileMap, parseFile, function (err) {
|
|
565
|
+
* if (err) {
|
|
566
|
+
* console.error(err);
|
|
567
|
+
* // JSON parse error exception
|
|
568
|
+
* } else {
|
|
569
|
+
* console.log(configs);
|
|
570
|
+
* }
|
|
571
|
+
* });
|
|
572
|
+
*
|
|
573
|
+
* // Using Promises
|
|
574
|
+
* async.forEachOf(validConfigFileMap, parseFile)
|
|
575
|
+
* .then( () => {
|
|
576
|
+
* console.log(configs);
|
|
577
|
+
* // configs is now a map of JSON data, e.g.
|
|
578
|
+
* // { dev: //parsed dev.json, test: //parsed test.json, prod: //parsed prod.json}
|
|
579
|
+
* }).catch( err => {
|
|
580
|
+
* console.error(err);
|
|
581
|
+
* });
|
|
582
|
+
*
|
|
583
|
+
* //Error handing
|
|
584
|
+
* async.forEachOf(invalidConfigFileMap, parseFile)
|
|
585
|
+
* .then( () => {
|
|
586
|
+
* console.log(configs);
|
|
587
|
+
* }).catch( err => {
|
|
588
|
+
* console.error(err);
|
|
589
|
+
* // JSON parse error exception
|
|
590
|
+
* });
|
|
591
|
+
*
|
|
592
|
+
* // Using async/await
|
|
593
|
+
* async () => {
|
|
594
|
+
* try {
|
|
595
|
+
* let result = await async.forEachOf(validConfigFileMap, parseFile);
|
|
596
|
+
* console.log(configs);
|
|
597
|
+
* // configs is now a map of JSON data, e.g.
|
|
598
|
+
* // { dev: //parsed dev.json, test: //parsed test.json, prod: //parsed prod.json}
|
|
599
|
+
* }
|
|
600
|
+
* catch (err) {
|
|
601
|
+
* console.log(err);
|
|
602
|
+
* }
|
|
603
|
+
* }
|
|
604
|
+
*
|
|
605
|
+
* //Error handing
|
|
606
|
+
* async () => {
|
|
607
|
+
* try {
|
|
608
|
+
* let result = await async.forEachOf(invalidConfigFileMap, parseFile);
|
|
609
|
+
* console.log(configs);
|
|
610
|
+
* }
|
|
611
|
+
* catch (err) {
|
|
612
|
+
* console.log(err);
|
|
613
|
+
* // JSON parse error exception
|
|
614
|
+
* }
|
|
615
|
+
* }
|
|
616
|
+
*
|
|
542
617
|
*/
|
|
543
618
|
function eachOf(coll, iteratee, callback) {
|
|
544
619
|
var eachOfImplementation = isArrayLike(coll) ? eachOfArrayLike : eachOfGeneric;
|
|
@@ -550,7 +625,7 @@ var eachOf$1 = awaitify(eachOf, 3);
|
|
|
550
625
|
/**
|
|
551
626
|
* Produces a new collection of values by mapping each value in `coll` through
|
|
552
627
|
* the `iteratee` function. The `iteratee` is called with an item from `coll`
|
|
553
|
-
* and a callback for when it has finished processing. Each of these
|
|
628
|
+
* and a callback for when it has finished processing. Each of these callbacks
|
|
554
629
|
* takes 2 arguments: an `error`, and the transformed item from `coll`. If
|
|
555
630
|
* `iteratee` passes an error to its callback, the main `callback` (for the
|
|
556
631
|
* `map` function) is immediately called with the error.
|
|
@@ -580,9 +655,89 @@ var eachOf$1 = awaitify(eachOf, 3);
|
|
|
580
655
|
* @returns {Promise} a promise, if no callback is passed
|
|
581
656
|
* @example
|
|
582
657
|
*
|
|
583
|
-
*
|
|
584
|
-
*
|
|
658
|
+
* // file1.txt is a file that is 1000 bytes in size
|
|
659
|
+
* // file2.txt is a file that is 2000 bytes in size
|
|
660
|
+
* // file3.txt is a file that is 3000 bytes in size
|
|
661
|
+
* // file4.txt does not exist
|
|
662
|
+
*
|
|
663
|
+
* const fileList = ['file1.txt','file2.txt','file3.txt'];
|
|
664
|
+
* const withMissingFileList = ['file1.txt','file2.txt','file4.txt'];
|
|
665
|
+
*
|
|
666
|
+
* // asynchronous function that returns the file size in bytes
|
|
667
|
+
* function getFileSizeInBytes(file, callback) {
|
|
668
|
+
* fs.stat(file, function(err, stat) {
|
|
669
|
+
* if (err) {
|
|
670
|
+
* return callback(err);
|
|
671
|
+
* }
|
|
672
|
+
* callback(null, stat.size);
|
|
673
|
+
* });
|
|
674
|
+
* }
|
|
675
|
+
*
|
|
676
|
+
* // Using callbacks
|
|
677
|
+
* async.map(fileList, getFileSizeInBytes, function(err, results) {
|
|
678
|
+
* if (err) {
|
|
679
|
+
* console.log(err);
|
|
680
|
+
* } else {
|
|
681
|
+
* console.log(results);
|
|
682
|
+
* // results is now an array of the file size in bytes for each file, e.g.
|
|
683
|
+
* // [ 1000, 2000, 3000]
|
|
684
|
+
* }
|
|
685
|
+
* });
|
|
686
|
+
*
|
|
687
|
+
* // Error Handling
|
|
688
|
+
* async.map(withMissingFileList, getFileSizeInBytes, function(err, results) {
|
|
689
|
+
* if (err) {
|
|
690
|
+
* console.log(err);
|
|
691
|
+
* // [ Error: ENOENT: no such file or directory ]
|
|
692
|
+
* } else {
|
|
693
|
+
* console.log(results);
|
|
694
|
+
* }
|
|
695
|
+
* });
|
|
696
|
+
*
|
|
697
|
+
* // Using Promises
|
|
698
|
+
* async.map(fileList, getFileSizeInBytes)
|
|
699
|
+
* .then( results => {
|
|
700
|
+
* console.log(results);
|
|
701
|
+
* // results is now an array of the file size in bytes for each file, e.g.
|
|
702
|
+
* // [ 1000, 2000, 3000]
|
|
703
|
+
* }).catch( err => {
|
|
704
|
+
* console.log(err);
|
|
585
705
|
* });
|
|
706
|
+
*
|
|
707
|
+
* // Error Handling
|
|
708
|
+
* async.map(withMissingFileList, getFileSizeInBytes)
|
|
709
|
+
* .then( results => {
|
|
710
|
+
* console.log(results);
|
|
711
|
+
* }).catch( err => {
|
|
712
|
+
* console.log(err);
|
|
713
|
+
* // [ Error: ENOENT: no such file or directory ]
|
|
714
|
+
* });
|
|
715
|
+
*
|
|
716
|
+
* // Using async/await
|
|
717
|
+
* async () => {
|
|
718
|
+
* try {
|
|
719
|
+
* let results = await async.map(fileList, getFileSizeInBytes);
|
|
720
|
+
* console.log(results);
|
|
721
|
+
* // results is now an array of the file size in bytes for each file, e.g.
|
|
722
|
+
* // [ 1000, 2000, 3000]
|
|
723
|
+
* }
|
|
724
|
+
* catch (err) {
|
|
725
|
+
* console.log(err);
|
|
726
|
+
* }
|
|
727
|
+
* }
|
|
728
|
+
*
|
|
729
|
+
* // Error Handling
|
|
730
|
+
* async () => {
|
|
731
|
+
* try {
|
|
732
|
+
* let results = await async.map(withMissingFileList, getFileSizeInBytes);
|
|
733
|
+
* console.log(results);
|
|
734
|
+
* }
|
|
735
|
+
* catch (err) {
|
|
736
|
+
* console.log(err);
|
|
737
|
+
* // [ Error: ENOENT: no such file or directory ]
|
|
738
|
+
* }
|
|
739
|
+
* }
|
|
740
|
+
*
|
|
586
741
|
*/
|
|
587
742
|
function map (coll, iteratee, callback) {
|
|
588
743
|
return _asyncMap(eachOf$1, coll, iteratee, callback)
|
|
@@ -756,15 +911,40 @@ function promiseCallback () {
|
|
|
756
911
|
* @returns {Promise} a promise, if a callback is not passed
|
|
757
912
|
* @example
|
|
758
913
|
*
|
|
914
|
+
* //Using Callbacks
|
|
759
915
|
* async.auto({
|
|
760
|
-
*
|
|
761
|
-
*
|
|
762
|
-
*
|
|
763
|
-
*
|
|
764
|
-
*
|
|
916
|
+
* get_data: function(callback) {
|
|
917
|
+
* // async code to get some data
|
|
918
|
+
* callback(null, 'data', 'converted to array');
|
|
919
|
+
* },
|
|
920
|
+
* make_folder: function(callback) {
|
|
921
|
+
* // async code to create a directory to store a file in
|
|
922
|
+
* // this is run at the same time as getting the data
|
|
923
|
+
* callback(null, 'folder');
|
|
924
|
+
* },
|
|
925
|
+
* write_file: ['get_data', 'make_folder', function(results, callback) {
|
|
926
|
+
* // once there is some data and the directory exists,
|
|
927
|
+
* // write the data to a file in the directory
|
|
928
|
+
* callback(null, 'filename');
|
|
929
|
+
* }],
|
|
930
|
+
* email_link: ['write_file', function(results, callback) {
|
|
931
|
+
* // once the file is written let's email a link to it...
|
|
932
|
+
* callback(null, {'file':results.write_file, 'email':'user@example.com'});
|
|
765
933
|
* }]
|
|
766
|
-
* },
|
|
934
|
+
* }, function(err, results) {
|
|
935
|
+
* if (err) {
|
|
936
|
+
* console.log('err = ', err);
|
|
937
|
+
* }
|
|
938
|
+
* console.log('results = ', results);
|
|
939
|
+
* // results = {
|
|
940
|
+
* // get_data: ['data', 'converted to array']
|
|
941
|
+
* // make_folder; 'folder',
|
|
942
|
+
* // write_file: 'filename'
|
|
943
|
+
* // email_link: { file: 'filename', email: 'user@example.com' }
|
|
944
|
+
* // }
|
|
945
|
+
* });
|
|
767
946
|
*
|
|
947
|
+
* //Using Promises
|
|
768
948
|
* async.auto({
|
|
769
949
|
* get_data: function(callback) {
|
|
770
950
|
* console.log('in get_data');
|
|
@@ -778,21 +958,62 @@ function promiseCallback () {
|
|
|
778
958
|
* callback(null, 'folder');
|
|
779
959
|
* },
|
|
780
960
|
* write_file: ['get_data', 'make_folder', function(results, callback) {
|
|
781
|
-
* console.log('in write_file', JSON.stringify(results));
|
|
782
961
|
* // once there is some data and the directory exists,
|
|
783
962
|
* // write the data to a file in the directory
|
|
784
963
|
* callback(null, 'filename');
|
|
785
964
|
* }],
|
|
786
965
|
* email_link: ['write_file', function(results, callback) {
|
|
787
|
-
* console.log('in email_link', JSON.stringify(results));
|
|
788
966
|
* // once the file is written let's email a link to it...
|
|
789
|
-
* // results.write_file contains the filename returned by write_file.
|
|
790
967
|
* callback(null, {'file':results.write_file, 'email':'user@example.com'});
|
|
791
968
|
* }]
|
|
792
|
-
* }
|
|
793
|
-
* console.log('err = ', err);
|
|
969
|
+
* }).then(results => {
|
|
794
970
|
* console.log('results = ', results);
|
|
971
|
+
* // results = {
|
|
972
|
+
* // get_data: ['data', 'converted to array']
|
|
973
|
+
* // make_folder; 'folder',
|
|
974
|
+
* // write_file: 'filename'
|
|
975
|
+
* // email_link: { file: 'filename', email: 'user@example.com' }
|
|
976
|
+
* // }
|
|
977
|
+
* }).catch(err => {
|
|
978
|
+
* console.log('err = ', err);
|
|
795
979
|
* });
|
|
980
|
+
*
|
|
981
|
+
* //Using async/await
|
|
982
|
+
* async () => {
|
|
983
|
+
* try {
|
|
984
|
+
* let results = await async.auto({
|
|
985
|
+
* get_data: function(callback) {
|
|
986
|
+
* // async code to get some data
|
|
987
|
+
* callback(null, 'data', 'converted to array');
|
|
988
|
+
* },
|
|
989
|
+
* make_folder: function(callback) {
|
|
990
|
+
* // async code to create a directory to store a file in
|
|
991
|
+
* // this is run at the same time as getting the data
|
|
992
|
+
* callback(null, 'folder');
|
|
993
|
+
* },
|
|
994
|
+
* write_file: ['get_data', 'make_folder', function(results, callback) {
|
|
995
|
+
* // once there is some data and the directory exists,
|
|
996
|
+
* // write the data to a file in the directory
|
|
997
|
+
* callback(null, 'filename');
|
|
998
|
+
* }],
|
|
999
|
+
* email_link: ['write_file', function(results, callback) {
|
|
1000
|
+
* // once the file is written let's email a link to it...
|
|
1001
|
+
* callback(null, {'file':results.write_file, 'email':'user@example.com'});
|
|
1002
|
+
* }]
|
|
1003
|
+
* });
|
|
1004
|
+
* console.log('results = ', results);
|
|
1005
|
+
* // results = {
|
|
1006
|
+
* // get_data: ['data', 'converted to array']
|
|
1007
|
+
* // make_folder; 'folder',
|
|
1008
|
+
* // write_file: 'filename'
|
|
1009
|
+
* // email_link: { file: 'filename', email: 'user@example.com' }
|
|
1010
|
+
* // }
|
|
1011
|
+
* }
|
|
1012
|
+
* catch (err) {
|
|
1013
|
+
* console.log(err);
|
|
1014
|
+
* }
|
|
1015
|
+
* }
|
|
1016
|
+
*
|
|
796
1017
|
*/
|
|
797
1018
|
function auto(tasks, concurrency, callback) {
|
|
798
1019
|
if (typeof concurrency !== 'number') {
|
|
@@ -970,10 +1191,36 @@ var FN_ARGS = /^(?:async\s+)?(?:function)?\s*\w*\s*\(\s*([^)]+)\s*\)(?:\s*{)/;
|
|
|
970
1191
|
var ARROW_FN_ARGS = /^(?:async\s+)?\(?\s*([^)=]+)\s*\)?(?:\s*=>)/;
|
|
971
1192
|
var FN_ARG_SPLIT = /,/;
|
|
972
1193
|
var FN_ARG = /(=.+)?(\s*)$/;
|
|
973
|
-
|
|
1194
|
+
|
|
1195
|
+
function stripComments(string) {
|
|
1196
|
+
let stripped = '';
|
|
1197
|
+
let index = 0;
|
|
1198
|
+
let endBlockComment = string.indexOf('*/');
|
|
1199
|
+
while (index < string.length) {
|
|
1200
|
+
if (string[index] === '/' && string[index+1] === '/') {
|
|
1201
|
+
// inline comment
|
|
1202
|
+
let endIndex = string.indexOf('\n', index);
|
|
1203
|
+
index = (endIndex === -1) ? string.length : endIndex;
|
|
1204
|
+
} else if ((endBlockComment !== -1) && (string[index] === '/') && (string[index+1] === '*')) {
|
|
1205
|
+
// block comment
|
|
1206
|
+
let endIndex = string.indexOf('*/', index);
|
|
1207
|
+
if (endIndex !== -1) {
|
|
1208
|
+
index = endIndex + 2;
|
|
1209
|
+
endBlockComment = string.indexOf('*/', index);
|
|
1210
|
+
} else {
|
|
1211
|
+
stripped += string[index];
|
|
1212
|
+
index++;
|
|
1213
|
+
}
|
|
1214
|
+
} else {
|
|
1215
|
+
stripped += string[index];
|
|
1216
|
+
index++;
|
|
1217
|
+
}
|
|
1218
|
+
}
|
|
1219
|
+
return stripped;
|
|
1220
|
+
}
|
|
974
1221
|
|
|
975
1222
|
function parseParams(func) {
|
|
976
|
-
const src = func.toString()
|
|
1223
|
+
const src = stripComments(func.toString());
|
|
977
1224
|
let match = src.match(FN_ARGS);
|
|
978
1225
|
if (!match) {
|
|
979
1226
|
match = src.match(ARROW_FN_ARGS);
|
|
@@ -1600,7 +1847,7 @@ function cargo$1(worker, concurrency, payload) {
|
|
|
1600
1847
|
* @param {AsyncFunction} iteratee - A function applied to each item in the
|
|
1601
1848
|
* array to produce the next step in the reduction.
|
|
1602
1849
|
* The `iteratee` should complete with the next state of the reduction.
|
|
1603
|
-
* If the iteratee
|
|
1850
|
+
* If the iteratee completes with an error, the reduction is stopped and the
|
|
1604
1851
|
* main `callback` is immediately called with the error.
|
|
1605
1852
|
* Invoked with (memo, item, callback).
|
|
1606
1853
|
* @param {Function} [callback] - A callback which is called after all the
|
|
@@ -1609,14 +1856,90 @@ function cargo$1(worker, concurrency, payload) {
|
|
|
1609
1856
|
* @returns {Promise} a promise, if no callback is passed
|
|
1610
1857
|
* @example
|
|
1611
1858
|
*
|
|
1612
|
-
*
|
|
1613
|
-
*
|
|
1614
|
-
*
|
|
1615
|
-
*
|
|
1859
|
+
* // file1.txt is a file that is 1000 bytes in size
|
|
1860
|
+
* // file2.txt is a file that is 2000 bytes in size
|
|
1861
|
+
* // file3.txt is a file that is 3000 bytes in size
|
|
1862
|
+
* // file4.txt does not exist
|
|
1863
|
+
*
|
|
1864
|
+
* const fileList = ['file1.txt','file2.txt','file3.txt'];
|
|
1865
|
+
* const withMissingFileList = ['file1.txt','file2.txt','file3.txt', 'file4.txt'];
|
|
1866
|
+
*
|
|
1867
|
+
* // asynchronous function that computes the file size in bytes
|
|
1868
|
+
* // file size is added to the memoized value, then returned
|
|
1869
|
+
* function getFileSizeInBytes(memo, file, callback) {
|
|
1870
|
+
* fs.stat(file, function(err, stat) {
|
|
1871
|
+
* if (err) {
|
|
1872
|
+
* return callback(err);
|
|
1873
|
+
* }
|
|
1874
|
+
* callback(null, memo + stat.size);
|
|
1616
1875
|
* });
|
|
1617
|
-
* }
|
|
1618
|
-
*
|
|
1876
|
+
* }
|
|
1877
|
+
*
|
|
1878
|
+
* // Using callbacks
|
|
1879
|
+
* async.reduce(fileList, 0, getFileSizeInBytes, function(err, result) {
|
|
1880
|
+
* if (err) {
|
|
1881
|
+
* console.log(err);
|
|
1882
|
+
* } else {
|
|
1883
|
+
* console.log(result);
|
|
1884
|
+
* // 6000
|
|
1885
|
+
* // which is the sum of the file sizes of the three files
|
|
1886
|
+
* }
|
|
1887
|
+
* });
|
|
1888
|
+
*
|
|
1889
|
+
* // Error Handling
|
|
1890
|
+
* async.reduce(withMissingFileList, 0, getFileSizeInBytes, function(err, result) {
|
|
1891
|
+
* if (err) {
|
|
1892
|
+
* console.log(err);
|
|
1893
|
+
* // [ Error: ENOENT: no such file or directory ]
|
|
1894
|
+
* } else {
|
|
1895
|
+
* console.log(result);
|
|
1896
|
+
* }
|
|
1897
|
+
* });
|
|
1898
|
+
*
|
|
1899
|
+
* // Using Promises
|
|
1900
|
+
* async.reduce(fileList, 0, getFileSizeInBytes)
|
|
1901
|
+
* .then( result => {
|
|
1902
|
+
* console.log(result);
|
|
1903
|
+
* // 6000
|
|
1904
|
+
* // which is the sum of the file sizes of the three files
|
|
1905
|
+
* }).catch( err => {
|
|
1906
|
+
* console.log(err);
|
|
1619
1907
|
* });
|
|
1908
|
+
*
|
|
1909
|
+
* // Error Handling
|
|
1910
|
+
* async.reduce(withMissingFileList, 0, getFileSizeInBytes)
|
|
1911
|
+
* .then( result => {
|
|
1912
|
+
* console.log(result);
|
|
1913
|
+
* }).catch( err => {
|
|
1914
|
+
* console.log(err);
|
|
1915
|
+
* // [ Error: ENOENT: no such file or directory ]
|
|
1916
|
+
* });
|
|
1917
|
+
*
|
|
1918
|
+
* // Using async/await
|
|
1919
|
+
* async () => {
|
|
1920
|
+
* try {
|
|
1921
|
+
* let result = await async.reduce(fileList, 0, getFileSizeInBytes);
|
|
1922
|
+
* console.log(result);
|
|
1923
|
+
* // 6000
|
|
1924
|
+
* // which is the sum of the file sizes of the three files
|
|
1925
|
+
* }
|
|
1926
|
+
* catch (err) {
|
|
1927
|
+
* console.log(err);
|
|
1928
|
+
* }
|
|
1929
|
+
* }
|
|
1930
|
+
*
|
|
1931
|
+
* // Error Handling
|
|
1932
|
+
* async () => {
|
|
1933
|
+
* try {
|
|
1934
|
+
* let result = await async.reduce(withMissingFileList, 0, getFileSizeInBytes);
|
|
1935
|
+
* console.log(result);
|
|
1936
|
+
* }
|
|
1937
|
+
* catch (err) {
|
|
1938
|
+
* console.log(err);
|
|
1939
|
+
* // [ Error: ENOENT: no such file or directory ]
|
|
1940
|
+
* }
|
|
1941
|
+
* }
|
|
1942
|
+
*
|
|
1620
1943
|
*/
|
|
1621
1944
|
function reduce(coll, memo, iteratee, callback) {
|
|
1622
1945
|
callback = once(callback);
|
|
@@ -1654,7 +1977,7 @@ var reduce$1 = awaitify(reduce, 4);
|
|
|
1654
1977
|
* app.get('/cats', function(request, response) {
|
|
1655
1978
|
* var User = request.models.User;
|
|
1656
1979
|
* async.seq(
|
|
1657
|
-
*
|
|
1980
|
+
* User.get.bind(User), // 'User.get' has signature (id, callback(err, data))
|
|
1658
1981
|
* function(user, fn) {
|
|
1659
1982
|
* user.getCats(fn); // 'getCats' has signature (callback(err, data))
|
|
1660
1983
|
* }
|
|
@@ -1820,9 +2143,77 @@ var concatLimit$1 = awaitify(concatLimit, 4);
|
|
|
1820
2143
|
* @returns A Promise, if no callback is passed
|
|
1821
2144
|
* @example
|
|
1822
2145
|
*
|
|
1823
|
-
*
|
|
1824
|
-
*
|
|
2146
|
+
* // dir1 is a directory that contains file1.txt, file2.txt
|
|
2147
|
+
* // dir2 is a directory that contains file3.txt, file4.txt
|
|
2148
|
+
* // dir3 is a directory that contains file5.txt
|
|
2149
|
+
* // dir4 does not exist
|
|
2150
|
+
*
|
|
2151
|
+
* let directoryList = ['dir1','dir2','dir3'];
|
|
2152
|
+
* let withMissingDirectoryList = ['dir1','dir2','dir3', 'dir4'];
|
|
2153
|
+
*
|
|
2154
|
+
* // Using callbacks
|
|
2155
|
+
* async.concat(directoryList, fs.readdir, function(err, results) {
|
|
2156
|
+
* if (err) {
|
|
2157
|
+
* console.log(err);
|
|
2158
|
+
* } else {
|
|
2159
|
+
* console.log(results);
|
|
2160
|
+
* // [ 'file1.txt', 'file2.txt', 'file3.txt', 'file4.txt', file5.txt ]
|
|
2161
|
+
* }
|
|
2162
|
+
* });
|
|
2163
|
+
*
|
|
2164
|
+
* // Error Handling
|
|
2165
|
+
* async.concat(withMissingDirectoryList, fs.readdir, function(err, results) {
|
|
2166
|
+
* if (err) {
|
|
2167
|
+
* console.log(err);
|
|
2168
|
+
* // [ Error: ENOENT: no such file or directory ]
|
|
2169
|
+
* // since dir4 does not exist
|
|
2170
|
+
* } else {
|
|
2171
|
+
* console.log(results);
|
|
2172
|
+
* }
|
|
2173
|
+
* });
|
|
2174
|
+
*
|
|
2175
|
+
* // Using Promises
|
|
2176
|
+
* async.concat(directoryList, fs.readdir)
|
|
2177
|
+
* .then(results => {
|
|
2178
|
+
* console.log(results);
|
|
2179
|
+
* // [ 'file1.txt', 'file2.txt', 'file3.txt', 'file4.txt', file5.txt ]
|
|
2180
|
+
* }).catch(err => {
|
|
2181
|
+
* console.log(err);
|
|
2182
|
+
* });
|
|
2183
|
+
*
|
|
2184
|
+
* // Error Handling
|
|
2185
|
+
* async.concat(withMissingDirectoryList, fs.readdir)
|
|
2186
|
+
* .then(results => {
|
|
2187
|
+
* console.log(results);
|
|
2188
|
+
* }).catch(err => {
|
|
2189
|
+
* console.log(err);
|
|
2190
|
+
* // [ Error: ENOENT: no such file or directory ]
|
|
2191
|
+
* // since dir4 does not exist
|
|
1825
2192
|
* });
|
|
2193
|
+
*
|
|
2194
|
+
* // Using async/await
|
|
2195
|
+
* async () => {
|
|
2196
|
+
* try {
|
|
2197
|
+
* let results = await async.concat(directoryList, fs.readdir);
|
|
2198
|
+
* console.log(results);
|
|
2199
|
+
* // [ 'file1.txt', 'file2.txt', 'file3.txt', 'file4.txt', file5.txt ]
|
|
2200
|
+
* } catch (err) {
|
|
2201
|
+
* console.log(err);
|
|
2202
|
+
* }
|
|
2203
|
+
* }
|
|
2204
|
+
*
|
|
2205
|
+
* // Error Handling
|
|
2206
|
+
* async () => {
|
|
2207
|
+
* try {
|
|
2208
|
+
* let results = await async.concat(withMissingDirectoryList, fs.readdir);
|
|
2209
|
+
* console.log(results);
|
|
2210
|
+
* } catch (err) {
|
|
2211
|
+
* console.log(err);
|
|
2212
|
+
* // [ Error: ENOENT: no such file or directory ]
|
|
2213
|
+
* // since dir4 does not exist
|
|
2214
|
+
* }
|
|
2215
|
+
* }
|
|
2216
|
+
*
|
|
1826
2217
|
*/
|
|
1827
2218
|
function concat(coll, iteratee, callback) {
|
|
1828
2219
|
return concatLimit$1(coll, Infinity, iteratee, callback)
|
|
@@ -1954,13 +2345,48 @@ function _createTester(check, getResult) {
|
|
|
1954
2345
|
* @returns A Promise, if no callback is passed
|
|
1955
2346
|
* @example
|
|
1956
2347
|
*
|
|
1957
|
-
*
|
|
1958
|
-
*
|
|
1959
|
-
*
|
|
1960
|
-
*
|
|
1961
|
-
*
|
|
2348
|
+
* // dir1 is a directory that contains file1.txt, file2.txt
|
|
2349
|
+
* // dir2 is a directory that contains file3.txt, file4.txt
|
|
2350
|
+
* // dir3 is a directory that contains file5.txt
|
|
2351
|
+
*
|
|
2352
|
+
* // asynchronous function that checks if a file exists
|
|
2353
|
+
* function fileExists(file, callback) {
|
|
2354
|
+
* fs.access(file, fs.constants.F_OK, (err) => {
|
|
2355
|
+
* callback(null, !err);
|
|
2356
|
+
* });
|
|
2357
|
+
* }
|
|
2358
|
+
*
|
|
2359
|
+
* async.detect(['file3.txt','file2.txt','dir1/file1.txt'], fileExists,
|
|
2360
|
+
* function(err, result) {
|
|
2361
|
+
* console.log(result);
|
|
2362
|
+
* // dir1/file1.txt
|
|
2363
|
+
* // result now equals the first file in the list that exists
|
|
2364
|
+
* }
|
|
2365
|
+
*);
|
|
2366
|
+
*
|
|
2367
|
+
* // Using Promises
|
|
2368
|
+
* async.detect(['file3.txt','file2.txt','dir1/file1.txt'], fileExists)
|
|
2369
|
+
* .then(result => {
|
|
2370
|
+
* console.log(result);
|
|
2371
|
+
* // dir1/file1.txt
|
|
1962
2372
|
* // result now equals the first file in the list that exists
|
|
2373
|
+
* }).catch(err => {
|
|
2374
|
+
* console.log(err);
|
|
1963
2375
|
* });
|
|
2376
|
+
*
|
|
2377
|
+
* // Using async/await
|
|
2378
|
+
* async () => {
|
|
2379
|
+
* try {
|
|
2380
|
+
* let result = await async.detect(['file3.txt','file2.txt','dir1/file1.txt'], fileExists);
|
|
2381
|
+
* console.log(result);
|
|
2382
|
+
* // dir1/file1.txt
|
|
2383
|
+
* // result now equals the file in the list that exists
|
|
2384
|
+
* }
|
|
2385
|
+
* catch (err) {
|
|
2386
|
+
* console.log(err);
|
|
2387
|
+
* }
|
|
2388
|
+
* }
|
|
2389
|
+
*
|
|
1964
2390
|
*/
|
|
1965
2391
|
function detect(coll, iteratee, callback) {
|
|
1966
2392
|
return _createTester(bool => bool, (res, item) => item)(eachOf$1, coll, iteratee, callback)
|
|
@@ -2024,12 +2450,15 @@ var detectSeries$1 = awaitify(detectSeries, 3);
|
|
|
2024
2450
|
|
|
2025
2451
|
function consoleFunc(name) {
|
|
2026
2452
|
return (fn, ...args) => wrapAsync(fn)(...args, (err, ...resultArgs) => {
|
|
2453
|
+
/* istanbul ignore else */
|
|
2027
2454
|
if (typeof console === 'object') {
|
|
2455
|
+
/* istanbul ignore else */
|
|
2028
2456
|
if (err) {
|
|
2457
|
+
/* istanbul ignore else */
|
|
2029
2458
|
if (console.error) {
|
|
2030
2459
|
console.error(err);
|
|
2031
2460
|
}
|
|
2032
|
-
} else if (console[name]) {
|
|
2461
|
+
} else if (console[name]) { /* istanbul ignore else */
|
|
2033
2462
|
resultArgs.forEach(x => console[name](x));
|
|
2034
2463
|
}
|
|
2035
2464
|
}
|
|
@@ -2174,37 +2603,78 @@ function _withoutIndex(iteratee) {
|
|
|
2174
2603
|
* @returns {Promise} a promise, if a callback is omitted
|
|
2175
2604
|
* @example
|
|
2176
2605
|
*
|
|
2177
|
-
* //
|
|
2178
|
-
* //
|
|
2179
|
-
*
|
|
2180
|
-
*
|
|
2181
|
-
* // if any of the saves produced an error, err would equal that error
|
|
2182
|
-
* });
|
|
2606
|
+
* // dir1 is a directory that contains file1.txt, file2.txt
|
|
2607
|
+
* // dir2 is a directory that contains file3.txt, file4.txt
|
|
2608
|
+
* // dir3 is a directory that contains file5.txt
|
|
2609
|
+
* // dir4 does not exist
|
|
2183
2610
|
*
|
|
2184
|
-
*
|
|
2185
|
-
*
|
|
2611
|
+
* const fileList = [ 'dir1/file2.txt', 'dir2/file3.txt', 'dir/file5.txt'];
|
|
2612
|
+
* const withMissingFileList = ['dir1/file1.txt', 'dir4/file2.txt'];
|
|
2186
2613
|
*
|
|
2187
|
-
*
|
|
2188
|
-
*
|
|
2614
|
+
* // asynchronous function that deletes a file
|
|
2615
|
+
* const deleteFile = function(file, callback) {
|
|
2616
|
+
* fs.unlink(file, callback);
|
|
2617
|
+
* };
|
|
2189
2618
|
*
|
|
2190
|
-
*
|
|
2191
|
-
*
|
|
2192
|
-
* callback('File name too long');
|
|
2193
|
-
* } else {
|
|
2194
|
-
* // Do work to process file here
|
|
2195
|
-
* console.log('File processed');
|
|
2196
|
-
* callback();
|
|
2197
|
-
* }
|
|
2198
|
-
* }, function(err) {
|
|
2199
|
-
* // if any of the file processing produced an error, err would equal that error
|
|
2619
|
+
* // Using callbacks
|
|
2620
|
+
* async.each(fileList, deleteFile, function(err) {
|
|
2200
2621
|
* if( err ) {
|
|
2201
|
-
*
|
|
2202
|
-
* // All processing will now stop.
|
|
2203
|
-
* console.log('A file failed to process');
|
|
2622
|
+
* console.log(err);
|
|
2204
2623
|
* } else {
|
|
2205
|
-
*
|
|
2624
|
+
* console.log('All files have been deleted successfully');
|
|
2206
2625
|
* }
|
|
2207
2626
|
* });
|
|
2627
|
+
*
|
|
2628
|
+
* // Error Handling
|
|
2629
|
+
* async.each(withMissingFileList, deleteFile, function(err){
|
|
2630
|
+
* console.log(err);
|
|
2631
|
+
* // [ Error: ENOENT: no such file or directory ]
|
|
2632
|
+
* // since dir4/file2.txt does not exist
|
|
2633
|
+
* // dir1/file1.txt could have been deleted
|
|
2634
|
+
* });
|
|
2635
|
+
*
|
|
2636
|
+
* // Using Promises
|
|
2637
|
+
* async.each(fileList, deleteFile)
|
|
2638
|
+
* .then( () => {
|
|
2639
|
+
* console.log('All files have been deleted successfully');
|
|
2640
|
+
* }).catch( err => {
|
|
2641
|
+
* console.log(err);
|
|
2642
|
+
* });
|
|
2643
|
+
*
|
|
2644
|
+
* // Error Handling
|
|
2645
|
+
* async.each(fileList, deleteFile)
|
|
2646
|
+
* .then( () => {
|
|
2647
|
+
* console.log('All files have been deleted successfully');
|
|
2648
|
+
* }).catch( err => {
|
|
2649
|
+
* console.log(err);
|
|
2650
|
+
* // [ Error: ENOENT: no such file or directory ]
|
|
2651
|
+
* // since dir4/file2.txt does not exist
|
|
2652
|
+
* // dir1/file1.txt could have been deleted
|
|
2653
|
+
* });
|
|
2654
|
+
*
|
|
2655
|
+
* // Using async/await
|
|
2656
|
+
* async () => {
|
|
2657
|
+
* try {
|
|
2658
|
+
* await async.each(files, deleteFile);
|
|
2659
|
+
* }
|
|
2660
|
+
* catch (err) {
|
|
2661
|
+
* console.log(err);
|
|
2662
|
+
* }
|
|
2663
|
+
* }
|
|
2664
|
+
*
|
|
2665
|
+
* // Error Handling
|
|
2666
|
+
* async () => {
|
|
2667
|
+
* try {
|
|
2668
|
+
* await async.each(withMissingFileList, deleteFile);
|
|
2669
|
+
* }
|
|
2670
|
+
* catch (err) {
|
|
2671
|
+
* console.log(err);
|
|
2672
|
+
* // [ Error: ENOENT: no such file or directory ]
|
|
2673
|
+
* // since dir4/file2.txt does not exist
|
|
2674
|
+
* // dir1/file1.txt could have been deleted
|
|
2675
|
+
* }
|
|
2676
|
+
* }
|
|
2677
|
+
*
|
|
2208
2678
|
*/
|
|
2209
2679
|
function eachLimit(coll, iteratee, callback) {
|
|
2210
2680
|
return eachOf$1(coll, _withoutIndex(wrapAsync(iteratee)), callback);
|
|
@@ -2339,13 +2809,78 @@ function ensureAsync(fn) {
|
|
|
2339
2809
|
* @returns {Promise} a promise, if no callback provided
|
|
2340
2810
|
* @example
|
|
2341
2811
|
*
|
|
2342
|
-
*
|
|
2343
|
-
*
|
|
2344
|
-
*
|
|
2345
|
-
*
|
|
2346
|
-
*
|
|
2347
|
-
*
|
|
2812
|
+
* // dir1 is a directory that contains file1.txt, file2.txt
|
|
2813
|
+
* // dir2 is a directory that contains file3.txt, file4.txt
|
|
2814
|
+
* // dir3 is a directory that contains file5.txt
|
|
2815
|
+
* // dir4 does not exist
|
|
2816
|
+
*
|
|
2817
|
+
* const fileList = ['dir1/file1.txt','dir2/file3.txt','dir3/file5.txt'];
|
|
2818
|
+
* const withMissingFileList = ['file1.txt','file2.txt','file4.txt'];
|
|
2819
|
+
*
|
|
2820
|
+
* // asynchronous function that checks if a file exists
|
|
2821
|
+
* function fileExists(file, callback) {
|
|
2822
|
+
* fs.access(file, fs.constants.F_OK, (err) => {
|
|
2823
|
+
* callback(null, !err);
|
|
2824
|
+
* });
|
|
2825
|
+
* }
|
|
2826
|
+
*
|
|
2827
|
+
* // Using callbacks
|
|
2828
|
+
* async.every(fileList, fileExists, function(err, result) {
|
|
2829
|
+
* console.log(result);
|
|
2830
|
+
* // true
|
|
2831
|
+
* // result is true since every file exists
|
|
2832
|
+
* });
|
|
2833
|
+
*
|
|
2834
|
+
* async.every(withMissingFileList, fileExists, function(err, result) {
|
|
2835
|
+
* console.log(result);
|
|
2836
|
+
* // false
|
|
2837
|
+
* // result is false since NOT every file exists
|
|
2348
2838
|
* });
|
|
2839
|
+
*
|
|
2840
|
+
* // Using Promises
|
|
2841
|
+
* async.every(fileList, fileExists)
|
|
2842
|
+
* .then( result => {
|
|
2843
|
+
* console.log(result);
|
|
2844
|
+
* // true
|
|
2845
|
+
* // result is true since every file exists
|
|
2846
|
+
* }).catch( err => {
|
|
2847
|
+
* console.log(err);
|
|
2848
|
+
* });
|
|
2849
|
+
*
|
|
2850
|
+
* async.every(withMissingFileList, fileExists)
|
|
2851
|
+
* .then( result => {
|
|
2852
|
+
* console.log(result);
|
|
2853
|
+
* // false
|
|
2854
|
+
* // result is false since NOT every file exists
|
|
2855
|
+
* }).catch( err => {
|
|
2856
|
+
* console.log(err);
|
|
2857
|
+
* });
|
|
2858
|
+
*
|
|
2859
|
+
* // Using async/await
|
|
2860
|
+
* async () => {
|
|
2861
|
+
* try {
|
|
2862
|
+
* let result = await async.every(fileList, fileExists);
|
|
2863
|
+
* console.log(result);
|
|
2864
|
+
* // true
|
|
2865
|
+
* // result is true since every file exists
|
|
2866
|
+
* }
|
|
2867
|
+
* catch (err) {
|
|
2868
|
+
* console.log(err);
|
|
2869
|
+
* }
|
|
2870
|
+
* }
|
|
2871
|
+
*
|
|
2872
|
+
* async () => {
|
|
2873
|
+
* try {
|
|
2874
|
+
* let result = await async.every(withMissingFileList, fileExists);
|
|
2875
|
+
* console.log(result);
|
|
2876
|
+
* // false
|
|
2877
|
+
* // result is false since NOT every file exists
|
|
2878
|
+
* }
|
|
2879
|
+
* catch (err) {
|
|
2880
|
+
* console.log(err);
|
|
2881
|
+
* }
|
|
2882
|
+
* }
|
|
2883
|
+
*
|
|
2349
2884
|
*/
|
|
2350
2885
|
function every(coll, iteratee, callback) {
|
|
2351
2886
|
return _createTester(bool => !bool, res => !res)(eachOf$1, coll, iteratee, callback)
|
|
@@ -2463,13 +2998,53 @@ function _filter(eachfn, coll, iteratee, callback) {
|
|
|
2463
2998
|
* @returns {Promise} a promise, if no callback provided
|
|
2464
2999
|
* @example
|
|
2465
3000
|
*
|
|
2466
|
-
*
|
|
2467
|
-
*
|
|
2468
|
-
*
|
|
2469
|
-
*
|
|
2470
|
-
*
|
|
2471
|
-
*
|
|
3001
|
+
* // dir1 is a directory that contains file1.txt, file2.txt
|
|
3002
|
+
* // dir2 is a directory that contains file3.txt, file4.txt
|
|
3003
|
+
* // dir3 is a directory that contains file5.txt
|
|
3004
|
+
*
|
|
3005
|
+
* const files = ['dir1/file1.txt','dir2/file3.txt','dir3/file6.txt'];
|
|
3006
|
+
*
|
|
3007
|
+
* // asynchronous function that checks if a file exists
|
|
3008
|
+
* function fileExists(file, callback) {
|
|
3009
|
+
* fs.access(file, fs.constants.F_OK, (err) => {
|
|
3010
|
+
* callback(null, !err);
|
|
3011
|
+
* });
|
|
3012
|
+
* }
|
|
3013
|
+
*
|
|
3014
|
+
* // Using callbacks
|
|
3015
|
+
* async.filter(files, fileExists, function(err, results) {
|
|
3016
|
+
* if(err) {
|
|
3017
|
+
* console.log(err);
|
|
3018
|
+
* } else {
|
|
3019
|
+
* console.log(results);
|
|
3020
|
+
* // [ 'dir1/file1.txt', 'dir2/file3.txt' ]
|
|
3021
|
+
* // results is now an array of the existing files
|
|
3022
|
+
* }
|
|
3023
|
+
* });
|
|
3024
|
+
*
|
|
3025
|
+
* // Using Promises
|
|
3026
|
+
* async.filter(files, fileExists)
|
|
3027
|
+
* .then(results => {
|
|
3028
|
+
* console.log(results);
|
|
3029
|
+
* // [ 'dir1/file1.txt', 'dir2/file3.txt' ]
|
|
3030
|
+
* // results is now an array of the existing files
|
|
3031
|
+
* }).catch(err => {
|
|
3032
|
+
* console.log(err);
|
|
2472
3033
|
* });
|
|
3034
|
+
*
|
|
3035
|
+
* // Using async/await
|
|
3036
|
+
* async () => {
|
|
3037
|
+
* try {
|
|
3038
|
+
* let results = await async.filter(files, fileExists);
|
|
3039
|
+
* console.log(results);
|
|
3040
|
+
* // [ 'dir1/file1.txt', 'dir2/file3.txt' ]
|
|
3041
|
+
* // results is now an array of the existing files
|
|
3042
|
+
* }
|
|
3043
|
+
* catch (err) {
|
|
3044
|
+
* console.log(err);
|
|
3045
|
+
* }
|
|
3046
|
+
* }
|
|
3047
|
+
*
|
|
2473
3048
|
*/
|
|
2474
3049
|
function filter (coll, iteratee, callback) {
|
|
2475
3050
|
return _filter(eachOf$1, coll, iteratee, callback)
|
|
@@ -2646,15 +3221,69 @@ var groupByLimit$1 = awaitify(groupByLimit, 4);
|
|
|
2646
3221
|
* @returns {Promise} a promise, if no callback is passed
|
|
2647
3222
|
* @example
|
|
2648
3223
|
*
|
|
2649
|
-
*
|
|
2650
|
-
*
|
|
2651
|
-
*
|
|
2652
|
-
*
|
|
3224
|
+
* // dir1 is a directory that contains file1.txt, file2.txt
|
|
3225
|
+
* // dir2 is a directory that contains file3.txt, file4.txt
|
|
3226
|
+
* // dir3 is a directory that contains file5.txt
|
|
3227
|
+
* // dir4 does not exist
|
|
3228
|
+
*
|
|
3229
|
+
* const files = ['dir1/file1.txt','dir2','dir4']
|
|
3230
|
+
*
|
|
3231
|
+
* // asynchronous function that detects file type as none, file, or directory
|
|
3232
|
+
* function detectFile(file, callback) {
|
|
3233
|
+
* fs.stat(file, function(err, stat) {
|
|
3234
|
+
* if (err) {
|
|
3235
|
+
* return callback(null, 'none');
|
|
3236
|
+
* }
|
|
3237
|
+
* callback(null, stat.isDirectory() ? 'directory' : 'file');
|
|
2653
3238
|
* });
|
|
2654
|
-
* }
|
|
2655
|
-
*
|
|
2656
|
-
*
|
|
3239
|
+
* }
|
|
3240
|
+
*
|
|
3241
|
+
* //Using callbacks
|
|
3242
|
+
* async.groupBy(files, detectFile, function(err, result) {
|
|
3243
|
+
* if(err) {
|
|
3244
|
+
* console.log(err);
|
|
3245
|
+
* } else {
|
|
3246
|
+
* console.log(result);
|
|
3247
|
+
* // {
|
|
3248
|
+
* // file: [ 'dir1/file1.txt' ],
|
|
3249
|
+
* // none: [ 'dir4' ],
|
|
3250
|
+
* // directory: [ 'dir2']
|
|
3251
|
+
* // }
|
|
3252
|
+
* // result is object containing the files grouped by type
|
|
3253
|
+
* }
|
|
2657
3254
|
* });
|
|
3255
|
+
*
|
|
3256
|
+
* // Using Promises
|
|
3257
|
+
* async.groupBy(files, detectFile)
|
|
3258
|
+
* .then( result => {
|
|
3259
|
+
* console.log(result);
|
|
3260
|
+
* // {
|
|
3261
|
+
* // file: [ 'dir1/file1.txt' ],
|
|
3262
|
+
* // none: [ 'dir4' ],
|
|
3263
|
+
* // directory: [ 'dir2']
|
|
3264
|
+
* // }
|
|
3265
|
+
* // result is object containing the files grouped by type
|
|
3266
|
+
* }).catch( err => {
|
|
3267
|
+
* console.log(err);
|
|
3268
|
+
* });
|
|
3269
|
+
*
|
|
3270
|
+
* // Using async/await
|
|
3271
|
+
* async () => {
|
|
3272
|
+
* try {
|
|
3273
|
+
* let result = await async.groupBy(files, detectFile);
|
|
3274
|
+
* console.log(result);
|
|
3275
|
+
* // {
|
|
3276
|
+
* // file: [ 'dir1/file1.txt' ],
|
|
3277
|
+
* // none: [ 'dir4' ],
|
|
3278
|
+
* // directory: [ 'dir2']
|
|
3279
|
+
* // }
|
|
3280
|
+
* // result is object containing the files grouped by type
|
|
3281
|
+
* }
|
|
3282
|
+
* catch (err) {
|
|
3283
|
+
* console.log(err);
|
|
3284
|
+
* }
|
|
3285
|
+
* }
|
|
3286
|
+
*
|
|
2658
3287
|
*/
|
|
2659
3288
|
function groupBy (coll, iteratee, callback) {
|
|
2660
3289
|
return groupByLimit$1(coll, Infinity, iteratee, callback)
|
|
@@ -2675,7 +3304,7 @@ function groupBy (coll, iteratee, callback) {
|
|
|
2675
3304
|
* The iteratee should complete with a `key` to group the value under.
|
|
2676
3305
|
* Invoked with (value, callback).
|
|
2677
3306
|
* @param {Function} [callback] - A callback which is called when all `iteratee`
|
|
2678
|
-
* functions have finished, or an error occurs. Result is an `Object`
|
|
3307
|
+
* functions have finished, or an error occurs. Result is an `Object` whose
|
|
2679
3308
|
* properties are arrays of values which returned the corresponding key.
|
|
2680
3309
|
* @returns {Promise} a promise, if no callback is passed
|
|
2681
3310
|
*/
|
|
@@ -2779,20 +3408,110 @@ var mapValuesLimit$1 = awaitify(mapValuesLimit, 4);
|
|
|
2779
3408
|
* @returns {Promise} a promise, if no callback is passed
|
|
2780
3409
|
* @example
|
|
2781
3410
|
*
|
|
2782
|
-
*
|
|
2783
|
-
*
|
|
2784
|
-
*
|
|
2785
|
-
*
|
|
2786
|
-
*
|
|
2787
|
-
*
|
|
2788
|
-
*
|
|
2789
|
-
*
|
|
3411
|
+
* // file1.txt is a file that is 1000 bytes in size
|
|
3412
|
+
* // file2.txt is a file that is 2000 bytes in size
|
|
3413
|
+
* // file3.txt is a file that is 3000 bytes in size
|
|
3414
|
+
* // file4.txt does not exist
|
|
3415
|
+
*
|
|
3416
|
+
* const fileMap = {
|
|
3417
|
+
* f1: 'file1.txt',
|
|
3418
|
+
* f2: 'file2.txt',
|
|
3419
|
+
* f3: 'file3.txt'
|
|
3420
|
+
* };
|
|
3421
|
+
*
|
|
3422
|
+
* const withMissingFileMap = {
|
|
3423
|
+
* f1: 'file1.txt',
|
|
3424
|
+
* f2: 'file2.txt',
|
|
3425
|
+
* f3: 'file4.txt'
|
|
3426
|
+
* };
|
|
3427
|
+
*
|
|
3428
|
+
* // asynchronous function that returns the file size in bytes
|
|
3429
|
+
* function getFileSizeInBytes(file, key, callback) {
|
|
3430
|
+
* fs.stat(file, function(err, stat) {
|
|
3431
|
+
* if (err) {
|
|
3432
|
+
* return callback(err);
|
|
3433
|
+
* }
|
|
3434
|
+
* callback(null, stat.size);
|
|
3435
|
+
* });
|
|
3436
|
+
* }
|
|
3437
|
+
*
|
|
3438
|
+
* // Using callbacks
|
|
3439
|
+
* async.mapValues(fileMap, getFileSizeInBytes, function(err, result) {
|
|
3440
|
+
* if (err) {
|
|
3441
|
+
* console.log(err);
|
|
3442
|
+
* } else {
|
|
3443
|
+
* console.log(result);
|
|
3444
|
+
* // result is now a map of file size in bytes for each file, e.g.
|
|
3445
|
+
* // {
|
|
3446
|
+
* // f1: 1000,
|
|
3447
|
+
* // f2: 2000,
|
|
3448
|
+
* // f3: 3000
|
|
3449
|
+
* // }
|
|
3450
|
+
* }
|
|
3451
|
+
* });
|
|
3452
|
+
*
|
|
3453
|
+
* // Error handling
|
|
3454
|
+
* async.mapValues(withMissingFileMap, getFileSizeInBytes, function(err, result) {
|
|
3455
|
+
* if (err) {
|
|
3456
|
+
* console.log(err);
|
|
3457
|
+
* // [ Error: ENOENT: no such file or directory ]
|
|
3458
|
+
* } else {
|
|
3459
|
+
* console.log(result);
|
|
3460
|
+
* }
|
|
3461
|
+
* });
|
|
3462
|
+
*
|
|
3463
|
+
* // Using Promises
|
|
3464
|
+
* async.mapValues(fileMap, getFileSizeInBytes)
|
|
3465
|
+
* .then( result => {
|
|
3466
|
+
* console.log(result);
|
|
3467
|
+
* // result is now a map of file size in bytes for each file, e.g.
|
|
2790
3468
|
* // {
|
|
2791
|
-
* // f1:
|
|
2792
|
-
* // f2:
|
|
2793
|
-
* // f3:
|
|
3469
|
+
* // f1: 1000,
|
|
3470
|
+
* // f2: 2000,
|
|
3471
|
+
* // f3: 3000
|
|
2794
3472
|
* // }
|
|
3473
|
+
* }).catch (err => {
|
|
3474
|
+
* console.log(err);
|
|
2795
3475
|
* });
|
|
3476
|
+
*
|
|
3477
|
+
* // Error Handling
|
|
3478
|
+
* async.mapValues(withMissingFileMap, getFileSizeInBytes)
|
|
3479
|
+
* .then( result => {
|
|
3480
|
+
* console.log(result);
|
|
3481
|
+
* }).catch (err => {
|
|
3482
|
+
* console.log(err);
|
|
3483
|
+
* // [ Error: ENOENT: no such file or directory ]
|
|
3484
|
+
* });
|
|
3485
|
+
*
|
|
3486
|
+
* // Using async/await
|
|
3487
|
+
* async () => {
|
|
3488
|
+
* try {
|
|
3489
|
+
* let result = await async.mapValues(fileMap, getFileSizeInBytes);
|
|
3490
|
+
* console.log(result);
|
|
3491
|
+
* // result is now a map of file size in bytes for each file, e.g.
|
|
3492
|
+
* // {
|
|
3493
|
+
* // f1: 1000,
|
|
3494
|
+
* // f2: 2000,
|
|
3495
|
+
* // f3: 3000
|
|
3496
|
+
* // }
|
|
3497
|
+
* }
|
|
3498
|
+
* catch (err) {
|
|
3499
|
+
* console.log(err);
|
|
3500
|
+
* }
|
|
3501
|
+
* }
|
|
3502
|
+
*
|
|
3503
|
+
* // Error Handling
|
|
3504
|
+
* async () => {
|
|
3505
|
+
* try {
|
|
3506
|
+
* let result = await async.mapValues(withMissingFileMap, getFileSizeInBytes);
|
|
3507
|
+
* console.log(result);
|
|
3508
|
+
* }
|
|
3509
|
+
* catch (err) {
|
|
3510
|
+
* console.log(err);
|
|
3511
|
+
* // [ Error: ENOENT: no such file or directory ]
|
|
3512
|
+
* }
|
|
3513
|
+
* }
|
|
3514
|
+
*
|
|
2796
3515
|
*/
|
|
2797
3516
|
function mapValues(obj, iteratee, callback) {
|
|
2798
3517
|
return mapValuesLimit$1(obj, Infinity, iteratee, callback)
|
|
@@ -2892,6 +3611,8 @@ function memoize(fn, hasher = v => v) {
|
|
|
2892
3611
|
return memoized;
|
|
2893
3612
|
}
|
|
2894
3613
|
|
|
3614
|
+
/* istanbul ignore file */
|
|
3615
|
+
|
|
2895
3616
|
/**
|
|
2896
3617
|
* Calls `callback` on a later loop around the event loop. In Node.js this just
|
|
2897
3618
|
* calls `process.nextTick`. In the browser it will use `setImmediate` if
|
|
@@ -2985,6 +3706,8 @@ var _parallel = awaitify((eachfn, tasks, callback) => {
|
|
|
2985
3706
|
* @returns {Promise} a promise, if a callback is not passed
|
|
2986
3707
|
*
|
|
2987
3708
|
* @example
|
|
3709
|
+
*
|
|
3710
|
+
* //Using Callbacks
|
|
2988
3711
|
* async.parallel([
|
|
2989
3712
|
* function(callback) {
|
|
2990
3713
|
* setTimeout(function() {
|
|
@@ -2996,10 +3719,9 @@ var _parallel = awaitify((eachfn, tasks, callback) => {
|
|
|
2996
3719
|
* callback(null, 'two');
|
|
2997
3720
|
* }, 100);
|
|
2998
3721
|
* }
|
|
2999
|
-
* ],
|
|
3000
|
-
*
|
|
3001
|
-
*
|
|
3002
|
-
* // the results array will equal ['one','two'] even though
|
|
3722
|
+
* ], function(err, results) {
|
|
3723
|
+
* console.log(results);
|
|
3724
|
+
* // results is equal to ['one','two'] even though
|
|
3003
3725
|
* // the second function had a shorter timeout.
|
|
3004
3726
|
* });
|
|
3005
3727
|
*
|
|
@@ -3016,8 +3738,96 @@ var _parallel = awaitify((eachfn, tasks, callback) => {
|
|
|
3016
3738
|
* }, 100);
|
|
3017
3739
|
* }
|
|
3018
3740
|
* }, function(err, results) {
|
|
3019
|
-
*
|
|
3741
|
+
* console.log(results);
|
|
3742
|
+
* // results is equal to: { one: 1, two: 2 }
|
|
3020
3743
|
* });
|
|
3744
|
+
*
|
|
3745
|
+
* //Using Promises
|
|
3746
|
+
* async.parallel([
|
|
3747
|
+
* function(callback) {
|
|
3748
|
+
* setTimeout(function() {
|
|
3749
|
+
* callback(null, 'one');
|
|
3750
|
+
* }, 200);
|
|
3751
|
+
* },
|
|
3752
|
+
* function(callback) {
|
|
3753
|
+
* setTimeout(function() {
|
|
3754
|
+
* callback(null, 'two');
|
|
3755
|
+
* }, 100);
|
|
3756
|
+
* }
|
|
3757
|
+
* ]).then(results => {
|
|
3758
|
+
* console.log(results);
|
|
3759
|
+
* // results is equal to ['one','two'] even though
|
|
3760
|
+
* // the second function had a shorter timeout.
|
|
3761
|
+
* }).catch(err => {
|
|
3762
|
+
* console.log(err);
|
|
3763
|
+
* });
|
|
3764
|
+
*
|
|
3765
|
+
* // an example using an object instead of an array
|
|
3766
|
+
* async.parallel({
|
|
3767
|
+
* one: function(callback) {
|
|
3768
|
+
* setTimeout(function() {
|
|
3769
|
+
* callback(null, 1);
|
|
3770
|
+
* }, 200);
|
|
3771
|
+
* },
|
|
3772
|
+
* two: function(callback) {
|
|
3773
|
+
* setTimeout(function() {
|
|
3774
|
+
* callback(null, 2);
|
|
3775
|
+
* }, 100);
|
|
3776
|
+
* }
|
|
3777
|
+
* }).then(results => {
|
|
3778
|
+
* console.log(results);
|
|
3779
|
+
* // results is equal to: { one: 1, two: 2 }
|
|
3780
|
+
* }).catch(err => {
|
|
3781
|
+
* console.log(err);
|
|
3782
|
+
* });
|
|
3783
|
+
*
|
|
3784
|
+
* //Using async/await
|
|
3785
|
+
* async () => {
|
|
3786
|
+
* try {
|
|
3787
|
+
* let results = await async.parallel([
|
|
3788
|
+
* function(callback) {
|
|
3789
|
+
* setTimeout(function() {
|
|
3790
|
+
* callback(null, 'one');
|
|
3791
|
+
* }, 200);
|
|
3792
|
+
* },
|
|
3793
|
+
* function(callback) {
|
|
3794
|
+
* setTimeout(function() {
|
|
3795
|
+
* callback(null, 'two');
|
|
3796
|
+
* }, 100);
|
|
3797
|
+
* }
|
|
3798
|
+
* ]);
|
|
3799
|
+
* console.log(results);
|
|
3800
|
+
* // results is equal to ['one','two'] even though
|
|
3801
|
+
* // the second function had a shorter timeout.
|
|
3802
|
+
* }
|
|
3803
|
+
* catch (err) {
|
|
3804
|
+
* console.log(err);
|
|
3805
|
+
* }
|
|
3806
|
+
* }
|
|
3807
|
+
*
|
|
3808
|
+
* // an example using an object instead of an array
|
|
3809
|
+
* async () => {
|
|
3810
|
+
* try {
|
|
3811
|
+
* let results = await async.parallel({
|
|
3812
|
+
* one: function(callback) {
|
|
3813
|
+
* setTimeout(function() {
|
|
3814
|
+
* callback(null, 1);
|
|
3815
|
+
* }, 200);
|
|
3816
|
+
* },
|
|
3817
|
+
* two: function(callback) {
|
|
3818
|
+
* setTimeout(function() {
|
|
3819
|
+
* callback(null, 2);
|
|
3820
|
+
* }, 100);
|
|
3821
|
+
* }
|
|
3822
|
+
* });
|
|
3823
|
+
* console.log(results);
|
|
3824
|
+
* // results is equal to: { one: 1, two: 2 }
|
|
3825
|
+
* }
|
|
3826
|
+
* catch (err) {
|
|
3827
|
+
* console.log(err);
|
|
3828
|
+
* }
|
|
3829
|
+
* }
|
|
3830
|
+
*
|
|
3021
3831
|
*/
|
|
3022
3832
|
function parallel(tasks, callback) {
|
|
3023
3833
|
return _parallel(eachOf$1, tasks, callback);
|
|
@@ -3075,7 +3885,7 @@ function parallelLimit(tasks, limit, callback) {
|
|
|
3075
3885
|
* Invoke with `queue.unshift(task, [callback])`.
|
|
3076
3886
|
* @property {AsyncFunction} pushAsync - the same as `q.push`, except this returns
|
|
3077
3887
|
* a promise that rejects if an error occurs.
|
|
3078
|
-
* @property {AsyncFunction}
|
|
3888
|
+
* @property {AsyncFunction} unshiftAsync - the same as `q.unshift`, except this returns
|
|
3079
3889
|
* a promise that rejects if an error occurs.
|
|
3080
3890
|
* @property {Function} remove - remove items from the queue that match a test
|
|
3081
3891
|
* function. The test function will be passed an object with a `data` property,
|
|
@@ -3114,7 +3924,7 @@ function parallelLimit(tasks, limit, callback) {
|
|
|
3114
3924
|
* should be pushed to the queue after calling this function. Invoke with `queue.kill()`.
|
|
3115
3925
|
*
|
|
3116
3926
|
* @example
|
|
3117
|
-
* const q =
|
|
3927
|
+
* const q = async.queue(worker, 2)
|
|
3118
3928
|
* q.push(item1)
|
|
3119
3929
|
* q.push(item2)
|
|
3120
3930
|
* q.push(item3)
|
|
@@ -3337,6 +4147,7 @@ function smaller(x, y) {
|
|
|
3337
4147
|
function priorityQueue(worker, concurrency) {
|
|
3338
4148
|
// Start with a normal queue
|
|
3339
4149
|
var q = queue$1(worker, concurrency);
|
|
4150
|
+
var processingScheduled = false;
|
|
3340
4151
|
|
|
3341
4152
|
q._tasks = new Heap();
|
|
3342
4153
|
|
|
@@ -3364,7 +4175,13 @@ function priorityQueue(worker, concurrency) {
|
|
|
3364
4175
|
q._tasks.push(item);
|
|
3365
4176
|
}
|
|
3366
4177
|
|
|
3367
|
-
|
|
4178
|
+
if (!processingScheduled) {
|
|
4179
|
+
processingScheduled = true;
|
|
4180
|
+
setImmediate$1(() => {
|
|
4181
|
+
processingScheduled = false;
|
|
4182
|
+
q.process();
|
|
4183
|
+
});
|
|
4184
|
+
}
|
|
3368
4185
|
};
|
|
3369
4186
|
|
|
3370
4187
|
// Remove unshift function
|
|
@@ -3435,7 +4252,7 @@ var race$1 = awaitify(race, 2);
|
|
|
3435
4252
|
* @param {AsyncFunction} iteratee - A function applied to each item in the
|
|
3436
4253
|
* array to produce the next step in the reduction.
|
|
3437
4254
|
* The `iteratee` should complete with the next state of the reduction.
|
|
3438
|
-
* If the iteratee
|
|
4255
|
+
* If the iteratee completes with an error, the reduction is stopped and the
|
|
3439
4256
|
* main `callback` is immediately called with the error.
|
|
3440
4257
|
* Invoked with (memo, item, callback).
|
|
3441
4258
|
* @param {Function} [callback] - A callback which is called after all the
|
|
@@ -3617,14 +4434,48 @@ function reject(eachfn, arr, _iteratee, callback) {
|
|
|
3617
4434
|
* @returns {Promise} a promise, if no callback is passed
|
|
3618
4435
|
* @example
|
|
3619
4436
|
*
|
|
3620
|
-
*
|
|
3621
|
-
*
|
|
3622
|
-
*
|
|
3623
|
-
*
|
|
3624
|
-
*
|
|
3625
|
-
*
|
|
3626
|
-
*
|
|
4437
|
+
* // dir1 is a directory that contains file1.txt, file2.txt
|
|
4438
|
+
* // dir2 is a directory that contains file3.txt, file4.txt
|
|
4439
|
+
* // dir3 is a directory that contains file5.txt
|
|
4440
|
+
*
|
|
4441
|
+
* const fileList = ['dir1/file1.txt','dir2/file3.txt','dir3/file6.txt'];
|
|
4442
|
+
*
|
|
4443
|
+
* // asynchronous function that checks if a file exists
|
|
4444
|
+
* function fileExists(file, callback) {
|
|
4445
|
+
* fs.access(file, fs.constants.F_OK, (err) => {
|
|
4446
|
+
* callback(null, !err);
|
|
4447
|
+
* });
|
|
4448
|
+
* }
|
|
4449
|
+
*
|
|
4450
|
+
* // Using callbacks
|
|
4451
|
+
* async.reject(fileList, fileExists, function(err, results) {
|
|
4452
|
+
* // [ 'dir3/file6.txt' ]
|
|
4453
|
+
* // results now equals an array of the non-existing files
|
|
3627
4454
|
* });
|
|
4455
|
+
*
|
|
4456
|
+
* // Using Promises
|
|
4457
|
+
* async.reject(fileList, fileExists)
|
|
4458
|
+
* .then( results => {
|
|
4459
|
+
* console.log(results);
|
|
4460
|
+
* // [ 'dir3/file6.txt' ]
|
|
4461
|
+
* // results now equals an array of the non-existing files
|
|
4462
|
+
* }).catch( err => {
|
|
4463
|
+
* console.log(err);
|
|
4464
|
+
* });
|
|
4465
|
+
*
|
|
4466
|
+
* // Using async/await
|
|
4467
|
+
* async () => {
|
|
4468
|
+
* try {
|
|
4469
|
+
* let results = await async.reject(fileList, fileExists);
|
|
4470
|
+
* console.log(results);
|
|
4471
|
+
* // [ 'dir3/file6.txt' ]
|
|
4472
|
+
* // results now equals an array of the non-existing files
|
|
4473
|
+
* }
|
|
4474
|
+
* catch (err) {
|
|
4475
|
+
* console.log(err);
|
|
4476
|
+
* }
|
|
4477
|
+
* }
|
|
4478
|
+
*
|
|
3628
4479
|
*/
|
|
3629
4480
|
function reject$1 (coll, iteratee, callback) {
|
|
3630
4481
|
return reject(eachOf$1, coll, iteratee, callback)
|
|
@@ -3917,35 +4768,135 @@ function retryable (opts, task) {
|
|
|
3917
4768
|
* with (err, result).
|
|
3918
4769
|
* @return {Promise} a promise, if no callback is passed
|
|
3919
4770
|
* @example
|
|
4771
|
+
*
|
|
4772
|
+
* //Using Callbacks
|
|
3920
4773
|
* async.series([
|
|
3921
4774
|
* function(callback) {
|
|
3922
|
-
*
|
|
3923
|
-
*
|
|
4775
|
+
* setTimeout(function() {
|
|
4776
|
+
* // do some async task
|
|
4777
|
+
* callback(null, 'one');
|
|
4778
|
+
* }, 200);
|
|
3924
4779
|
* },
|
|
3925
4780
|
* function(callback) {
|
|
3926
|
-
*
|
|
3927
|
-
*
|
|
4781
|
+
* setTimeout(function() {
|
|
4782
|
+
* // then do another async task
|
|
4783
|
+
* callback(null, 'two');
|
|
4784
|
+
* }, 100);
|
|
3928
4785
|
* }
|
|
3929
|
-
* ],
|
|
3930
|
-
*
|
|
3931
|
-
*
|
|
3932
|
-
* // results is now equal to ['one', 'two']
|
|
4786
|
+
* ], function(err, results) {
|
|
4787
|
+
* console.log(results);
|
|
4788
|
+
* // results is equal to ['one','two']
|
|
3933
4789
|
* });
|
|
3934
4790
|
*
|
|
4791
|
+
* // an example using objects instead of arrays
|
|
3935
4792
|
* async.series({
|
|
3936
4793
|
* one: function(callback) {
|
|
3937
4794
|
* setTimeout(function() {
|
|
4795
|
+
* // do some async task
|
|
3938
4796
|
* callback(null, 1);
|
|
3939
4797
|
* }, 200);
|
|
3940
4798
|
* },
|
|
3941
|
-
* two: function(callback){
|
|
4799
|
+
* two: function(callback) {
|
|
3942
4800
|
* setTimeout(function() {
|
|
4801
|
+
* // then do another async task
|
|
3943
4802
|
* callback(null, 2);
|
|
3944
4803
|
* }, 100);
|
|
3945
4804
|
* }
|
|
3946
4805
|
* }, function(err, results) {
|
|
3947
|
-
*
|
|
4806
|
+
* console.log(results);
|
|
4807
|
+
* // results is equal to: { one: 1, two: 2 }
|
|
4808
|
+
* });
|
|
4809
|
+
*
|
|
4810
|
+
* //Using Promises
|
|
4811
|
+
* async.series([
|
|
4812
|
+
* function(callback) {
|
|
4813
|
+
* setTimeout(function() {
|
|
4814
|
+
* callback(null, 'one');
|
|
4815
|
+
* }, 200);
|
|
4816
|
+
* },
|
|
4817
|
+
* function(callback) {
|
|
4818
|
+
* setTimeout(function() {
|
|
4819
|
+
* callback(null, 'two');
|
|
4820
|
+
* }, 100);
|
|
4821
|
+
* }
|
|
4822
|
+
* ]).then(results => {
|
|
4823
|
+
* console.log(results);
|
|
4824
|
+
* // results is equal to ['one','two']
|
|
4825
|
+
* }).catch(err => {
|
|
4826
|
+
* console.log(err);
|
|
3948
4827
|
* });
|
|
4828
|
+
*
|
|
4829
|
+
* // an example using an object instead of an array
|
|
4830
|
+
* async.series({
|
|
4831
|
+
* one: function(callback) {
|
|
4832
|
+
* setTimeout(function() {
|
|
4833
|
+
* // do some async task
|
|
4834
|
+
* callback(null, 1);
|
|
4835
|
+
* }, 200);
|
|
4836
|
+
* },
|
|
4837
|
+
* two: function(callback) {
|
|
4838
|
+
* setTimeout(function() {
|
|
4839
|
+
* // then do another async task
|
|
4840
|
+
* callback(null, 2);
|
|
4841
|
+
* }, 100);
|
|
4842
|
+
* }
|
|
4843
|
+
* }).then(results => {
|
|
4844
|
+
* console.log(results);
|
|
4845
|
+
* // results is equal to: { one: 1, two: 2 }
|
|
4846
|
+
* }).catch(err => {
|
|
4847
|
+
* console.log(err);
|
|
4848
|
+
* });
|
|
4849
|
+
*
|
|
4850
|
+
* //Using async/await
|
|
4851
|
+
* async () => {
|
|
4852
|
+
* try {
|
|
4853
|
+
* let results = await async.series([
|
|
4854
|
+
* function(callback) {
|
|
4855
|
+
* setTimeout(function() {
|
|
4856
|
+
* // do some async task
|
|
4857
|
+
* callback(null, 'one');
|
|
4858
|
+
* }, 200);
|
|
4859
|
+
* },
|
|
4860
|
+
* function(callback) {
|
|
4861
|
+
* setTimeout(function() {
|
|
4862
|
+
* // then do another async task
|
|
4863
|
+
* callback(null, 'two');
|
|
4864
|
+
* }, 100);
|
|
4865
|
+
* }
|
|
4866
|
+
* ]);
|
|
4867
|
+
* console.log(results);
|
|
4868
|
+
* // results is equal to ['one','two']
|
|
4869
|
+
* }
|
|
4870
|
+
* catch (err) {
|
|
4871
|
+
* console.log(err);
|
|
4872
|
+
* }
|
|
4873
|
+
* }
|
|
4874
|
+
*
|
|
4875
|
+
* // an example using an object instead of an array
|
|
4876
|
+
* async () => {
|
|
4877
|
+
* try {
|
|
4878
|
+
* let results = await async.parallel({
|
|
4879
|
+
* one: function(callback) {
|
|
4880
|
+
* setTimeout(function() {
|
|
4881
|
+
* // do some async task
|
|
4882
|
+
* callback(null, 1);
|
|
4883
|
+
* }, 200);
|
|
4884
|
+
* },
|
|
4885
|
+
* two: function(callback) {
|
|
4886
|
+
* setTimeout(function() {
|
|
4887
|
+
* // then do another async task
|
|
4888
|
+
* callback(null, 2);
|
|
4889
|
+
* }, 100);
|
|
4890
|
+
* }
|
|
4891
|
+
* });
|
|
4892
|
+
* console.log(results);
|
|
4893
|
+
* // results is equal to: { one: 1, two: 2 }
|
|
4894
|
+
* }
|
|
4895
|
+
* catch (err) {
|
|
4896
|
+
* console.log(err);
|
|
4897
|
+
* }
|
|
4898
|
+
* }
|
|
4899
|
+
*
|
|
3949
4900
|
*/
|
|
3950
4901
|
function series(tasks, callback) {
|
|
3951
4902
|
return _parallel(eachOfSeries$1, tasks, callback);
|
|
@@ -3974,13 +4925,79 @@ function series(tasks, callback) {
|
|
|
3974
4925
|
* @returns {Promise} a promise, if no callback provided
|
|
3975
4926
|
* @example
|
|
3976
4927
|
*
|
|
3977
|
-
*
|
|
3978
|
-
*
|
|
3979
|
-
*
|
|
3980
|
-
*
|
|
3981
|
-
*
|
|
3982
|
-
*
|
|
4928
|
+
* // dir1 is a directory that contains file1.txt, file2.txt
|
|
4929
|
+
* // dir2 is a directory that contains file3.txt, file4.txt
|
|
4930
|
+
* // dir3 is a directory that contains file5.txt
|
|
4931
|
+
* // dir4 does not exist
|
|
4932
|
+
*
|
|
4933
|
+
* // asynchronous function that checks if a file exists
|
|
4934
|
+
* function fileExists(file, callback) {
|
|
4935
|
+
* fs.access(file, fs.constants.F_OK, (err) => {
|
|
4936
|
+
* callback(null, !err);
|
|
4937
|
+
* });
|
|
4938
|
+
* }
|
|
4939
|
+
*
|
|
4940
|
+
* // Using callbacks
|
|
4941
|
+
* async.some(['dir1/missing.txt','dir2/missing.txt','dir3/file5.txt'], fileExists,
|
|
4942
|
+
* function(err, result) {
|
|
4943
|
+
* console.log(result);
|
|
4944
|
+
* // true
|
|
4945
|
+
* // result is true since some file in the list exists
|
|
4946
|
+
* }
|
|
4947
|
+
*);
|
|
4948
|
+
*
|
|
4949
|
+
* async.some(['dir1/missing.txt','dir2/missing.txt','dir4/missing.txt'], fileExists,
|
|
4950
|
+
* function(err, result) {
|
|
4951
|
+
* console.log(result);
|
|
4952
|
+
* // false
|
|
4953
|
+
* // result is false since none of the files exists
|
|
4954
|
+
* }
|
|
4955
|
+
*);
|
|
4956
|
+
*
|
|
4957
|
+
* // Using Promises
|
|
4958
|
+
* async.some(['dir1/missing.txt','dir2/missing.txt','dir3/file5.txt'], fileExists)
|
|
4959
|
+
* .then( result => {
|
|
4960
|
+
* console.log(result);
|
|
4961
|
+
* // true
|
|
4962
|
+
* // result is true since some file in the list exists
|
|
4963
|
+
* }).catch( err => {
|
|
4964
|
+
* console.log(err);
|
|
3983
4965
|
* });
|
|
4966
|
+
*
|
|
4967
|
+
* async.some(['dir1/missing.txt','dir2/missing.txt','dir4/missing.txt'], fileExists)
|
|
4968
|
+
* .then( result => {
|
|
4969
|
+
* console.log(result);
|
|
4970
|
+
* // false
|
|
4971
|
+
* // result is false since none of the files exists
|
|
4972
|
+
* }).catch( err => {
|
|
4973
|
+
* console.log(err);
|
|
4974
|
+
* });
|
|
4975
|
+
*
|
|
4976
|
+
* // Using async/await
|
|
4977
|
+
* async () => {
|
|
4978
|
+
* try {
|
|
4979
|
+
* let result = await async.some(['dir1/missing.txt','dir2/missing.txt','dir3/file5.txt'], fileExists);
|
|
4980
|
+
* console.log(result);
|
|
4981
|
+
* // true
|
|
4982
|
+
* // result is true since some file in the list exists
|
|
4983
|
+
* }
|
|
4984
|
+
* catch (err) {
|
|
4985
|
+
* console.log(err);
|
|
4986
|
+
* }
|
|
4987
|
+
* }
|
|
4988
|
+
*
|
|
4989
|
+
* async () => {
|
|
4990
|
+
* try {
|
|
4991
|
+
* let result = await async.some(['dir1/missing.txt','dir2/missing.txt','dir4/missing.txt'], fileExists);
|
|
4992
|
+
* console.log(result);
|
|
4993
|
+
* // false
|
|
4994
|
+
* // result is false since none of the files exists
|
|
4995
|
+
* }
|
|
4996
|
+
* catch (err) {
|
|
4997
|
+
* console.log(err);
|
|
4998
|
+
* }
|
|
4999
|
+
* }
|
|
5000
|
+
*
|
|
3984
5001
|
*/
|
|
3985
5002
|
function some(coll, iteratee, callback) {
|
|
3986
5003
|
return _createTester(Boolean, res => res)(eachOf$1, coll, iteratee, callback)
|
|
@@ -4062,31 +5079,133 @@ var someSeries$1 = awaitify(someSeries, 3);
|
|
|
4062
5079
|
* @returns {Promise} a promise, if no callback passed
|
|
4063
5080
|
* @example
|
|
4064
5081
|
*
|
|
4065
|
-
*
|
|
4066
|
-
*
|
|
4067
|
-
*
|
|
5082
|
+
* // bigfile.txt is a file that is 251100 bytes in size
|
|
5083
|
+
* // mediumfile.txt is a file that is 11000 bytes in size
|
|
5084
|
+
* // smallfile.txt is a file that is 121 bytes in size
|
|
5085
|
+
*
|
|
5086
|
+
* // asynchronous function that returns the file size in bytes
|
|
5087
|
+
* function getFileSizeInBytes(file, callback) {
|
|
5088
|
+
* fs.stat(file, function(err, stat) {
|
|
5089
|
+
* if (err) {
|
|
5090
|
+
* return callback(err);
|
|
5091
|
+
* }
|
|
5092
|
+
* callback(null, stat.size);
|
|
4068
5093
|
* });
|
|
4069
|
-
* }
|
|
4070
|
-
*
|
|
4071
|
-
*
|
|
4072
|
-
*
|
|
5094
|
+
* }
|
|
5095
|
+
*
|
|
5096
|
+
* // Using callbacks
|
|
5097
|
+
* async.sortBy(['mediumfile.txt','smallfile.txt','bigfile.txt'], getFileSizeInBytes,
|
|
5098
|
+
* function(err, results) {
|
|
5099
|
+
* if (err) {
|
|
5100
|
+
* console.log(err);
|
|
5101
|
+
* } else {
|
|
5102
|
+
* console.log(results);
|
|
5103
|
+
* // results is now the original array of files sorted by
|
|
5104
|
+
* // file size (ascending by default), e.g.
|
|
5105
|
+
* // [ 'smallfile.txt', 'mediumfile.txt', 'bigfile.txt']
|
|
5106
|
+
* }
|
|
5107
|
+
* }
|
|
5108
|
+
* );
|
|
4073
5109
|
*
|
|
4074
5110
|
* // By modifying the callback parameter the
|
|
4075
5111
|
* // sorting order can be influenced:
|
|
4076
5112
|
*
|
|
4077
5113
|
* // ascending order
|
|
4078
|
-
* async.sortBy([
|
|
4079
|
-
*
|
|
4080
|
-
*
|
|
4081
|
-
*
|
|
4082
|
-
*
|
|
5114
|
+
* async.sortBy(['mediumfile.txt','smallfile.txt','bigfile.txt'], function(file, callback) {
|
|
5115
|
+
* getFileSizeInBytes(file, function(getFileSizeErr, fileSize) {
|
|
5116
|
+
* if (getFileSizeErr) return callback(getFileSizeErr);
|
|
5117
|
+
* callback(null, fileSize);
|
|
5118
|
+
* });
|
|
5119
|
+
* }, function(err, results) {
|
|
5120
|
+
* if (err) {
|
|
5121
|
+
* console.log(err);
|
|
5122
|
+
* } else {
|
|
5123
|
+
* console.log(results);
|
|
5124
|
+
* // results is now the original array of files sorted by
|
|
5125
|
+
* // file size (ascending by default), e.g.
|
|
5126
|
+
* // [ 'smallfile.txt', 'mediumfile.txt', 'bigfile.txt']
|
|
5127
|
+
* }
|
|
5128
|
+
* }
|
|
5129
|
+
* );
|
|
4083
5130
|
*
|
|
4084
5131
|
* // descending order
|
|
4085
|
-
* async.sortBy([
|
|
4086
|
-
*
|
|
4087
|
-
*
|
|
4088
|
-
*
|
|
5132
|
+
* async.sortBy(['bigfile.txt','mediumfile.txt','smallfile.txt'], function(file, callback) {
|
|
5133
|
+
* getFileSizeInBytes(file, function(getFileSizeErr, fileSize) {
|
|
5134
|
+
* if (getFileSizeErr) {
|
|
5135
|
+
* return callback(getFileSizeErr);
|
|
5136
|
+
* }
|
|
5137
|
+
* callback(null, fileSize * -1);
|
|
5138
|
+
* });
|
|
5139
|
+
* }, function(err, results) {
|
|
5140
|
+
* if (err) {
|
|
5141
|
+
* console.log(err);
|
|
5142
|
+
* } else {
|
|
5143
|
+
* console.log(results);
|
|
5144
|
+
* // results is now the original array of files sorted by
|
|
5145
|
+
* // file size (ascending by default), e.g.
|
|
5146
|
+
* // [ 'bigfile.txt', 'mediumfile.txt', 'smallfile.txt']
|
|
5147
|
+
* }
|
|
5148
|
+
* }
|
|
5149
|
+
* );
|
|
5150
|
+
*
|
|
5151
|
+
* // Error handling
|
|
5152
|
+
* async.sortBy(['mediumfile.txt','smallfile.txt','missingfile.txt'], getFileSizeInBytes,
|
|
5153
|
+
* function(err, results) {
|
|
5154
|
+
* if (err) {
|
|
5155
|
+
* console.log(err);
|
|
5156
|
+
* // [ Error: ENOENT: no such file or directory ]
|
|
5157
|
+
* } else {
|
|
5158
|
+
* console.log(results);
|
|
5159
|
+
* }
|
|
5160
|
+
* }
|
|
5161
|
+
* );
|
|
5162
|
+
*
|
|
5163
|
+
* // Using Promises
|
|
5164
|
+
* async.sortBy(['mediumfile.txt','smallfile.txt','bigfile.txt'], getFileSizeInBytes)
|
|
5165
|
+
* .then( results => {
|
|
5166
|
+
* console.log(results);
|
|
5167
|
+
* // results is now the original array of files sorted by
|
|
5168
|
+
* // file size (ascending by default), e.g.
|
|
5169
|
+
* // [ 'smallfile.txt', 'mediumfile.txt', 'bigfile.txt']
|
|
5170
|
+
* }).catch( err => {
|
|
5171
|
+
* console.log(err);
|
|
5172
|
+
* });
|
|
5173
|
+
*
|
|
5174
|
+
* // Error handling
|
|
5175
|
+
* async.sortBy(['mediumfile.txt','smallfile.txt','missingfile.txt'], getFileSizeInBytes)
|
|
5176
|
+
* .then( results => {
|
|
5177
|
+
* console.log(results);
|
|
5178
|
+
* }).catch( err => {
|
|
5179
|
+
* console.log(err);
|
|
5180
|
+
* // [ Error: ENOENT: no such file or directory ]
|
|
4089
5181
|
* });
|
|
5182
|
+
*
|
|
5183
|
+
* // Using async/await
|
|
5184
|
+
* (async () => {
|
|
5185
|
+
* try {
|
|
5186
|
+
* let results = await async.sortBy(['bigfile.txt','mediumfile.txt','smallfile.txt'], getFileSizeInBytes);
|
|
5187
|
+
* console.log(results);
|
|
5188
|
+
* // results is now the original array of files sorted by
|
|
5189
|
+
* // file size (ascending by default), e.g.
|
|
5190
|
+
* // [ 'smallfile.txt', 'mediumfile.txt', 'bigfile.txt']
|
|
5191
|
+
* }
|
|
5192
|
+
* catch (err) {
|
|
5193
|
+
* console.log(err);
|
|
5194
|
+
* }
|
|
5195
|
+
* })();
|
|
5196
|
+
*
|
|
5197
|
+
* // Error handling
|
|
5198
|
+
* async () => {
|
|
5199
|
+
* try {
|
|
5200
|
+
* let results = await async.sortBy(['missingfile.txt','mediumfile.txt','smallfile.txt'], getFileSizeInBytes);
|
|
5201
|
+
* console.log(results);
|
|
5202
|
+
* }
|
|
5203
|
+
* catch (err) {
|
|
5204
|
+
* console.log(err);
|
|
5205
|
+
* // [ Error: ENOENT: no such file or directory ]
|
|
5206
|
+
* }
|
|
5207
|
+
* }
|
|
5208
|
+
*
|
|
4090
5209
|
*/
|
|
4091
5210
|
function sortBy (coll, iteratee, callback) {
|
|
4092
5211
|
var _iteratee = wrapAsync(iteratee);
|
|
@@ -4287,26 +5406,118 @@ function timesSeries (n, iteratee, callback) {
|
|
|
4287
5406
|
* @returns {Promise} a promise, if no callback provided
|
|
4288
5407
|
* @example
|
|
4289
5408
|
*
|
|
4290
|
-
*
|
|
4291
|
-
*
|
|
4292
|
-
*
|
|
4293
|
-
*
|
|
4294
|
-
*
|
|
5409
|
+
* // file1.txt is a file that is 1000 bytes in size
|
|
5410
|
+
* // file2.txt is a file that is 2000 bytes in size
|
|
5411
|
+
* // file3.txt is a file that is 3000 bytes in size
|
|
5412
|
+
*
|
|
5413
|
+
* // helper function that returns human-readable size format from bytes
|
|
5414
|
+
* function formatBytes(bytes, decimals = 2) {
|
|
5415
|
+
* // implementation not included for brevity
|
|
5416
|
+
* return humanReadbleFilesize;
|
|
5417
|
+
* }
|
|
5418
|
+
*
|
|
5419
|
+
* const fileList = ['file1.txt','file2.txt','file3.txt'];
|
|
5420
|
+
*
|
|
5421
|
+
* // asynchronous function that returns the file size, transformed to human-readable format
|
|
5422
|
+
* // e.g. 1024 bytes = 1KB, 1234 bytes = 1.21 KB, 1048576 bytes = 1MB, etc.
|
|
5423
|
+
* function transformFileSize(acc, value, key, callback) {
|
|
5424
|
+
* fs.stat(value, function(err, stat) {
|
|
5425
|
+
* if (err) {
|
|
5426
|
+
* return callback(err);
|
|
5427
|
+
* }
|
|
5428
|
+
* acc[key] = formatBytes(stat.size);
|
|
5429
|
+
* callback(null);
|
|
4295
5430
|
* });
|
|
4296
|
-
* }
|
|
4297
|
-
*
|
|
5431
|
+
* }
|
|
5432
|
+
*
|
|
5433
|
+
* // Using callbacks
|
|
5434
|
+
* async.transform(fileList, transformFileSize, function(err, result) {
|
|
5435
|
+
* if(err) {
|
|
5436
|
+
* console.log(err);
|
|
5437
|
+
* } else {
|
|
5438
|
+
* console.log(result);
|
|
5439
|
+
* // [ '1000 Bytes', '1.95 KB', '2.93 KB' ]
|
|
5440
|
+
* }
|
|
5441
|
+
* });
|
|
5442
|
+
*
|
|
5443
|
+
* // Using Promises
|
|
5444
|
+
* async.transform(fileList, transformFileSize)
|
|
5445
|
+
* .then(result => {
|
|
5446
|
+
* console.log(result);
|
|
5447
|
+
* // [ '1000 Bytes', '1.95 KB', '2.93 KB' ]
|
|
5448
|
+
* }).catch(err => {
|
|
5449
|
+
* console.log(err);
|
|
4298
5450
|
* });
|
|
4299
5451
|
*
|
|
5452
|
+
* // Using async/await
|
|
5453
|
+
* (async () => {
|
|
5454
|
+
* try {
|
|
5455
|
+
* let result = await async.transform(fileList, transformFileSize);
|
|
5456
|
+
* console.log(result);
|
|
5457
|
+
* // [ '1000 Bytes', '1.95 KB', '2.93 KB' ]
|
|
5458
|
+
* }
|
|
5459
|
+
* catch (err) {
|
|
5460
|
+
* console.log(err);
|
|
5461
|
+
* }
|
|
5462
|
+
* })();
|
|
5463
|
+
*
|
|
4300
5464
|
* @example
|
|
4301
5465
|
*
|
|
4302
|
-
*
|
|
4303
|
-
*
|
|
4304
|
-
*
|
|
4305
|
-
*
|
|
4306
|
-
*
|
|
4307
|
-
*
|
|
4308
|
-
*
|
|
4309
|
-
*
|
|
5466
|
+
* // file1.txt is a file that is 1000 bytes in size
|
|
5467
|
+
* // file2.txt is a file that is 2000 bytes in size
|
|
5468
|
+
* // file3.txt is a file that is 3000 bytes in size
|
|
5469
|
+
*
|
|
5470
|
+
* // helper function that returns human-readable size format from bytes
|
|
5471
|
+
* function formatBytes(bytes, decimals = 2) {
|
|
5472
|
+
* // implementation not included for brevity
|
|
5473
|
+
* return humanReadbleFilesize;
|
|
5474
|
+
* }
|
|
5475
|
+
*
|
|
5476
|
+
* const fileMap = { f1: 'file1.txt', f2: 'file2.txt', f3: 'file3.txt' };
|
|
5477
|
+
*
|
|
5478
|
+
* // asynchronous function that returns the file size, transformed to human-readable format
|
|
5479
|
+
* // e.g. 1024 bytes = 1KB, 1234 bytes = 1.21 KB, 1048576 bytes = 1MB, etc.
|
|
5480
|
+
* function transformFileSize(acc, value, key, callback) {
|
|
5481
|
+
* fs.stat(value, function(err, stat) {
|
|
5482
|
+
* if (err) {
|
|
5483
|
+
* return callback(err);
|
|
5484
|
+
* }
|
|
5485
|
+
* acc[key] = formatBytes(stat.size);
|
|
5486
|
+
* callback(null);
|
|
5487
|
+
* });
|
|
5488
|
+
* }
|
|
5489
|
+
*
|
|
5490
|
+
* // Using callbacks
|
|
5491
|
+
* async.transform(fileMap, transformFileSize, function(err, result) {
|
|
5492
|
+
* if(err) {
|
|
5493
|
+
* console.log(err);
|
|
5494
|
+
* } else {
|
|
5495
|
+
* console.log(result);
|
|
5496
|
+
* // { f1: '1000 Bytes', f2: '1.95 KB', f3: '2.93 KB' }
|
|
5497
|
+
* }
|
|
5498
|
+
* });
|
|
5499
|
+
*
|
|
5500
|
+
* // Using Promises
|
|
5501
|
+
* async.transform(fileMap, transformFileSize)
|
|
5502
|
+
* .then(result => {
|
|
5503
|
+
* console.log(result);
|
|
5504
|
+
* // { f1: '1000 Bytes', f2: '1.95 KB', f3: '2.93 KB' }
|
|
5505
|
+
* }).catch(err => {
|
|
5506
|
+
* console.log(err);
|
|
5507
|
+
* });
|
|
5508
|
+
*
|
|
5509
|
+
* // Using async/await
|
|
5510
|
+
* async () => {
|
|
5511
|
+
* try {
|
|
5512
|
+
* let result = await async.transform(fileMap, transformFileSize);
|
|
5513
|
+
* console.log(result);
|
|
5514
|
+
* // { f1: '1000 Bytes', f2: '1.95 KB', f3: '2.93 KB' }
|
|
5515
|
+
* }
|
|
5516
|
+
* catch (err) {
|
|
5517
|
+
* console.log(err);
|
|
5518
|
+
* }
|
|
5519
|
+
* }
|
|
5520
|
+
*
|
|
4310
5521
|
*/
|
|
4311
5522
|
function transform (coll, accumulator, iteratee, callback) {
|
|
4312
5523
|
if (arguments.length <= 3 && typeof accumulator === 'function') {
|
|
@@ -4484,7 +5695,7 @@ var whilst$1 = awaitify(whilst, 3);
|
|
|
4484
5695
|
* @example
|
|
4485
5696
|
* const results = []
|
|
4486
5697
|
* let finished = false
|
|
4487
|
-
* async.until(function test(
|
|
5698
|
+
* async.until(function test(cb) {
|
|
4488
5699
|
* cb(null, finished)
|
|
4489
5700
|
* }, function iter(next) {
|
|
4490
5701
|
* fetchPage(url, (err, body) => {
|