object

Object operations/combinators.

Members

static, constant native :Object

Contains all the static functions from `Object` but curried and flipped;
Example
// E.g., `Object.defineProperties(obj, descriptor)` can now be used like
import {defineProperties} from 'fjl'
defineProperties(descriptor, someObj),
// Et. al.

Methods

static assign(obj0, …objs) → {Object}

Defined as `Object.assign` else is the same thing but shimmed.
Parameters:
Name Type Attributes Description
obj0 Object
objs Object <repeatable>
Returns:
Object

static assignDeep(obj0, …objsopt) → {Object}

Merges all objects down into one (takes two or more args).
Parameters:
Name Type Attributes Description
obj0 Object
objs Object <optional>
<repeatable>
One or more objects to merge onto `obj0`.
Returns:
Object

static copy(x, outopt) → {*}

Make a copy of a value or optionally copy incoming value onto an outgoing value (second parameter).
Parameters:
Name Type Attributes Description
x * Thing to copy.
out * <optional>
Optional value to copy on to. Not required.
Returns:
* - - Copied thing or optionally outgoing value copied onto.

static createTypedDescriptor(Type, target, propName) → {Descriptor}

Creates a descriptor for a property which is settable but throws errors when the `Type` is disobeyed.
Parameters:
Name Type Description
Type TypeRef {String|Function}
target *
propName String
Returns:
Descriptor - - Property descriptor with just getter and setter.

static defineEnumProp(Type, target, propName, defaultValueopt) → {TargetDescriptorTuple}

Allows you to define a "typed", enumerated property on `target`.
Parameters:
Name Type Attributes Description
Type TypeRef {String|Function}
target TargetDescriptorTuple Target or array of target and descriptor ([target, descriptor]).
propName String
defaultValue * <optional>

static defineEnumProps(argsTuple, targetopt) → {Array.<TargetDescriptorTuple>}

Allows you to define multiple enum props at once on target.
Parameters:
Name Type Attributes Description
argsTuple Array.<DefinePropArgsTuple> Array of argArrays for `defineEnumProp`.
target Target <optional>
Target to use in internal calls if one is not provided but encountered 'argArray'.
Returns:
Array.<TargetDescriptorTuple> - - Results of each call to `defineEnumProp`.

static defineProp(Type, target, propName, defaultValueopt) → {TargetDescriptorTuple}

Allows you to define a "typed" property on given `target`.
Parameters:
Name Type Attributes Description
Type TypeRef {String|Function}
target TargetDescriptorTuple Target or array of target and descriptor ([target, descriptor]).
propName String
defaultValue * <optional>

static defineProps(argsTuple, targetopt) → {Array.<TargetDescriptorTuple>}

Allows you to define multiple props at once on target.
Parameters:
Name Type Attributes Description
argsTuple Array.<DefinePropArgsTuple> Array of argArrays for `defineProp`.
target Target <optional>
Target to use in internal calls if one is not provided but encountered 'argArray'.
Returns:
Array.<TargetDescriptorTuple> - - Results of each call to `defineProp`.

static fromAssocList(xs, OutTypeopt) → {*}

From associated list to object.
Parameters:
Name Type Attributes Default Description
xs Array.<Array> Associated list.
OutType Constructor | function <optional>
Object Output type. Default `Object`.
Returns:
* - - Default is `Object`

static fromAssocListDeep(xs, OutTypeopt) → {*}

From associated list to object (deep conversion on associative lists (array of 2 value arrays)).
Parameters:
Name Type Attributes Default Description
xs Array.<Array> Associated list.
OutType Constructor | function <optional>
Object Output type. Default `Object`.
Returns:
* - - Default is `Object`

static hasOwnProperty(propName, typeInstance) → {Boolean}

Parameters:
Name Type Description
propName *
typeInstance *
Returns:
Boolean
Deprecated:
  • - Use property directly instead.

static instanceOf(instanceConstructor, instance) → {Boolean}

Returns whether constructor has derived object.
Parameters:
Name Type Description
instanceConstructor function Constructor.
instance *
Returns:
Boolean

static instanceOfOne(x, …types) → {boolean}

Checks if given value is instance of one of the types given.
Parameters:
Name Type Attributes Description
x *
types TypeRef <repeatable>
Returns:
boolean

static isArray(value) → {boolean}

Checks if value is an array (same as `Array.isArray`).
Parameters:
Name Type Description
value *
Returns:
boolean

static isBoolean(value) → {Boolean}

Checks if value is a boolean.
Parameters:
Name Type Description
value *
Returns:
Boolean

static isCallable(x) → {Boolean}

Returns a boolean depicting whether a value is callable or not.
Parameters:
Name Type Description
x *
Returns:
Boolean

static isClass(x) → {boolean}

Checks if `value` is an es2015 `class`.
Parameters:
Name Type Description
x *
Returns:
boolean

static isEmpty(x) → {Boolean}

Checks to see if passed in value is empty; I.e., check for one of '', 0, `null`, `undefined`, `NaN`, `false`, empty array, empty object, ~~empty function (zero arity)~~, or empty collection (es6 collection: Map, Set, WeakMap, or WeakSet etc.) (`!value.size`).
Parameters:
Name Type Description
x * Value to check.
Returns:
Boolean

static isEmptyCollection(x) → {Boolean}

Checks if collection is empty or not (Map, WeakMap, WeakSet, Set etc.).
Parameters:
Name Type Description
x *
Returns:
Boolean

static isEmptyList(x) → {Boolean}

Checks if !length.
Parameters:
Name Type Description
x *
Returns:
Boolean

static isEmptyObject(obj) → {Boolean}

Checks if object has own properties/enumerable-props or not.
Parameters:
Name Type Description
obj *
Returns:
Boolean

static isFunction(value) → {Boolean}

Returns whether a value is a function or not.
Parameters:
Name Type Description
value *
Returns:
Boolean

static isFunctor(x) → {bool}

Checks if value qualifies (has `map` method) as a functor.
Parameters:
Name Type Description
x *
Returns:
bool

static isLoosely(type, x) → {Boolean}

Synonym for `isOfType` (or just a more accurate name).
Parameters:
Name Type Description
type function | String Type reference (constructor or `constructor.name`).
x * Value to check.
Returns:
Boolean

static isLooselyOneOf(x, …types) → {boolean}

Checks if given value is either strictly one of given types or is an `instanceof` one of given types.
Parameters:
Name Type Attributes Description
x *
types TypeRef <repeatable>
Returns:
boolean

static isMap(value) → {Boolean}

Checks whether value is of `Map` or not.
Parameters:
Name Type Description
value *
Returns:
Boolean

static isNull(value) → {Boolean}

Checks if value is null.
Parameters:
Name Type Description
value *
Returns:
Boolean

static isNumber(value) → {Boolean}

Checks if value is a valid number (also checks if isNaN so that you don't have to).
Parameters:
Name Type Description
value *
Returns:
Boolean

static isObject(value) → {Boolean}

Checks whether value is an object or not.
Parameters:
Name Type Description
value
Returns:
Boolean

static isOfType(type, x) → {Boolean}

Loose type checker; E.g., If `type` is not a constructor, but a constructor name, does a type check on constructor names, else if first check fails and `type` is a constructor, performs an `instanceof` check on value with constructor.
Parameters:
Name Type Description
type function | String Type reference (constructor or `constructor.name`).
x * Value to check.
Returns:
Boolean
Example
isOfType(Number, 99) === true        // true  (passes strict type check (numbers are not instances of `Number`
                                     //        constructor)
isOfType('Number', 99) === true      // true  (passes strict type check)
isOfType(Number, NaN) === true       // true. (passes instance of check)
                                     //        If you want "true" strict type checking use `isType`
isOfType(Object, []) === true        // true  (passes instance of check)
isOfType(Array, []) === true         // true  (passes instance of check)
isOfType(Object, {}) === true        // true  (passes instance of check)
isOfType(Object.name, {}) === true   // true  (Passes strict type check)
class Abc extends String {}
isOfType(String, new Abc('abcd')) // true (passes instanceof check)

static isSet(value) → {Boolean}

Checks whether value is of `Set` or not.
Parameters:
Name Type Description
value *
Returns:
Boolean

static isset(x) → {Boolean}

Returns whether passed in values is defined and not null or not.
Parameters:
Name Type Description
x *
Returns:
Boolean

static isStrictly(type, obj) → {Boolean}

Synonym for `isType` (or just a more accurate name for `isType`).
Parameters:
Name Type Description
type function | ObjectConstructor | String Constructor or constructor name
obj *
Returns:
Boolean

static isStrictlyOneOf(x, …types) → {boolean}

Checks if given value is strictly one of given types.
Parameters:
Name Type Attributes Description
x *
types TypeRef <repeatable>
Returns:
boolean

static isString(value) → {Boolean}

Checks whether value is a string or not.
Parameters:
Name Type Description
value *
Returns:
Boolean

static isSymbol(value) → {Boolean}

Checks if value is a `Symbol`.
Parameters:
Name Type Description
value *
Returns:
Boolean

static isType(type, obj) → {Boolean}

Strict type checker. Checks if given value is a direct instance of given type; E.g.,
Parameters:
Name Type Description
type function | ObjectConstructor | String Constructor or constructor name
obj *
Returns:
Boolean
Example
isType(String, 'abcdefg')  === true // true
  isType(String.name, 'abcdefg') === true
  isType(Number, NaN) === false
  isType(Number, 99) === true
  isType('Null', 99) === false // though, for `null` and `undefined` checks
                               // @see `isset`, in this module, instead
  isType('Undefined', undefined) === true // true

static isUndefined(value) → {Boolean}

Checks if value is undefined.
Parameters:
Name Type Description
value *
Returns:
Boolean

static isUsableImmutablePrimitive(x) → {Boolean}

Checks if given `x` is set and of one of [String, Boolean, Number, Symbol] (null and undefined are immutable but are not "usable" (usually not what we want to operate on).
Parameters:
Name Type Description
x *
Returns:
Boolean

static isWeakMap(value) → {Boolean}

Checks whether value is of `WeakMap` or not.
Parameters:
Name Type Description
value *
Returns:
Boolean

static isWeakSet(value) → {Boolean}

Checks whether value is of `WeakSet` or not.
Parameters:
Name Type Description
value *
Returns:
Boolean

static jsonClone(x) → {*}

Clones and object or array using `JSON.parse(JSON.stringify(...))` pattern.
Parameters:
Name Type Description
x *
Returns:
*

static keys(obj) → {Array.<String>}

Gets passed in object's own enumerable keys (same as `Object.keys`).
Parameters:
Name Type Description
obj *
Returns:
Array.<String>

static length(x) → {Number}

Parameters:
Name Type Description
x *
Throws:
- Throws an error if value doesn't have a `length` property ( `null`, `undefined`, {Boolean}, Symbol, et. al.).
Type
Error
Returns:
Number

static lookup(key, obj) → {*}

Looks up property and returns it's value; Else `undefined`. Method is null safe (will not throw on `null` or `undefined`).
Parameters:
Name Type Description
key String Key to search on `obj`
obj Object Object to search `name` on.
Returns:
*

static of(x, …argsopt) → {*|undefined}

Creates a value `of` given type; Checks for one of the following construction strategies (in order listed):
Parameters:
Name Type Attributes Description
x * Value to derive returned value's type from.
args * <optional>
<repeatable>
Any args to pass in to matched construction strategy.
Returns:
* | undefined - - New value of given value's type else `undefined`.
Example
// - If exists `(value).constructor.of` uses this.
// - If value is of one String, Boolean, Symbol, or Number types calls it's
//      constructor as a function (in cast form;  E.g., `constructor(...args)` )
// - Else if constructor is a function, thus far, then calls constructor using
//      the `new` keyword (with any passed in args).

static searchObj(nsString, obj) → {*}

Gives you value at key/namespace-key within `obj`; E.g., searchObj('all.your.base', {all: {your: {base: 99}}}) === 99 // `true`
Parameters:
Name Type Description
nsString String
obj *
Returns:
*
Example
```
if (obj && obj.all && obj.all.your && obj.all.your.base) {
  // Thing we want to do
}

// So with our function becomes
if (searchObj('all.your.base', obj)) {
  // Thing we want to do
}
```

static toArray(x) → {Array}

Converts incoming value to an array.
Parameters:
Name Type Description
x * Thing to convert from.
Returns:
Array

static toAssocList(obj) → {Array.<*, *>}

Returns an associated list from given object.
Parameters:
Name Type Description
obj Object | Array | *
Returns:
Array.<*, *>

static toAssocListDeep(obj, TypeConstraintopt) → {*}

Returns an associated list from given object (deeply (on incoming object's type)).
Parameters:
Name Type Attributes Default Description
obj *
TypeConstraint Constructor | function <optional>
Object Type constraint to convert on.
Returns:
*

static toEnumerableDescriptor() → {TargetDescriptorTuple}

Returns a target-descriptor tuple whose 'descriptor' will be set to enumerable (`enumerable: true`).
Parameters:
Type Description
TargetDescriptorTuple [target, descriptor] tuple.
Returns:
TargetDescriptorTuple - - Array of target and descriptor.

static toTargetDescriptorTuple(targetOrTargetDescriptorTuple) → {Array.<*>|Array.<*, *>}

Returns an target and descriptor tuple from given.
Parameters:
Name Type Description
targetOrTargetDescriptorTuple * | Array.<*, *> Target object or tuple of target and descriptor.
Returns:
Array.<*> | Array.<*, *>

static toTypeRef(type) → {String}

Resolves/normalizes a type name from either a string or a constructor.
Parameters:
Name Type Description
type function | String String or function representing a type.
Returns:
String
To Do:
  • write tests for this function.

static toTypeRefName(Type) → {String}

Returns possible Type's TypeRef name.
Parameters:
Name Type Description
Type TypeRef | *
Returns:
String
To Do:
  • Ensure tests are written for this function.

static toTypeRefNames(…types) → {Array.<String>}

Returns possible Types' TypeRef names.
Parameters:
Name Type Attributes Description
types TypeRef | * <repeatable>
Returns:
Array.<String>
To Do:
  • Ensure tests are written for this function.

static toTypeRefs(…types) → {Array.<TypeRef>}

Returns an array of type refs from possible type refs (converts null, undefined, NaN, and other values into type refs (either constructor name or constructor name based on whether value(s) is a string, a constructor, or not).
Parameters:
Name Type Attributes Description
types TypeRef | * <repeatable>
Returns:
Array.<TypeRef>
To Do:
  • Ensure tests are written for this function.

static typeOf(value) → {string}

Returns the constructor/class/type name of a value.
Parameters:
Name Type Description
value *
Returns:
string - - Constructor's name or derived name (in the case of `null`, `undefined`, or `NaN` (whose normalized names are 'Null', 'Undefined', 'NaN' respectively).

object

Members

static, constant native :Object

Contains all the static functions from `Object` but curried and flipped;
Example
// E.g., `Object.defineProperties(obj, descriptor)` can now be used like
import {defineProperties} from 'fjl'
defineProperties(descriptor, someObj),
// Et. al.

Methods

static assign(obj0, …objs) → {Object}

Defined as `Object.assign` else is the same thing but shimmed.
Parameters:
Name Type Attributes Description
obj0 Object
objs Object <repeatable>
Returns:
Object

static assignDeep(obj0, …objsopt) → {Object}

Merges all objects down into one (takes two or more args).
Parameters:
Name Type Attributes Description
obj0 Object
objs Object <optional>
<repeatable>
One or more objects to merge onto `obj0`.
Returns:
Object

static copy(x, outopt) → {*}

Make a copy of a value or optionally copy incoming value onto an outgoing value (second parameter).
Parameters:
Name Type Attributes Description
x * Thing to copy.
out * <optional>
Optional value to copy on to. Not required.
Returns:
* - - Copied thing or optionally outgoing value copied onto.

static createTypedDescriptor(Type, target, propName) → {Descriptor}

Creates a descriptor for a property which is settable but throws errors when the `Type` is disobeyed.
Parameters:
Name Type Description
Type TypeRef {String|Function}
target *
propName String
Returns:
Descriptor - - Property descriptor with just getter and setter.

static defineEnumProp(Type, target, propName, defaultValueopt) → {TargetDescriptorTuple}

Allows you to define a "typed", enumerated property on `target`.
Parameters:
Name Type Attributes Description
Type TypeRef {String|Function}
target TargetDescriptorTuple Target or array of target and descriptor ([target, descriptor]).
propName String
defaultValue * <optional>

static defineEnumProps(argsTuple, targetopt) → {Array.<TargetDescriptorTuple>}

Allows you to define multiple enum props at once on target.
Parameters:
Name Type Attributes Description
argsTuple Array.<DefinePropArgsTuple> Array of argArrays for `defineEnumProp`.
target Target <optional>
Target to use in internal calls if one is not provided but encountered 'argArray'.
Returns:
Array.<TargetDescriptorTuple> - - Results of each call to `defineEnumProp`.

static defineProp(Type, target, propName, defaultValueopt) → {TargetDescriptorTuple}

Allows you to define a "typed" property on given `target`.
Parameters:
Name Type Attributes Description
Type TypeRef {String|Function}
target TargetDescriptorTuple Target or array of target and descriptor ([target, descriptor]).
propName String
defaultValue * <optional>

static defineProps(argsTuple, targetopt) → {Array.<TargetDescriptorTuple>}

Allows you to define multiple props at once on target.
Parameters:
Name Type Attributes Description
argsTuple Array.<DefinePropArgsTuple> Array of argArrays for `defineProp`.
target Target <optional>
Target to use in internal calls if one is not provided but encountered 'argArray'.
Returns:
Array.<TargetDescriptorTuple> - - Results of each call to `defineProp`.

static fromAssocList(xs, OutTypeopt) → {*}

From associated list to object.
Parameters:
Name Type Attributes Default Description
xs Array.<Array> Associated list.
OutType Constructor | function <optional>
Object Output type. Default `Object`.
Returns:
* - - Default is `Object`

static fromAssocListDeep(xs, OutTypeopt) → {*}

From associated list to object (deep conversion on associative lists (array of 2 value arrays)).
Parameters:
Name Type Attributes Default Description
xs Array.<Array> Associated list.
OutType Constructor | function <optional>
Object Output type. Default `Object`.
Returns:
* - - Default is `Object`

static hasOwnProperty(propName, typeInstance) → {Boolean}

Parameters:
Name Type Description
propName *
typeInstance *
Returns:
Boolean
Deprecated:
  • - Use property directly instead.

static instanceOf(instanceConstructor, instance) → {Boolean}

Returns whether constructor has derived object.
Parameters:
Name Type Description
instanceConstructor function Constructor.
instance *
Returns:
Boolean

static instanceOfOne(x, …types) → {boolean}

Checks if given value is instance of one of the types given.
Parameters:
Name Type Attributes Description
x *
types TypeRef <repeatable>
Returns:
boolean

static isArray(value) → {boolean}

Checks if value is an array (same as `Array.isArray`).
Parameters:
Name Type Description
value *
Returns:
boolean

static isBoolean(value) → {Boolean}

Checks if value is a boolean.
Parameters:
Name Type Description
value *
Returns:
Boolean

static isCallable(x) → {Boolean}

Returns a boolean depicting whether a value is callable or not.
Parameters:
Name Type Description
x *
Returns:
Boolean

static isClass(x) → {boolean}

Checks if `value` is an es2015 `class`.
Parameters:
Name Type Description
x *
Returns:
boolean

static isEmpty(x) → {Boolean}

Checks to see if passed in value is empty; I.e., check for one of '', 0, `null`, `undefined`, `NaN`, `false`, empty array, empty object, ~~empty function (zero arity)~~, or empty collection (es6 collection: Map, Set, WeakMap, or WeakSet etc.) (`!value.size`).
Parameters:
Name Type Description
x * Value to check.
Returns:
Boolean

static isEmptyCollection(x) → {Boolean}

Checks if collection is empty or not (Map, WeakMap, WeakSet, Set etc.).
Parameters:
Name Type Description
x *
Returns:
Boolean

static isEmptyList(x) → {Boolean}

Checks if !length.
Parameters:
Name Type Description
x *
Returns:
Boolean

static isEmptyObject(obj) → {Boolean}

Checks if object has own properties/enumerable-props or not.
Parameters:
Name Type Description
obj *
Returns:
Boolean

static isFunction(value) → {Boolean}

Returns whether a value is a function or not.
Parameters:
Name Type Description
value *
Returns:
Boolean

static isFunctor(x) → {bool}

Checks if value qualifies (has `map` method) as a functor.
Parameters:
Name Type Description
x *
Returns:
bool

static isLoosely(type, x) → {Boolean}

Synonym for `isOfType` (or just a more accurate name).
Parameters:
Name Type Description
type function | String Type reference (constructor or `constructor.name`).
x * Value to check.
Returns:
Boolean

static isLooselyOneOf(x, …types) → {boolean}

Checks if given value is either strictly one of given types or is an `instanceof` one of given types.
Parameters:
Name Type Attributes Description
x *
types TypeRef <repeatable>
Returns:
boolean

static isMap(value) → {Boolean}

Checks whether value is of `Map` or not.
Parameters:
Name Type Description
value *
Returns:
Boolean

static isNull(value) → {Boolean}

Checks if value is null.
Parameters:
Name Type Description
value *
Returns:
Boolean

static isNumber(value) → {Boolean}

Checks if value is a valid number (also checks if isNaN so that you don't have to).
Parameters:
Name Type Description
value *
Returns:
Boolean

static isObject(value) → {Boolean}

Checks whether value is an object or not.
Parameters:
Name Type Description
value
Returns:
Boolean

static isOfType(type, x) → {Boolean}

Loose type checker; E.g., If `type` is not a constructor, but a constructor name, does a type check on constructor names, else if first check fails and `type` is a constructor, performs an `instanceof` check on value with constructor.
Parameters:
Name Type Description
type function | String Type reference (constructor or `constructor.name`).
x * Value to check.
Returns:
Boolean
Example
isOfType(Number, 99) === true        // true  (passes strict type check (numbers are not instances of `Number`
                                     //        constructor)
isOfType('Number', 99) === true      // true  (passes strict type check)
isOfType(Number, NaN) === true       // true. (passes instance of check)
                                     //        If you want "true" strict type checking use `isType`
isOfType(Object, []) === true        // true  (passes instance of check)
isOfType(Array, []) === true         // true  (passes instance of check)
isOfType(Object, {}) === true        // true  (passes instance of check)
isOfType(Object.name, {}) === true   // true  (Passes strict type check)
class Abc extends String {}
isOfType(String, new Abc('abcd')) // true (passes instanceof check)

static isSet(value) → {Boolean}

Checks whether value is of `Set` or not.
Parameters:
Name Type Description
value *
Returns:
Boolean

static isset(x) → {Boolean}

Returns whether passed in values is defined and not null or not.
Parameters:
Name Type Description
x *
Returns:
Boolean

static isStrictly(type, obj) → {Boolean}

Synonym for `isType` (or just a more accurate name for `isType`).
Parameters:
Name Type Description
type function | ObjectConstructor | String Constructor or constructor name
obj *
Returns:
Boolean

static isStrictlyOneOf(x, …types) → {boolean}

Checks if given value is strictly one of given types.
Parameters:
Name Type Attributes Description
x *
types TypeRef <repeatable>
Returns:
boolean

static isString(value) → {Boolean}

Checks whether value is a string or not.
Parameters:
Name Type Description
value *
Returns:
Boolean

static isSymbol(value) → {Boolean}

Checks if value is a `Symbol`.
Parameters:
Name Type Description
value *
Returns:
Boolean

static isType(type, obj) → {Boolean}

Strict type checker. Checks if given value is a direct instance of given type; E.g.,
Parameters:
Name Type Description
type function | ObjectConstructor | String Constructor or constructor name
obj *
Returns:
Boolean
Example
isType(String, 'abcdefg')  === true // true
  isType(String.name, 'abcdefg') === true
  isType(Number, NaN) === false
  isType(Number, 99) === true
  isType('Null', 99) === false // though, for `null` and `undefined` checks
                               // @see `isset`, in this module, instead
  isType('Undefined', undefined) === true // true

static isUndefined(value) → {Boolean}

Checks if value is undefined.
Parameters:
Name Type Description
value *
Returns:
Boolean

static isUsableImmutablePrimitive(x) → {Boolean}

Checks if given `x` is set and of one of [String, Boolean, Number, Symbol] (null and undefined are immutable but are not "usable" (usually not what we want to operate on).
Parameters:
Name Type Description
x *
Returns:
Boolean

static isWeakMap(value) → {Boolean}

Checks whether value is of `WeakMap` or not.
Parameters:
Name Type Description
value *
Returns:
Boolean

static isWeakSet(value) → {Boolean}

Checks whether value is of `WeakSet` or not.
Parameters:
Name Type Description
value *
Returns:
Boolean

static jsonClone(x) → {*}

Clones and object or array using `JSON.parse(JSON.stringify(...))` pattern.
Parameters:
Name Type Description
x *
Returns:
*

static keys(obj) → {Array.<String>}

Gets passed in object's own enumerable keys (same as `Object.keys`).
Parameters:
Name Type Description
obj *
Returns:
Array.<String>

static length(x) → {Number}

Parameters:
Name Type Description
x *
Throws:
- Throws an error if value doesn't have a `length` property ( `null`, `undefined`, {Boolean}, Symbol, et. al.).
Type
Error
Returns:
Number

static lookup(key, obj) → {*}

Looks up property and returns it's value; Else `undefined`. Method is null safe (will not throw on `null` or `undefined`).
Parameters:
Name Type Description
key String Key to search on `obj`
obj Object Object to search `name` on.
Returns:
*

static of(x, …argsopt) → {*|undefined}

Creates a value `of` given type; Checks for one of the following construction strategies (in order listed):
Parameters:
Name Type Attributes Description
x * Value to derive returned value's type from.
args * <optional>
<repeatable>
Any args to pass in to matched construction strategy.
Returns:
* | undefined - - New value of given value's type else `undefined`.
Example
// - If exists `(value).constructor.of` uses this.
// - If value is of one String, Boolean, Symbol, or Number types calls it's
//      constructor as a function (in cast form;  E.g., `constructor(...args)` )
// - Else if constructor is a function, thus far, then calls constructor using
//      the `new` keyword (with any passed in args).

static searchObj(nsString, obj) → {*}

Gives you value at key/namespace-key within `obj`; E.g., searchObj('all.your.base', {all: {your: {base: 99}}}) === 99 // `true`
Parameters:
Name Type Description
nsString String
obj *
Returns:
*
Example
```
if (obj && obj.all && obj.all.your && obj.all.your.base) {
  // Thing we want to do
}

// So with our function becomes
if (searchObj('all.your.base', obj)) {
  // Thing we want to do
}
```

static toArray(x) → {Array}

Converts incoming value to an array.
Parameters:
Name Type Description
x * Thing to convert from.
Returns:
Array

static toAssocList(obj) → {Array.<*, *>}

Returns an associated list from given object.
Parameters:
Name Type Description
obj Object | Array | *
Returns:
Array.<*, *>

static toAssocListDeep(obj, TypeConstraintopt) → {*}

Returns an associated list from given object (deeply (on incoming object's type)).
Parameters:
Name Type Attributes Default Description
obj *
TypeConstraint Constructor | function <optional>
Object Type constraint to convert on.
Returns:
*

static toEnumerableDescriptor() → {TargetDescriptorTuple}

Returns a target-descriptor tuple whose 'descriptor' will be set to enumerable (`enumerable: true`).
Parameters:
Type Description
TargetDescriptorTuple [target, descriptor] tuple.
Returns:
TargetDescriptorTuple - - Array of target and descriptor.

static toTargetDescriptorTuple(targetOrTargetDescriptorTuple) → {Array.<*>|Array.<*, *>}

Returns an target and descriptor tuple from given.
Parameters:
Name Type Description
targetOrTargetDescriptorTuple * | Array.<*, *> Target object or tuple of target and descriptor.
Returns:
Array.<*> | Array.<*, *>

static toTypeRef(type) → {String}

Resolves/normalizes a type name from either a string or a constructor.
Parameters:
Name Type Description
type function | String String or function representing a type.
Returns:
String
To Do:
  • write tests for this function.

static toTypeRefName(Type) → {String}

Returns possible Type's TypeRef name.
Parameters:
Name Type Description
Type TypeRef | *
Returns:
String
To Do:
  • Ensure tests are written for this function.

static toTypeRefNames(…types) → {Array.<String>}

Returns possible Types' TypeRef names.
Parameters:
Name Type Attributes Description
types TypeRef | * <repeatable>
Returns:
Array.<String>
To Do:
  • Ensure tests are written for this function.

static toTypeRefs(…types) → {Array.<TypeRef>}

Returns an array of type refs from possible type refs (converts null, undefined, NaN, and other values into type refs (either constructor name or constructor name based on whether value(s) is a string, a constructor, or not).
Parameters:
Name Type Attributes Description
types TypeRef | * <repeatable>
Returns:
Array.<TypeRef>
To Do:
  • Ensure tests are written for this function.

static typeOf(value) → {string}

Returns the constructor/class/type name of a value.
Parameters:
Name Type Description
value *
Returns:
string - - Constructor's name or derived name (in the case of `null`, `undefined`, or `NaN` (whose normalized names are 'Null', 'Undefined', 'NaN' respectively).

object

Members

static, constant native :Object

Contains all the static functions from `Object` but curried and flipped;
Example
// E.g., `Object.defineProperties(obj, descriptor)` can now be used like
import {defineProperties} from 'fjl'
defineProperties(descriptor, someObj),
// Et. al.

Methods

static assign(obj0, …objs) → {Object}

Defined as `Object.assign` else is the same thing but shimmed.
Parameters:
Name Type Attributes Description
obj0 Object
objs Object <repeatable>
Returns:
Object

static assignDeep(obj0, …objsopt) → {Object}

Merges all objects down into one (takes two or more args).
Parameters:
Name Type Attributes Description
obj0 Object
objs Object <optional>
<repeatable>
One or more objects to merge onto `obj0`.
Returns:
Object

static copy(x, outopt) → {*}

Make a copy of a value or optionally copy incoming value onto an outgoing value (second parameter).
Parameters:
Name Type Attributes Description
x * Thing to copy.
out * <optional>
Optional value to copy on to. Not required.
Returns:
* - - Copied thing or optionally outgoing value copied onto.

static createTypedDescriptor(Type, target, propName) → {Descriptor}

Creates a descriptor for a property which is settable but throws errors when the `Type` is disobeyed.
Parameters:
Name Type Description
Type TypeRef {String|Function}
target *
propName String
Returns:
Descriptor - - Property descriptor with just getter and setter.

static defineEnumProp(Type, target, propName, defaultValueopt) → {TargetDescriptorTuple}

Allows you to define a "typed", enumerated property on `target`.
Parameters:
Name Type Attributes Description
Type TypeRef {String|Function}
target TargetDescriptorTuple Target or array of target and descriptor ([target, descriptor]).
propName String
defaultValue * <optional>

static defineEnumProps(argsTuple, targetopt) → {Array.<TargetDescriptorTuple>}

Allows you to define multiple enum props at once on target.
Parameters:
Name Type Attributes Description
argsTuple Array.<DefinePropArgsTuple> Array of argArrays for `defineEnumProp`.
target Target <optional>
Target to use in internal calls if one is not provided but encountered 'argArray'.
Returns:
Array.<TargetDescriptorTuple> - - Results of each call to `defineEnumProp`.

static defineProp(Type, target, propName, defaultValueopt) → {TargetDescriptorTuple}

Allows you to define a "typed" property on given `target`.
Parameters:
Name Type Attributes Description
Type TypeRef {String|Function}
target TargetDescriptorTuple Target or array of target and descriptor ([target, descriptor]).
propName String
defaultValue * <optional>

static defineProps(argsTuple, targetopt) → {Array.<TargetDescriptorTuple>}

Allows you to define multiple props at once on target.
Parameters:
Name Type Attributes Description
argsTuple Array.<DefinePropArgsTuple> Array of argArrays for `defineProp`.
target Target <optional>
Target to use in internal calls if one is not provided but encountered 'argArray'.
Returns:
Array.<TargetDescriptorTuple> - - Results of each call to `defineProp`.

static fromAssocList(xs, OutTypeopt) → {*}

From associated list to object.
Parameters:
Name Type Attributes Default Description
xs Array.<Array> Associated list.
OutType Constructor | function <optional>
Object Output type. Default `Object`.
Returns:
* - - Default is `Object`

static fromAssocListDeep(xs, OutTypeopt) → {*}

From associated list to object (deep conversion on associative lists (array of 2 value arrays)).
Parameters:
Name Type Attributes Default Description
xs Array.<Array> Associated list.
OutType Constructor | function <optional>
Object Output type. Default `Object`.
Returns:
* - - Default is `Object`

static hasOwnProperty(propName, typeInstance) → {Boolean}

Parameters:
Name Type Description
propName *
typeInstance *
Returns:
Boolean
Deprecated:
  • - Use property directly instead.

static instanceOf(instanceConstructor, instance) → {Boolean}

Returns whether constructor has derived object.
Parameters:
Name Type Description
instanceConstructor function Constructor.
instance *
Returns:
Boolean

static instanceOfOne(x, …types) → {boolean}

Checks if given value is instance of one of the types given.
Parameters:
Name Type Attributes Description
x *
types TypeRef <repeatable>
Returns:
boolean

static isArray(value) → {boolean}

Checks if value is an array (same as `Array.isArray`).
Parameters:
Name Type Description
value *
Returns:
boolean

static isBoolean(value) → {Boolean}

Checks if value is a boolean.
Parameters:
Name Type Description
value *
Returns:
Boolean

static isCallable(x) → {Boolean}

Returns a boolean depicting whether a value is callable or not.
Parameters:
Name Type Description
x *
Returns:
Boolean

static isClass(x) → {boolean}

Checks if `value` is an es2015 `class`.
Parameters:
Name Type Description
x *
Returns:
boolean

static isEmpty(x) → {Boolean}

Checks to see if passed in value is empty; I.e., check for one of '', 0, `null`, `undefined`, `NaN`, `false`, empty array, empty object, ~~empty function (zero arity)~~, or empty collection (es6 collection: Map, Set, WeakMap, or WeakSet etc.) (`!value.size`).
Parameters:
Name Type Description
x * Value to check.
Returns:
Boolean

static isEmptyCollection(x) → {Boolean}

Checks if collection is empty or not (Map, WeakMap, WeakSet, Set etc.).
Parameters:
Name Type Description
x *
Returns:
Boolean

static isEmptyList(x) → {Boolean}

Checks if !length.
Parameters:
Name Type Description
x *
Returns:
Boolean

static isEmptyObject(obj) → {Boolean}

Checks if object has own properties/enumerable-props or not.
Parameters:
Name Type Description
obj *
Returns:
Boolean

static isFunction(value) → {Boolean}

Returns whether a value is a function or not.
Parameters:
Name Type Description
value *
Returns:
Boolean

static isFunctor(x) → {bool}

Checks if value qualifies (has `map` method) as a functor.
Parameters:
Name Type Description
x *
Returns:
bool

static isLoosely(type, x) → {Boolean}

Synonym for `isOfType` (or just a more accurate name).
Parameters:
Name Type Description
type function | String Type reference (constructor or `constructor.name`).
x * Value to check.
Returns:
Boolean

static isLooselyOneOf(x, …types) → {boolean}

Checks if given value is either strictly one of given types or is an `instanceof` one of given types.
Parameters:
Name Type Attributes Description
x *
types TypeRef <repeatable>
Returns:
boolean

static isMap(value) → {Boolean}

Checks whether value is of `Map` or not.
Parameters:
Name Type Description
value *
Returns:
Boolean

static isNull(value) → {Boolean}

Checks if value is null.
Parameters:
Name Type Description
value *
Returns:
Boolean

static isNumber(value) → {Boolean}

Checks if value is a valid number (also checks if isNaN so that you don't have to).
Parameters:
Name Type Description
value *
Returns:
Boolean

static isObject(value) → {Boolean}

Checks whether value is an object or not.
Parameters:
Name Type Description
value
Returns:
Boolean

static isOfType(type, x) → {Boolean}

Loose type checker; E.g., If `type` is not a constructor, but a constructor name, does a type check on constructor names, else if first check fails and `type` is a constructor, performs an `instanceof` check on value with constructor.
Parameters:
Name Type Description
type function | String Type reference (constructor or `constructor.name`).
x * Value to check.
Returns:
Boolean
Example
isOfType(Number, 99) === true        // true  (passes strict type check (numbers are not instances of `Number`
                                     //        constructor)
isOfType('Number', 99) === true      // true  (passes strict type check)
isOfType(Number, NaN) === true       // true. (passes instance of check)
                                     //        If you want "true" strict type checking use `isType`
isOfType(Object, []) === true        // true  (passes instance of check)
isOfType(Array, []) === true         // true  (passes instance of check)
isOfType(Object, {}) === true        // true  (passes instance of check)
isOfType(Object.name, {}) === true   // true  (Passes strict type check)
class Abc extends String {}
isOfType(String, new Abc('abcd')) // true (passes instanceof check)

static isSet(value) → {Boolean}

Checks whether value is of `Set` or not.
Parameters:
Name Type Description
value *
Returns:
Boolean

static isset(x) → {Boolean}

Returns whether passed in values is defined and not null or not.
Parameters:
Name Type Description
x *
Returns:
Boolean

static isStrictly(type, obj) → {Boolean}

Synonym for `isType` (or just a more accurate name for `isType`).
Parameters:
Name Type Description
type function | ObjectConstructor | String Constructor or constructor name
obj *
Returns:
Boolean

static isStrictlyOneOf(x, …types) → {boolean}

Checks if given value is strictly one of given types.
Parameters:
Name Type Attributes Description
x *
types TypeRef <repeatable>
Returns:
boolean

static isString(value) → {Boolean}

Checks whether value is a string or not.
Parameters:
Name Type Description
value *
Returns:
Boolean

static isSymbol(value) → {Boolean}

Checks if value is a `Symbol`.
Parameters:
Name Type Description
value *
Returns:
Boolean

static isType(type, obj) → {Boolean}

Strict type checker. Checks if given value is a direct instance of given type; E.g.,
Parameters:
Name Type Description
type function | ObjectConstructor | String Constructor or constructor name
obj *
Returns:
Boolean
Example
isType(String, 'abcdefg')  === true // true
  isType(String.name, 'abcdefg') === true
  isType(Number, NaN) === false
  isType(Number, 99) === true
  isType('Null', 99) === false // though, for `null` and `undefined` checks
                               // @see `isset`, in this module, instead
  isType('Undefined', undefined) === true // true

static isUndefined(value) → {Boolean}

Checks if value is undefined.
Parameters:
Name Type Description
value *
Returns:
Boolean

static isUsableImmutablePrimitive(x) → {Boolean}

Checks if given `x` is set and of one of [String, Boolean, Number, Symbol] (null and undefined are immutable but are not "usable" (usually not what we want to operate on).
Parameters:
Name Type Description
x *
Returns:
Boolean

static isWeakMap(value) → {Boolean}

Checks whether value is of `WeakMap` or not.
Parameters:
Name Type Description
value *
Returns:
Boolean

static isWeakSet(value) → {Boolean}

Checks whether value is of `WeakSet` or not.
Parameters:
Name Type Description
value *
Returns:
Boolean

static jsonClone(x) → {*}

Clones and object or array using `JSON.parse(JSON.stringify(...))` pattern.
Parameters:
Name Type Description
x *
Returns:
*

static keys(obj) → {Array.<String>}

Gets passed in object's own enumerable keys (same as `Object.keys`).
Parameters:
Name Type Description
obj *
Returns:
Array.<String>

static length(x) → {Number}

Parameters:
Name Type Description
x *
Throws:
- Throws an error if value doesn't have a `length` property ( `null`, `undefined`, {Boolean}, Symbol, et. al.).
Type
Error
Returns:
Number

static lookup(key, obj) → {*}

Looks up property and returns it's value; Else `undefined`. Method is null safe (will not throw on `null` or `undefined`).
Parameters:
Name Type Description
key String Key to search on `obj`
obj Object Object to search `name` on.
Returns:
*

static of(x, …argsopt) → {*|undefined}

Creates a value `of` given type; Checks for one of the following construction strategies (in order listed):
Parameters:
Name Type Attributes Description
x * Value to derive returned value's type from.
args * <optional>
<repeatable>
Any args to pass in to matched construction strategy.
Returns:
* | undefined - - New value of given value's type else `undefined`.
Example
// - If exists `(value).constructor.of` uses this.
// - If value is of one String, Boolean, Symbol, or Number types calls it's
//      constructor as a function (in cast form;  E.g., `constructor(...args)` )
// - Else if constructor is a function, thus far, then calls constructor using
//      the `new` keyword (with any passed in args).

static searchObj(nsString, obj) → {*}

Gives you value at key/namespace-key within `obj`; E.g., searchObj('all.your.base', {all: {your: {base: 99}}}) === 99 // `true`
Parameters:
Name Type Description
nsString String
obj *
Returns:
*
Example
```
if (obj && obj.all && obj.all.your && obj.all.your.base) {
  // Thing we want to do
}

// So with our function becomes
if (searchObj('all.your.base', obj)) {
  // Thing we want to do
}
```

static toArray(x) → {Array}

Converts incoming value to an array.
Parameters:
Name Type Description
x * Thing to convert from.
Returns:
Array

static toAssocList(obj) → {Array.<*, *>}

Returns an associated list from given object.
Parameters:
Name Type Description
obj Object | Array | *
Returns:
Array.<*, *>

static toAssocListDeep(obj, TypeConstraintopt) → {*}

Returns an associated list from given object (deeply (on incoming object's type)).
Parameters:
Name Type Attributes Default Description
obj *
TypeConstraint Constructor | function <optional>
Object Type constraint to convert on.
Returns:
*

static toEnumerableDescriptor() → {TargetDescriptorTuple}

Returns a target-descriptor tuple whose 'descriptor' will be set to enumerable (`enumerable: true`).
Parameters:
Type Description
TargetDescriptorTuple [target, descriptor] tuple.
Returns:
TargetDescriptorTuple - - Array of target and descriptor.

static toTargetDescriptorTuple(targetOrTargetDescriptorTuple) → {Array.<*>|Array.<*, *>}

Returns an target and descriptor tuple from given.
Parameters:
Name Type Description
targetOrTargetDescriptorTuple * | Array.<*, *> Target object or tuple of target and descriptor.
Returns:
Array.<*> | Array.<*, *>

static toTypeRef(type) → {String}

Resolves/normalizes a type name from either a string or a constructor.
Parameters:
Name Type Description
type function | String String or function representing a type.
Returns:
String
To Do:
  • write tests for this function.

static toTypeRefName(Type) → {String}

Returns possible Type's TypeRef name.
Parameters:
Name Type Description
Type TypeRef | *
Returns:
String
To Do:
  • Ensure tests are written for this function.

static toTypeRefNames(…types) → {Array.<String>}

Returns possible Types' TypeRef names.
Parameters:
Name Type Attributes Description
types TypeRef | * <repeatable>
Returns:
Array.<String>
To Do:
  • Ensure tests are written for this function.

static toTypeRefs(…types) → {Array.<TypeRef>}

Returns an array of type refs from possible type refs (converts null, undefined, NaN, and other values into type refs (either constructor name or constructor name based on whether value(s) is a string, a constructor, or not).
Parameters:
Name Type Attributes Description
types TypeRef | * <repeatable>
Returns:
Array.<TypeRef>
To Do:
  • Ensure tests are written for this function.

static typeOf(value) → {string}

Returns the constructor/class/type name of a value.
Parameters:
Name Type Description
value *
Returns:
string - - Constructor's name or derived name (in the case of `null`, `undefined`, or `NaN` (whose normalized names are 'Null', 'Undefined', 'NaN' respectively).