-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
25 lines (23 loc) · 819 Bytes
/
Copy pathindex.js
File metadata and controls
25 lines (23 loc) · 819 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
'use strict'
const arrayPad = require('array-pad')
const ffn = require('ffn')
const isGlobalObject = require('is-global-object')
const isNil = require('is-nil')
const isObject = require('is-object')
const ofn = require('ofn')
const plainify = require('plainify')
const set = require('fast-path-set')
const wfn = require('wfn')
module.exports = ofn([2, 0, 1], (options, bcPath, f) => wfn(f, function supportBindOperator () {
const {arg: i = 0, path = bcPath, ignoreThis} = plainify('arg', options)
const args = arrayPad(Array.from(arguments), i)
if (!isNil(this) && !isGlobalObject(this) && !ffn(ignoreThis, {blacklist: true})(this)) {
if (path) {
if (!isObject(args[i])) args[i] = {}
set(args[i], path, this)
} else {
args.splice(i, 0, this)
}
}
return f.apply(this, args)
}))