Ƭ T: object
A type alias for object
Since
4.0.0
Ƭ Entries<O>: { [k in keyof O]: [k, O[k]] }[keyof O][]
Represents the entries of an object O as an array of key/value pair tuples
Since
4.0.0
| Name | Description |
|---|---|
O |
the object |
Ƭ GuardsFromStruct<S>: { [key in keyof S]: S[key] extends T<infer A> ? Guardable<T<A>> | GuardsFromStruct<S[key]> : Guardable<S[key]> | GuardsFromStruct<S[key]> }
Represents the resulting type from a struct of guards
Since
4.0.0
| Name | Description |
|---|---|
S |
the guard represented as a struct (or shape) |
Ƭ KeysOf<O>: keyof O[]
Extracts keys K[] from object O
Since
4.0.0
| Name | Type | Description |
|---|---|---|
O |
extends object |
the object |
Ƭ ValuesOf<O>: O[keyof O][]
Extracts values A[] from object O
Since
4.0.0
| Name | Type | Description |
|---|---|---|
O |
extends object |
the object |
▸ guard(x): x is object
Returns true if x is of type object and not null
Example
import { Obj } from 'tiinvo';
Obj.guard({}); // true
Obj.guard(null); // false
Since
4.0.0
| Name | Type | Description |
|---|---|---|
x |
unknown |
the object |
x is object
▸ guardOf<A>(s): (v: unknown) => v is A
Returns a guard which checks if a value v implements a shape s
Example
import { Obj, Str, Num, Bool } from 'tiinvo';
const isABC = Obj.guardOf({
a: Str.guard,
b: Num.guard,
c: Bool.guard
});
isABC({ a: `foo`, b: 1, c: true }); // true
isABC({ a: `foo`, b: false, c: 1 }); // false
// you can also set recursive shapes, or directly more comples ones
const isUser = Obj.guardOf({
name: Str.guard,
surname: Str.guard,
age: Num.guard,
billing: {
address: Str.guard,
city: Str.guard,
}
})
isUser(10) // false
isUser({}) // false
isUser({
name: 'john',
surname: 'doe',
age: 44,
}) // false
isUser({
name: 'john',
surname: 'doe',
age: 44,
billing: {
}
}) // false
isUser({
name: 'john',
surname: 'doe',
age: 44,
billing: {
address: '',
}
}) // false
isUser({
name: 'john',
surname: 'doe',
age: 44,
billing: {
address: 'some address',
city: 'some city',
}
}) // true
Since
4.0.0
| Name | Type | Description |
|---|---|---|
A |
extends unknown |
the guard structure |
| Name | Type | Description |
|---|---|---|
s |
GuardsFromStruct<A> |
the struct which represents the guarded type |
fn
the Guardable<A> if s is an object, otherwise it throws a TypeError
▸ (v): v is A
| Name | Type |
|---|---|
v |
unknown |
v is A
▸ hasKey<K>(k, o): o is Record<K, unknown>
Returns true if a is a object and has property k
Example
import { Obj } from 'tiinvo';
Obj.hasKey('a', {}); // false
Obj.hasKey('a', { a: 1 }); // true
const hasa = Obj.hasKey('a');
hasa({}); // false
hasa({ a: 1 }); // true
Since
4.0.0
| Name | Type | Description |
|---|---|---|
K |
extends string |
the key type |
| Name | Type | Description |
|---|---|---|
k |
K |
the key |
o |
unknown |
- |
o is Record<K, unknown>
o is an object and has a key K▸ hasKey<K>(k): (o: unknown) => o is Record<K, unknown>
Returns a guard which checks if a is a object and has property k
Example
import { Obj } from 'tiinvo';
const hasa = Obj.hasKey('a');
hasa({}); // false
hasa({ a: 1 }); // true
Since
4.0.0
| Name | Type | Description |
|---|---|---|
K |
extends string |
the key type |
| Name | Type | Description |
|---|---|---|
k |
K |
the key |
fn
the unary function which checks if o is an object and has the key K
▸ (o): o is Record<K, unknown>
| Name | Type |
|---|---|
o |
unknown |
o is Record<K, unknown>
▸ hasKeyOf<A, K>(k, g, o): o is Record<K, A>
Returns true if o is an object and has property K of type A
Example
import { Obj, Num } from 'tiinvo';
Obj.hasKeyOf('a', Num.guard, {}) // false
Obj.hasKeyOf('a', Num.guard, { a: 1 }) // true
Obj.hasKeyOf('a', Num.guard, { a: `nope` }) // false
Since
4.0.0
| Name | Type | Description |
|---|---|---|
A |
A |
the value type |
K |
extends string |
the key type |
| Name | Type | Description |
|---|---|---|
k |
K |
the key |
g |
Guardable<A> |
the guard to check if o[K] is of it’s type |
o |
unknown |
the value to check |
o is Record<K, A>
true if o is an object, has a key K and o[K] is of type Afalse otherwise▸ hasKeyOf<A, K>(k, g): (o: unknown) => o is Record<K, A>
Returns a guard which checks if o is an object and has property K of type A
Example
import { Obj, Num } from 'tiinvo';
const hasa = Obj.hasKeyOf('a', Num.guard);
hasa({}) // false
hasa({ a: 1 }) // true
hasa({ a: `nope` }) // false
Since
4.0.0
| Name | Type | Description |
|---|---|---|
A |
A |
the value type |
K |
extends string |
the key type |
| Name | Type | Description |
|---|---|---|
k |
K |
the key |
g |
Guardable<A> |
the guard to check if o[K] is of it’s type |
fn
▸ (o): o is Record<K, A>
| Name | Type |
|---|---|
o |
unknown |
o is Record<K, A>
▸ assign<T, U>(target, source): T & U
Copy the values of all of the enumerable own properties from one or more source objects to a new object.
important: This will not mutate any object, it will always return a new one instead.
Example
import { Obj } from 'tiinvo';
const a = { a: 1, b: 2 };
const b = { b: 3, c: 4 };
const c = { c: 5, d: 6 };
Obj.assign(a, b, c);
// { a: 1, b: 3, c: 5, d: 6 }
Since
4.0.0
| Name | Type |
|---|---|
T |
extends Object |
U |
U |
| Name | Type |
|---|---|
target |
T |
source |
U |
T & U
The target object
node_modules/typescript/lib/lib.es2015.core.d.ts:286
▸ assign<T, U, V>(target, source1, source2): T & U & V
Copy the values of all of the enumerable own properties from one or more source objects to a new object.
important: This will not mutate any object, it will always return a new one instead.
Example
import { Obj } from 'tiinvo';
const a = { a: 1, b: 2 };
const b = { b: 3, c: 4 };
const c = { c: 5, d: 6 };
Obj.assign(a, b, c);
// { a: 1, b: 3, c: 5, d: 6 }
Since
4.0.0
| Name | Type |
|---|---|
T |
extends Object |
U |
U |
V |
V |
| Name | Type |
|---|---|
target |
T |
source1 |
U |
source2 |
V |
T & U & V
The target object
node_modules/typescript/lib/lib.es2015.core.d.ts:295
▸ assign<T, U, V, W>(target, source1, source2, source3): T & U & V & W
Copy the values of all of the enumerable own properties from one or more source objects to a new object.
important: This will not mutate any object, it will always return a new one instead.
Example
import { Obj } from 'tiinvo';
const a = { a: 1, b: 2 };
const b = { b: 3, c: 4 };
const c = { c: 5, d: 6 };
Obj.assign(a, b, c);
// { a: 1, b: 3, c: 5, d: 6 }
Since
4.0.0
| Name | Type |
|---|---|
T |
extends Object |
U |
U |
V |
V |
W |
W |
| Name | Type |
|---|---|
target |
T |
source1 |
U |
source2 |
V |
source3 |
W |
T & U & V & W
The target object
node_modules/typescript/lib/lib.es2015.core.d.ts:305
▸ assign(target, ...sources): any
Copy the values of all of the enumerable own properties from one or more source objects to a new object.
important: This will not mutate any object, it will always return a new one instead.
Example
import { Obj } from 'tiinvo';
const a = { a: 1, b: 2 };
const b = { b: 3, c: 4 };
const c = { c: 5, d: 6 };
Obj.assign(a, b, c);
// { a: 1, b: 3, c: 5, d: 6 }
Since
4.0.0
| Name | Type |
|---|---|
target |
object |
...sources |
any[] |
any
The target object
node_modules/typescript/lib/lib.es2015.core.d.ts:313
▸ entries<O>(o): Entries<O>
Returns an array of key/values of the enumerable properties of an object o
Example
import { Obj } from 'tiinvo';
Obj.entries({ a: 1, b: 2 }); // [ ['a', 1], ['b', 2] ]
Since
4.0.0
| Name | Type | Description |
|---|---|---|
O |
extends object |
the object’s type |
| Name | Type | Description |
|---|---|---|
o |
O |
the object |
Entries<O>
the entries
▸ freeze<T>(f): T
Prevents the modification of existing property attributes and values, and prevents the addition of new properties.
Example
import { Obj } from 'tiinvo';
const a = { a: 1, b: 2 };
Obj.freeze(a);
a.a = 100; // throws
Since
4.0.0
| Name | Type |
|---|---|
T |
extends Function |
| Name | Type |
|---|---|
f |
T |
T
node_modules/typescript/lib/lib.es5.d.ts:221
▸ freeze<T, U>(o): Readonly<T>
Prevents the modification of existing property attributes and values, and prevents the addition of new properties.
Example
import { Obj } from 'tiinvo';
const a = { a: 1, b: 2 };
Obj.freeze(a);
a.a = 100; // throws
Since
4.0.0
| Name | Type |
|---|---|
T |
extends Object |
U |
extends string | number | bigint | boolean | symbol |
| Name | Type |
|---|---|
o |
T |
Readonly<T>
node_modules/typescript/lib/lib.es5.d.ts:227
▸ freeze<T>(o): Readonly<T>
Prevents the modification of existing property attributes and values, and prevents the addition of new properties.
Example
import { Obj } from 'tiinvo';
const a = { a: 1, b: 2 };
Obj.freeze(a);
a.a = 100; // throws
Since
4.0.0
| Name |
|---|
T |
| Name | Type |
|---|---|
o |
T |
Readonly<T>
node_modules/typescript/lib/lib.es5.d.ts:233
▸ fromEntries<T>(entries): Object
Returns an object created by key-value entries for properties and methods
Example
import { Obj } from 'tiinvo';
Obj.fromEntries([ ['a', 1], ['b', 2] ]) // { a: 1, b: 2 }
Since
4.0.0
| Name | Type |
|---|---|
T |
any |
| Name | Type | Description |
|---|---|---|
entries |
Iterable<readonly [PropertyKey, T]> |
the entries |
Object
node_modules/typescript/lib/lib.es2019.object.d.ts:28
▸ fromEntries(entries): any
Returns an object created by key-value entries for properties and methods
Example
import { Obj } from 'tiinvo';
Obj.fromEntries([ ['a', 1], ['b', 2] ]) // { a: 1, b: 2 }
Since
4.0.0
| Name | Type | Description |
|---|---|---|
entries |
Iterable<readonly any[]> |
the entries |
any
node_modules/typescript/lib/lib.es2019.object.d.ts:34
▸ get<a>(a): <b>(b: b) => T<b extends Record<a, u> ? u : null>
Gets a property a from an object b and returns a Option.t<c>
Example
import { Obj } from 'tiinvo';
const get = Obj.get(`foo`);
get({ foo: `bar` }); // some<`bar`>
get({}); // none
Since
4.0.0
| Name | Type |
|---|---|
a |
extends string |
| Name | Type | Description |
|---|---|---|
a |
a |
the property to get |
fn
▸ <b>(b): T<b extends Record<a, u> ? u : null>
| Name |
|---|
b |
| Name | Type |
|---|---|
b |
b |
T<b extends Record<a, u> ? u : null>
▸ omit<K, O>(k, o): Exclude<O, K>
Omits the keys in A that are in O
Example
import { Obj } from 'tiinvo';
Obj.omit(['a', 'b'], { a: 10, b: 20, c: 30 }) // { c: 30 }
Since
4.0.0
| Name | Type | Description |
|---|---|---|
K |
extends string |
the keys |
O |
extends Record<string, any> |
the object |
| Name | Type | Description |
|---|---|---|
k |
K[] |
the list of properties to omit |
o |
O |
the object |
Exclude<O, K>
▸ omit<K, O>(k): Unary<O, Exclude<O, K>>
Returns a unary Unary<O, Exclude<A, O>> function which omits the keys in A that are in O
Example
import { Obj } from 'tiinvo';
const omit = Obj.omit(['a', 'b'])
omit({ a: 1, b: 2, c: 3 }) // { c: 3 }
omit({ a: 1, b: 2 }) // {}
Since
4.0.0
| Name | Type | Description |
|---|---|---|
K |
extends string |
the keys |
O |
extends Record<string, any> |
the object |
| Name | Type | Description |
|---|---|---|
k |
K[] |
the list of properties to omit |
Unary<O, Exclude<O, K>>
▸ pick<K, O>(keys, o): Pick<O, K>
Returns a new object with the keys of a that are in b
Example
import { Obj } from 'tiinvo';
Obj.pick(['a', 'b'], { a: 1, b: 2, c: 3 }) // { a: 1, b: 2 }
const pick = Obj.pick(['a', 'b']);
pick({ a: 1, b: 2, c: 3 }); // { a: 1, b: 2 }
pick({ a: 1, b: 2 }); // { a: 1, b: 2 }
Since
4.0.0
| Name | Type | Description |
|---|---|---|
K |
extends string |
the keys |
O |
extends Record<string, any> |
the object |
| Name | Type | Description |
|---|---|---|
keys |
K[] |
the keys |
o |
O |
the object |
Pick<O, K>
▸ pick<K, O>(keys): Unary<O, Pick<O, K>>
| Name | Type |
|---|---|
K |
extends string |
O |
extends Record<string, any> |
| Name | Type |
|---|---|
keys |
K[] |
Unary<O, Pick<O, K>>
▸ map<a, b>(m): (a: a) => T<b>
Maps an object a to a value b
Example
import { Obj } from 'tiinvo';
Obj.map(Object.keys)({ a: 10, b: 20 }); // ['a', 'b']
Obj.map((x: Record<string, number>) => x.a ?? 0)({ a: 10 }); // 10
Obj.map((x: Record<string, number>) => x.a ?? 0)({ b: 10 }); // 0
Since
4.0.0
| Name | Type |
|---|---|
a |
extends object |
b |
b |
| Name | Type |
|---|---|
m |
Mappable<a, b> |
fn
▸ (a): T<b>
| Name | Type |
|---|---|
a |
a |
T<b>
▸ keys<x>(x): KeysOf<x>
Returns the names of the enumerable string properties and methods of an object.
Example
import { Obj } from 'tiinvo';
Obj.keys({ a: 10, b: 20 }) // ['a', 'b']
Since
4.0.0
| Name | Type |
|---|---|
x |
extends object |
| Name | Type |
|---|---|
x |
x |
KeysOf<x>
▸ size(x): number
Returns an object size
Example
import { Obj } from 'tiinvo';
Obj.size({ a: 1, b: 2 }) // 2
Obj.size({}) // 0
Since
4.0.0
| Name | Type | Description |
|---|---|---|
x |
object |
the object |
number
the size (count of keys) of the object
▸ values<a>(o): ValuesOf<a>
Returns an array of values of the enumerable properties of an object
Example
import { Obj } from 'tiinvo';
Obj.values({ a: 1, b: 2 }) // [1, 2]
Obj.values({}) // []
Since
4.0.0
| Name | Type |
|---|---|
a |
extends object |
| Name | Type |
|---|---|
o |
a |
ValuesOf<a>