chore(complex-matcher): remove unnecessary invoke

This commit is contained in:
Julien Fontanet 2018-02-04 16:35:57 +01:00
parent 191c531bad
commit 138d5627b5

View File

@ -2,43 +2,7 @@ import { isPlainObject, some } from 'lodash'
// =================================================================== // ===================================================================
// Invoke a function and returns it result. const RAW_STRING_CHARS = (() => {
// All parameters are forwarded.
//
// Why using `invoke()`?
// - avoid tedious IIFE syntax
// - avoid declaring variables in the common scope
// - monkey-patching
//
// ```js
// const sum = invoke(1, 2, (a, b) => a + b)
//
// eventEmitter.emit = invoke(eventEmitter.emit, emit => function (event) {
// if (event === 'foo') {
// throw new Error('event foo is disabled')
// }
//
// return emit.apply(this, arguments)
// })
// ```
function invoke (fn) {
const n = arguments.length - 1
if (!n) {
return fn()
}
fn = arguments[n]
const args = new Array(n)
for (let i = 0; i < n; ++i) {
args[i] = arguments[i]
}
return fn.apply(undefined, args)
}
// ===================================================================
const RAW_STRING_CHARS = invoke(() => {
const chars = { __proto__: null } const chars = { __proto__: null }
const add = (a, b = a) => { const add = (a, b = a) => {
let i = a.charCodeAt(0) let i = a.charCodeAt(0)
@ -55,7 +19,7 @@ const RAW_STRING_CHARS = invoke(() => {
add('A', 'Z') add('A', 'Z')
add('a', 'z') add('a', 'z')
return chars return chars
}) })()
const isRawString = string => { const isRawString = string => {
const { length } = string const { length } = string
for (let i = 0; i < length; ++i) { for (let i = 0; i < length; ++i) {