| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 10ae868 commit b95cfdf
1 file changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -18,7 +18,6 @@ const { AbortController, AbortSignal } = require('internal/abort_controller'); | |||
| 18 | 18 | const { | |
| 19 | 19 | AbortError, | |
| 20 | 20 | codes: { | |
| 21 | - ERR_INVALID_ARG_TYPE, | ||
| 22 | 21 | ERR_INVALID_ARG_VALUE, | |
| 23 | 22 | ERR_MISSING_ARGS, | |
| 24 | 23 | ERR_OUT_OF_RANGE, | |
@@ -28,6 +27,7 @@ const { | |||
| 28 | 27 | validateAbortSignal, | |
| 29 | 28 | validateInteger, | |
| 30 | 29 | validateObject, | |
| 30 | + validateFunction, | ||
| 31 | 31 | } = require('internal/validators'); | |
| 32 | 32 | const { kWeakHandler, kResistStopPropagation } = require('internal/event_target'); | |
| 33 | 33 | const { finished } = require('internal/streams/end-of-stream'); | |
@@ -66,10 +66,7 @@ function compose(stream, options) { | |||
| 66 | 66 | } | |
| 67 | 67 | ||
| 68 | 68 | function map(fn, options) { | |
| 69 | - if (typeof fn !== 'function') { | ||
| 70 | - throw new ERR_INVALID_ARG_TYPE( | ||
| 71 | - 'fn', ['Function', 'AsyncFunction'], fn); | ||
| 72 | - } | ||
| 69 | + validateFunction(fn, 'fn'); | ||
| 73 | 70 | if (options != null) { | |
| 74 | 71 | validateObject(options, 'options'); | |
| 75 | 72 | } | |
@@ -223,10 +220,7 @@ async function some(fn, options = undefined) { | |||
| 223 | 220 | } | |
| 224 | 221 | ||
| 225 | 222 | async function every(fn, options = undefined) { | |
| 226 | - if (typeof fn !== 'function') { | ||
| 227 | - throw new ERR_INVALID_ARG_TYPE( | ||
| 228 | - 'fn', ['Function', 'AsyncFunction'], fn); | ||
| 229 | - } | ||
| 223 | + validateFunction(fn, 'fn'); | ||
| 230 | 224 | // https://en.wikipedia.org/wiki/De_Morgan%27s_laws | |
| 231 | 225 | return !(await some.call(this, async (...args) => { | |
| 232 | 226 | return !(await fn(...args)); | |
@@ -241,10 +235,7 @@ async function find(fn, options) { | |||
| 241 | 235 | } | |
| 242 | 236 | ||
| 243 | 237 | async function forEach(fn, options) { | |
| 244 | - if (typeof fn !== 'function') { | ||
| 245 | - throw new ERR_INVALID_ARG_TYPE( | ||
| 246 | - 'fn', ['Function', 'AsyncFunction'], fn); | ||
| 247 | - } | ||
| 238 | + validateFunction(fn, 'fn'); | ||
| 248 | 239 | async function forEachFn(value, options) { | |
| 249 | 240 | await fn(value, options); | |
| 250 | 241 | return kEmpty; | |
@@ -254,10 +245,7 @@ async function forEach(fn, options) { | |||
| 254 | 245 | } | |
| 255 | 246 | ||
| 256 | 247 | function filter(fn, options) { | |
| 257 | - if (typeof fn !== 'function') { | ||
| 258 | - throw new ERR_INVALID_ARG_TYPE( | ||
| 259 | - 'fn', ['Function', 'AsyncFunction'], fn); | ||
| 260 | - } | ||
| 248 | + validateFunction(fn, 'fn'); | ||
| 261 | 249 | async function filterFn(value, options) { | |
| 262 | 250 | if (await fn(value, options)) { | |
| 263 | 251 | return value; | |
@@ -277,10 +265,7 @@ class ReduceAwareErrMissingArgs extends ERR_MISSING_ARGS { | |||
| 277 | 265 | } | |
| 278 | 266 | ||
| 279 | 267 | async function reduce(reducer, initialValue, options) { | |
| 280 | - if (typeof reducer !== 'function') { | ||
| 281 | - throw new ERR_INVALID_ARG_TYPE( | ||
| 282 | - 'reducer', ['Function', 'AsyncFunction'], reducer); | ||
| 283 | - } | ||
| 268 | + validateFunction(reducer, 'reducer'); | ||
| 284 | 269 | if (options != null) { | |
| 285 | 270 | validateObject(options, 'options'); | |
| 286 | 271 | } | |
| Back | FazBrowse Home | New Git URL |
0 commit comments