UNPKG

crocks

Version:

A collection of well known Algebraic Datatypes for your utter enjoyment.

52 lines (40 loc) 1.15 kB
/** @license ISC License (c) copyright 2019 original and current authors */ /** @author Ian Hofmann-Hicks (evil) */ var curry = require('../core/curry') var isArray = require('../core/isArray') var isEmpty = require('../core/isEmpty') var isInteger = require('../core/isInteger') var isObject = require('../core/isObject') var isString = require('../core/isString') var array = require('../core/array') var object = require('../core/object') function fn(name) { function unsetProp(key, obj) { if(!(isObject(obj) || isArray(obj))) { return obj } if(!(isString(key) && !isEmpty(key) || isInteger(key) && key >= 0)) { throw new TypeError( (name + ": Non-empty String required or Positive Integer required for first argument") ) } if(isObject(obj)) { if(isString(key) && !isEmpty(key)) { return object.unset(key, obj) } } if(isArray(obj)) { if(isInteger(key) && key >= 0) { return array.unset(key, obj) } } return obj } return curry(unsetProp) } var unsetProp = fn('unsetProp') unsetProp.origFn = fn module.exports = unsetProp