Skip to content

Object

Convention: refers to the type of the properties in the being processed by a function.

prop()

Fetches a property from an object.

  • Type
Overload 1
Overload 2
  • Details

Fetches a property or a nested property using either a single property name or an array representing a path.

  • Example
js
// Overload 1
prop('homo', { homo: 114514 }); // 114514
// Overload 2
prop(['inside', 'homo'], { inside: { homo: 114514 } }); // 114514
// Overload 1
prop('homo', { homo: 114514 }); // 114514
// Overload 2
prop(['inside', 'homo'], { inside: { homo: 114514 } }); // 114514

assoc()

Modifies a property in an object without mutating the original object.

  • Type
Overload 1
Overload 2
  • Details

Associates a new value to a property or a nested property in the object, returning a new object.

  • Example
js
// Overload 1
assoc('homo', 'yeah', { homo: 114514 }); // { "homo": "yeah" }
// Overload 2
assoc(['inside', 'homo'], 'yeah', { inside: { homo: 114514 } }); // { "inside": { "homo": "yeah" } }
// Overload 1
assoc('homo', 'yeah', { homo: 114514 }); // { "homo": "yeah" }
// Overload 2
assoc(['inside', 'homo'], 'yeah', { inside: { homo: 114514 } }); // { "inside": { "homo": "yeah" } }

modify()

Applies a function to a property in an object.

  • Type
Overload 1
Overload 2
  • Details

Modifies a property or a nested property in an object by applying a function to it.

  • Example
js
// Overload 1
modify('homo', (v) => 'yeah', { homo: 114514 }); // { "homo": "yeah" }
// Overload 2
modify(['inside', 'homo'], (v) => 'yeah', { inside: { homo: 114514 } }); // { "inside": { "homo": "yeah" } }
// Overload 1
modify('homo', (v) => 'yeah', { homo: 114514 }); // { "homo": "yeah" }
// Overload 2
modify(['inside', 'homo'], (v) => 'yeah', { inside: { homo: 114514 } }); // { "inside": { "homo": "yeah" } }

dissoc()

Removes a property from an object.

  • Type
Overload 1
Overload 2
  • Details

Deletes a property or a nested property from an object and returns the modified object.

  • Example
js
// Overload 1
dissoc('homo', { homo: 114514 }); // {}
// Overload 2
dissoc(['inside', 'homo'], { inside: { homo: 114514 } }); // { "inside": {} }
// Overload 1
dissoc('homo', { homo: 114514 }); // {}
// Overload 2
dissoc(['inside', 'homo'], { inside: { homo: 114514 } }); // { "inside": {} }

deepClone()

Creates a deep clone of an object.

  • Type
  • Details

Returns a deep clone of the given object.

  • Example
js
deepClone({ a: 1, b: 2, c: 3 }); // { a: 1, b: 2, c: 3 }
deepClone({ a: 1, b: 2, c: 3 }); // { a: 1, b: 2, c: 3 }

keys()

Fetches all the keys of an object.

  • Type
  • Details

Returns an array of all the keys of the given object.

  • Example
js
keys({ a: 1, b: 2, c: 3 }); // ['a', 'b', 'c']
keys({ a: 1, b: 2, c: 3 }); // ['a', 'b', 'c']

values()

Fetches all the values of an object.

  • Type
  • Details

Returns an array of all the values of the given object.

  • Example
js
values

({ a: 1, b: 2, c: 3 }); // [1, 2, 3]
values

({ a: 1, b: 2, c: 3 }); // [1, 2, 3]

makePair()

Converts an array of tuples into an object.

  • Type
  • Details

Transforms an array of tuples into an object where the first element of each tuple is a key, and the second element is the corresponding value.

  • Example
js
makePair([
  ['c', 'm'],
  ['a', 'e'],
  ['i', 'o']
]); // { c: "m", a: "e", i: "o" }
makePair([
  ['c', 'm'],
  ['a', 'e'],
  ['i', 'o']
]); // { c: "m", a: "e", i: "o" }

construct()

Curries a class constructor.

  • Type
  • Details

Accepts a class and returns a curried constructor function.

  • Example
js
class foo {
  constructor(a, b, c) {
    //do something...
  }
}
construct(foo)(1)(2)(3);
class foo {
  constructor(a, b, c) {
    //do something...
  }
}
construct(foo)(1)(2)(3);

has()

Checks if a property exists in an object.

  • Type
  • Details

Checks if a property exists in an object and returns true if it does, otherwise returns false.

  • Example
js
has('homo')({ homo: 1 }); // true
has('homo')({ homo: 1 }); // true

PureEval released under the GPL-3.0 License.