Inline FUNC_ERROR_TEXT.

This commit is contained in:
John-David Dalton
2017-01-09 18:51:09 -08:00
parent 71039740c3
commit 6d28724e48
11 changed files with 11 additions and 44 deletions

View File

@@ -1,6 +1,3 @@
/** Error message constants. */
const FUNC_ERROR_TEXT = 'Expected a function';
/**
* The base implementation of `delay` and `defer` which accepts `args`
* to provide to `func`.
@@ -13,7 +10,7 @@ const FUNC_ERROR_TEXT = 'Expected a function';
*/
function baseDelay(func, wait, args) {
if (typeof func != 'function') {
throw new TypeError(FUNC_ERROR_TEXT);
throw new TypeError('Expected a function');
}
return setTimeout(() => func(...args), wait);
}

View File

@@ -1,6 +1,3 @@
/** Error message constants. */
const FUNC_ERROR_TEXT = 'Expected a function';
/**
* Creates a `flow` or `flowRight` function.
*
@@ -22,7 +19,7 @@ function createFlow(fromRight) {
while (index--) {
func = funcs[index];
if (typeof func != 'function') {
throw new TypeError(FUNC_ERROR_TEXT);
throw new TypeError('Expected a function');
}
}
return function(...args) {

View File

@@ -9,9 +9,6 @@ import setData from './_setData.js';
import setWrapToString from './_setWrapToString.js';
import toInteger from './toInteger.js';
/** Error message constants. */
const FUNC_ERROR_TEXT = 'Expected a function';
/** Used to compose bitmasks for function metadata. */
const WRAP_BIND_FLAG = 1;
const WRAP_BIND_KEY_FLAG = 2;
@@ -51,7 +48,7 @@ const nativeMax = Math.max;
function createWrap(func, bitmask, thisArg, partials, holders, argPos, ary, arity) {
const isBindKey = bitmask & WRAP_BIND_KEY_FLAG;
if (!isBindKey && typeof func != 'function') {
throw new TypeError(FUNC_ERROR_TEXT);
throw new TypeError('Expected a function');
}
let length = partials ? partials.length : 0;
if (!length) {

View File

@@ -1,8 +1,5 @@
import toInteger from './toInteger.js';
/** Error message constants. */
const FUNC_ERROR_TEXT = 'Expected a function';
/**
* The opposite of `before`; this method creates a function that invokes
* `func` once it's called `n` or more times.
@@ -28,7 +25,7 @@ const FUNC_ERROR_TEXT = 'Expected a function';
*/
function after(n, func) {
if (typeof func != 'function') {
throw new TypeError(FUNC_ERROR_TEXT);
throw new TypeError('Expected a function');
}
n = toInteger(n);
return function(...args) {

View File

@@ -1,8 +1,5 @@
import toInteger from './toInteger.js';
/** Error message constants. */
const FUNC_ERROR_TEXT = 'Expected a function';
/**
* Creates a function that invokes `func`, with the `this` binding and arguments
* of the created function, while it's called less than `n` times. Subsequent
@@ -22,7 +19,7 @@ const FUNC_ERROR_TEXT = 'Expected a function';
function before(n, func) {
let result;
if (typeof func != 'function') {
throw new TypeError(FUNC_ERROR_TEXT);
throw new TypeError('Expected a function');
}
n = toInteger(n);
return function(...args) {

View File

@@ -1,9 +1,6 @@
import apply from './_apply.js';
import arrayMap from './_arrayMap.js';
/** Error message constants. */
const FUNC_ERROR_TEXT = 'Expected a function';
/**
* Creates a function that iterates over `pairs` and invokes the corresponding
* function of the first predicate to return truthy. The predicate-function
@@ -37,7 +34,7 @@ function cond(pairs) {
pairs = !length ? [] : arrayMap(pairs, pair => {
if (typeof pair[1] != 'function') {
throw new TypeError(FUNC_ERROR_TEXT);
throw new TypeError('Expected a function');
}
return [pair[0], pair[1]];
});

View File

@@ -1,9 +1,6 @@
import isObject from './isObject.js';
import toNumber from './toNumber.js';
/** Error message constants. */
const FUNC_ERROR_TEXT = 'Expected a function';
/* Built-in method references for those with the same name as other `lodash` methods. */
const nativeMax = Math.max;
const nativeMin = Math.min;
@@ -75,7 +72,7 @@ function debounce(func, wait, options) {
let trailing = true;
if (typeof func != 'function') {
throw new TypeError(FUNC_ERROR_TEXT);
throw new TypeError('Expected a function');
}
wait = toNumber(wait) || 0;
if (isObject(options)) {

View File

@@ -1,8 +1,5 @@
import MapCache from './_MapCache.js';
/** Error message constants. */
const FUNC_ERROR_TEXT = 'Expected a function';
/**
* Creates a function that memoizes the result of `func`. If `resolver` is
* provided, it determines the cache key for storing the result based on the
@@ -48,7 +45,7 @@ const FUNC_ERROR_TEXT = 'Expected a function';
*/
function memoize(func, resolver) {
if (typeof func != 'function' || (resolver != null && typeof resolver != 'function')) {
throw new TypeError(FUNC_ERROR_TEXT);
throw new TypeError('Expected a function');
}
const memoized = function(...args) {
const key = resolver ? resolver.apply(this, args) : args[0];

View File

@@ -1,6 +1,3 @@
/** Error message constants. */
const FUNC_ERROR_TEXT = 'Expected a function';
/**
* Creates a function that negates the result of the predicate `func`. The
* `func` predicate is invoked with the `this` binding and arguments of the
@@ -22,7 +19,7 @@ const FUNC_ERROR_TEXT = 'Expected a function';
*/
function negate(predicate) {
if (typeof predicate != 'function') {
throw new TypeError(FUNC_ERROR_TEXT);
throw new TypeError('Expected a function');
}
return function(...args) {
return !predicate.apply(this, args);

View File

@@ -3,9 +3,6 @@ import arrayPush from './_arrayPush.js';
import castSlice from './_castSlice.js';
import toInteger from './toInteger.js';
/** Error message constants. */
const FUNC_ERROR_TEXT = 'Expected a function';
/* Built-in method references for those with the same name as other `lodash` methods. */
const nativeMax = Math.max;
@@ -44,7 +41,7 @@ const nativeMax = Math.max;
*/
function spread(func, start) {
if (typeof func != 'function') {
throw new TypeError(FUNC_ERROR_TEXT);
throw new TypeError('Expected a function');
}
start = start == null ? 0 : nativeMax(toInteger(start), 0);
return (...args) => {

View File

@@ -1,9 +1,6 @@
import debounce from './debounce.js';
import isObject from './isObject.js';
/** Error message constants. */
const FUNC_ERROR_TEXT = 'Expected a function';
/**
* Creates a throttled function that only invokes `func` at most once per
* every `wait` milliseconds. The throttled function comes with a `cancel`
@@ -52,7 +49,7 @@ function throttle(func, wait, options) {
let trailing = true;
if (typeof func != 'function') {
throw new TypeError(FUNC_ERROR_TEXT);
throw new TypeError('Expected a function');
}
if (isObject(options)) {
leading = 'leading' in options ? !!options.leading : leading;