Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More β†’
Socket
Sign inDemoInstall
Socket

ts-essentials

Package Overview
Dependencies
Maintainers
1
Versions
60
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ts-essentials - npm Package Compare versions

Comparing version 6.0.3 to 6.0.4

2

dist/functions.d.ts
export declare class UnreachableCaseError extends Error {
constructor(value: never);
constructor(value: never);
}
export declare function assert(condition: any, msg?: string): asserts condition;
export declare function noop(..._args: unknown[]): void;
/** Essentials */
export declare type Primitive = string | number | boolean | bigint | symbol | undefined | null;
export declare type Builtin = Primitive | Function | Date | Error | RegExp;
export declare type IsTuple<T> = T extends [infer A] ? T : T extends [infer A, infer B] ? T : T extends [infer A, infer B, infer C] ? T : T extends [infer A, infer B, infer C, infer D] ? T : T extends [infer A, infer B, infer C, infer D, infer E] ? T : never;
export declare type IsTuple<T> = T extends [infer A]
? T
: T extends [infer A, infer B]
? T
: T extends [infer A, infer B, infer C]
? T
: T extends [infer A, infer B, infer C, infer D]
? T
: T extends [infer A, infer B, infer C, infer D, infer E]
? T
: never;
export declare type AnyArray<T = any> = Array<T> | ReadonlyArray<T>;
/** Like Record, but can be used with only one argument */
export declare type Dictionary<T, K extends string | number = string> = {
[key in K]: T;
[key in K]: T;
};

@@ -18,33 +29,145 @@ /** Given Dictionary<T> returns T */

/** Like Partial but recursive */
export declare type DeepPartial<T> = T extends Builtin ? T : T extends Map<infer K, infer V> ? Map<DeepPartial<K>, DeepPartial<V>> : T extends ReadonlyMap<infer K, infer V> ? ReadonlyMap<DeepPartial<K>, DeepPartial<V>> : T extends WeakMap<infer K, infer V> ? WeakMap<DeepPartial<K>, DeepPartial<V>> : T extends Set<infer U> ? Set<DeepPartial<U>> : T extends ReadonlySet<infer U> ? ReadonlySet<DeepPartial<U>> : T extends WeakSet<infer U> ? WeakSet<DeepPartial<U>> : T extends Array<infer U> ? T extends IsTuple<T> ? {
[K in keyof T]?: DeepPartial<T[K]>;
} : Array<DeepPartial<U>> : T extends Promise<infer U> ? Promise<DeepPartial<U>> : T extends {} ? {
[K in keyof T]?: DeepPartial<T[K]>;
} : Partial<T>;
export declare type DeepPartial<T> = T extends Builtin
? T
: T extends Map<infer K, infer V>
? Map<DeepPartial<K>, DeepPartial<V>>
: T extends ReadonlyMap<infer K, infer V>
? ReadonlyMap<DeepPartial<K>, DeepPartial<V>>
: T extends WeakMap<infer K, infer V>
? WeakMap<DeepPartial<K>, DeepPartial<V>>
: T extends Set<infer U>
? Set<DeepPartial<U>>
: T extends ReadonlySet<infer U>
? ReadonlySet<DeepPartial<U>>
: T extends WeakSet<infer U>
? WeakSet<DeepPartial<U>>
: T extends Array<infer U>
? T extends IsTuple<T>
? {
[K in keyof T]?: DeepPartial<T[K]>;
}
: Array<DeepPartial<U>>
: T extends Promise<infer U>
? Promise<DeepPartial<U>>
: T extends {}
? {
[K in keyof T]?: DeepPartial<T[K]>;
}
: Partial<T>;
/** Recursive nullable */
export declare type DeepNullable<T> = T extends Builtin ? T | null : T extends Map<infer K, infer V> ? Map<DeepNullable<K>, DeepNullable<V>> : T extends WeakMap<infer K, infer V> ? WeakMap<DeepNullable<K>, DeepNullable<V>> : T extends Set<infer U> ? Set<DeepNullable<U>> : T extends WeakSet<infer U> ? WeakSet<DeepNullable<U>> : T extends Array<infer U> ? T extends IsTuple<T> ? {
[K in keyof T]: DeepNullable<T[K]> | null;
} : Array<DeepNullable<U>> : T extends Promise<infer U> ? Promise<DeepNullable<U>> : T extends {} ? {
[K in keyof T]: DeepNullable<T[K]>;
} : T | null;
export declare type DeepNullable<T> = T extends Builtin
? T | null
: T extends Map<infer K, infer V>
? Map<DeepNullable<K>, DeepNullable<V>>
: T extends WeakMap<infer K, infer V>
? WeakMap<DeepNullable<K>, DeepNullable<V>>
: T extends Set<infer U>
? Set<DeepNullable<U>>
: T extends WeakSet<infer U>
? WeakSet<DeepNullable<U>>
: T extends Array<infer U>
? T extends IsTuple<T>
? {
[K in keyof T]: DeepNullable<T[K]> | null;
}
: Array<DeepNullable<U>>
: T extends Promise<infer U>
? Promise<DeepNullable<U>>
: T extends {}
? {
[K in keyof T]: DeepNullable<T[K]>;
}
: T | null;
/** Like NonNullable but recursive */
export declare type DeepNonNullable<T> = T extends Builtin ? NonNullable<T> : T extends Map<infer K, infer V> ? Map<DeepNonNullable<K>, DeepNonNullable<V>> : T extends ReadonlyMap<infer K, infer V> ? ReadonlyMap<DeepNonNullable<K>, DeepNonNullable<V>> : T extends WeakMap<infer K, infer V> ? WeakMap<DeepNonNullable<K>, DeepNonNullable<V>> : T extends Set<infer U> ? Set<DeepNonNullable<U>> : T extends ReadonlySet<infer U> ? ReadonlySet<DeepNonNullable<U>> : T extends WeakSet<infer U> ? WeakSet<DeepNonNullable<U>> : T extends Promise<infer U> ? Promise<DeepNonNullable<U>> : T extends {} ? {
[K in keyof T]: DeepNonNullable<T[K]>;
} : NonNullable<T>;
export declare type DeepNonNullable<T> = T extends Builtin
? NonNullable<T>
: T extends Map<infer K, infer V>
? Map<DeepNonNullable<K>, DeepNonNullable<V>>
: T extends ReadonlyMap<infer K, infer V>
? ReadonlyMap<DeepNonNullable<K>, DeepNonNullable<V>>
: T extends WeakMap<infer K, infer V>
? WeakMap<DeepNonNullable<K>, DeepNonNullable<V>>
: T extends Set<infer U>
? Set<DeepNonNullable<U>>
: T extends ReadonlySet<infer U>
? ReadonlySet<DeepNonNullable<U>>
: T extends WeakSet<infer U>
? WeakSet<DeepNonNullable<U>>
: T extends Promise<infer U>
? Promise<DeepNonNullable<U>>
: T extends {}
? {
[K in keyof T]: DeepNonNullable<T[K]>;
}
: NonNullable<T>;
/** Like Required but recursive */
export declare type DeepRequired<T> = T extends Builtin ? NonNullable<T> : T extends Map<infer K, infer V> ? Map<DeepRequired<K>, DeepRequired<V>> : T extends ReadonlyMap<infer K, infer V> ? ReadonlyMap<DeepRequired<K>, DeepRequired<V>> : T extends WeakMap<infer K, infer V> ? WeakMap<DeepRequired<K>, DeepRequired<V>> : T extends Set<infer U> ? Set<DeepRequired<U>> : T extends ReadonlySet<infer U> ? ReadonlySet<DeepRequired<U>> : T extends WeakSet<infer U> ? WeakSet<DeepRequired<U>> : T extends Promise<infer U> ? Promise<DeepRequired<U>> : T extends {} ? {
[K in keyof T]-?: DeepRequired<T[K]>;
} : NonNullable<T>;
export declare type DeepRequired<T> = T extends Builtin
? NonNullable<T>
: T extends Map<infer K, infer V>
? Map<DeepRequired<K>, DeepRequired<V>>
: T extends ReadonlyMap<infer K, infer V>
? ReadonlyMap<DeepRequired<K>, DeepRequired<V>>
: T extends WeakMap<infer K, infer V>
? WeakMap<DeepRequired<K>, DeepRequired<V>>
: T extends Set<infer U>
? Set<DeepRequired<U>>
: T extends ReadonlySet<infer U>
? ReadonlySet<DeepRequired<U>>
: T extends WeakSet<infer U>
? WeakSet<DeepRequired<U>>
: T extends Promise<infer U>
? Promise<DeepRequired<U>>
: T extends {}
? {
[K in keyof T]-?: DeepRequired<T[K]>;
}
: NonNullable<T>;
/** Like Readonly but recursive */
export declare type DeepReadonly<T> = T extends Builtin ? T : T extends Map<infer K, infer V> ? ReadonlyMap<DeepReadonly<K>, DeepReadonly<V>> : T extends ReadonlyMap<infer K, infer V> ? ReadonlyMap<DeepReadonly<K>, DeepReadonly<V>> : T extends WeakMap<infer K, infer V> ? WeakMap<DeepReadonly<K>, DeepReadonly<V>> : T extends Set<infer U> ? ReadonlySet<DeepReadonly<U>> : T extends ReadonlySet<infer U> ? ReadonlySet<DeepReadonly<U>> : T extends WeakSet<infer U> ? WeakSet<DeepReadonly<U>> : T extends Promise<infer U> ? Promise<DeepReadonly<U>> : T extends {} ? {
readonly [K in keyof T]: DeepReadonly<T[K]>;
} : Readonly<T>;
export declare type DeepReadonly<T> = T extends Builtin
? T
: T extends Map<infer K, infer V>
? ReadonlyMap<DeepReadonly<K>, DeepReadonly<V>>
: T extends ReadonlyMap<infer K, infer V>
? ReadonlyMap<DeepReadonly<K>, DeepReadonly<V>>
: T extends WeakMap<infer K, infer V>
? WeakMap<DeepReadonly<K>, DeepReadonly<V>>
: T extends Set<infer U>
? ReadonlySet<DeepReadonly<U>>
: T extends ReadonlySet<infer U>
? ReadonlySet<DeepReadonly<U>>
: T extends WeakSet<infer U>
? WeakSet<DeepReadonly<U>>
: T extends Promise<infer U>
? Promise<DeepReadonly<U>>
: T extends {}
? {
readonly [K in keyof T]: DeepReadonly<T[K]>;
}
: Readonly<T>;
/** Make readonly object writable */
export declare type Writable<T> = {
-readonly [P in keyof T]: T[P];
-readonly [P in keyof T]: T[P];
};
/** Like Writable but recursive */
export declare type DeepWritable<T> = T extends Builtin ? T : T extends Map<infer K, infer V> ? Map<DeepWritable<K>, DeepWritable<V>> : T extends ReadonlyMap<infer K, infer V> ? Map<DeepWritable<K>, DeepWritable<V>> : T extends WeakMap<infer K, infer V> ? WeakMap<DeepWritable<K>, DeepWritable<V>> : T extends Set<infer U> ? Set<DeepWritable<U>> : T extends ReadonlySet<infer U> ? Set<DeepWritable<U>> : T extends WeakSet<infer U> ? WeakSet<DeepWritable<U>> : T extends Promise<infer U> ? Promise<DeepWritable<U>> : T extends {} ? {
-readonly [K in keyof T]: DeepWritable<T[K]>;
} : T;
export declare type DeepWritable<T> = T extends Builtin
? T
: T extends Map<infer K, infer V>
? Map<DeepWritable<K>, DeepWritable<V>>
: T extends ReadonlyMap<infer K, infer V>
? Map<DeepWritable<K>, DeepWritable<V>>
: T extends WeakMap<infer K, infer V>
? WeakMap<DeepWritable<K>, DeepWritable<V>>
: T extends Set<infer U>
? Set<DeepWritable<U>>
: T extends ReadonlySet<infer U>
? Set<DeepWritable<U>>
: T extends WeakSet<infer U>
? WeakSet<DeepWritable<U>>
: T extends Promise<infer U>
? Promise<DeepWritable<U>>
: T extends {}
? {
-readonly [K in keyof T]: DeepWritable<T[K]>;
}
: T;
/** Combination of DeepPartial and DeepWritable */

@@ -55,25 +178,84 @@ export declare type Buildable<T> = DeepPartial<DeepWritable<T>>;

/** Omit all properties of given type in object type */
export declare type OmitProperties<T, P> = Pick<T, {
export declare type OmitProperties<T, P> = Pick<
T,
{
[K in keyof T]: T[K] extends P ? never : K;
}[keyof T]>;
}[keyof T]
>;
/** Pick all properties of given type in object type */
export declare type PickProperties<T, P> = Pick<T, {
export declare type PickProperties<T, P> = Pick<
T,
{
[K in keyof T]: T[K] extends P ? K : never;
}[keyof T]>;
}[keyof T]
>;
/** Recursively omit deep properties */
export declare type DeepOmit<T extends DeepOmitModify<Filter>, Filter> = T extends Builtin ? T : T extends Map<infer KeyType, infer ValueType> ? ValueType extends DeepOmitModify<Filter> ? Map<KeyType, DeepOmit<ValueType, Filter>> : T : T extends ReadonlyMap<infer KeyType, infer ValueType> ? ValueType extends DeepOmitModify<Filter> ? ReadonlyMap<KeyType, DeepOmit<ValueType, Filter>> : T : T extends WeakMap<infer KeyType, infer ValueType> ? ValueType extends DeepOmitModify<Filter> ? WeakMap<KeyType, DeepOmit<ValueType, Filter>> : T : T extends Set<infer ItemType> ? ItemType extends DeepOmitModify<Filter> ? Set<DeepOmit<ItemType, Filter>> : T : T extends ReadonlySet<infer ItemType> ? ItemType extends DeepOmitModify<Filter> ? ReadonlySet<DeepOmit<ItemType, Filter>> : T : T extends WeakSet<infer ItemType> ? ItemType extends DeepOmitModify<Filter> ? WeakSet<DeepOmit<ItemType, Filter>> : T : T extends Array<infer ItemType> ? ItemType extends DeepOmitModify<Filter> ? Array<DeepOmit<ItemType, Filter>> : T : T extends Promise<infer ItemType> ? ItemType extends DeepOmitModify<Filter> ? Promise<DeepOmit<ItemType, Filter>> : T : {
[K in Exclude<keyof T, keyof Filter>]: T[K];
} & OmitProperties<{
[K in Extract<keyof T, keyof Filter>]: Filter[K] extends true ? never : T[K] extends DeepOmitModify<Filter[K]> ? DeepOmit<T[K], Filter[K]> : T[K];
}, never>;
declare type DeepOmitModify<T> = {
[K in keyof T]: T[K] extends never ? any : T[K] extends object ? DeepOmitModify<T[K]> : never;
} | Array<DeepOmitModify<T>> | Promise<DeepOmitModify<T>> | Set<DeepOmitModify<T>> | ReadonlySet<DeepOmitModify<T>> | WeakSet<DeepOmitModify<T>> | Map<any, DeepOmitModify<T>> | WeakMap<any, DeepOmitModify<T>>;
export declare type DeepOmit<T extends DeepOmitModify<Filter>, Filter> = T extends Builtin
? T
: T extends Map<infer KeyType, infer ValueType>
? ValueType extends DeepOmitModify<Filter>
? Map<KeyType, DeepOmit<ValueType, Filter>>
: T
: T extends ReadonlyMap<infer KeyType, infer ValueType>
? ValueType extends DeepOmitModify<Filter>
? ReadonlyMap<KeyType, DeepOmit<ValueType, Filter>>
: T
: T extends WeakMap<infer KeyType, infer ValueType>
? ValueType extends DeepOmitModify<Filter>
? WeakMap<KeyType, DeepOmit<ValueType, Filter>>
: T
: T extends Set<infer ItemType>
? ItemType extends DeepOmitModify<Filter>
? Set<DeepOmit<ItemType, Filter>>
: T
: T extends ReadonlySet<infer ItemType>
? ItemType extends DeepOmitModify<Filter>
? ReadonlySet<DeepOmit<ItemType, Filter>>
: T
: T extends WeakSet<infer ItemType>
? ItemType extends DeepOmitModify<Filter>
? WeakSet<DeepOmit<ItemType, Filter>>
: T
: T extends Array<infer ItemType>
? ItemType extends DeepOmitModify<Filter>
? Array<DeepOmit<ItemType, Filter>>
: T
: T extends Promise<infer ItemType>
? ItemType extends DeepOmitModify<Filter>
? Promise<DeepOmit<ItemType, Filter>>
: T
: {
[K in Exclude<keyof T, keyof Filter>]: T[K];
} &
OmitProperties<
{
[K in Extract<keyof T, keyof Filter>]: Filter[K] extends true
? never
: T[K] extends DeepOmitModify<Filter[K]>
? DeepOmit<T[K], Filter[K]>
: T[K];
},
never
>;
declare type DeepOmitModify<T> =
| {
[K in keyof T]: T[K] extends never ? any : T[K] extends object ? DeepOmitModify<T[K]> : never;
}
| Array<DeepOmitModify<T>>
| Promise<DeepOmitModify<T>>
| Set<DeepOmitModify<T>>
| ReadonlySet<DeepOmitModify<T>>
| WeakSet<DeepOmitModify<T>>
| Map<any, DeepOmitModify<T>>
| WeakMap<any, DeepOmitModify<T>>;
/** Remove keys with `never` value from object type */
export declare type NonNever<T extends {}> = Pick<T, {
export declare type NonNever<T extends {}> = Pick<
T,
{
[K in keyof T]: T[K] extends never ? never : K;
}[keyof T]>;
}[keyof T]
>;
export declare type NonEmptyObject<T extends {}> = keyof T extends never ? never : T;
/** Merge 2 types, properties types from the latter override the ones defined on the former type */
export declare type Merge<M, N> = Omit<M, Extract<keyof M, keyof N>> & N;
export declare type Merge<M, N> = Omit<M, keyof N> & N;
/** Mark some properties as required, leaving others unchanged */

@@ -84,6 +266,10 @@ export declare type MarkRequired<T, RK extends keyof T> = Exclude<T, RK> & Required<Pick<T, RK>>;

/** Convert union type to intersection #darkmagic */
export declare type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends (k: infer I) => void ? I : never;
export declare type UnionToIntersection<U> = (U extends any
? (k: U) => void
: never) extends (k: infer I) => void
? I
: never;
/** Easy create opaque types ie. types that are subset of their original types (ex: positive numbers, uppercased string) */
export declare type Opaque<K, T> = T & {
__TYPE__: K;
__TYPE__: K;
};

@@ -96,22 +282,36 @@ /** Easily extract the type of a given object's values */

export declare type AsyncOrSync<T> = PromiseLike<T> | T;
declare type IsEqualConsideringWritability<X, Y> = (<T>() => T extends X ? 1 : 2) extends <T>() => T extends Y ? 1 : 2 ? true : false;
declare type IsFullyWritable<T extends object> = IsEqualConsideringWritability<{
declare type IsEqualConsideringWritability<X, Y> = (<T>() => T extends X ? 1 : 2) extends <T>() => T extends Y ? 1 : 2
? true
: false;
declare type IsFullyWritable<T extends object> = IsEqualConsideringWritability<
{
[Q in keyof T]: T[Q];
}, Writable<{
[Q in keyof T]: T[Q];
}>>;
},
Writable<
{
[Q in keyof T]: T[Q];
}
>
>;
/** Gets keys of an object which are readonly */
export declare type ReadonlyKeys<T extends object> = {
[P in keyof T]-?: IsFullyWritable<Pick<T, P>> extends true ? never : P;
[P in keyof T]-?: IsFullyWritable<Pick<T, P>> extends true ? never : P;
}[keyof T];
/** Gets keys of an object which are writable */
export declare type WritableKeys<T extends {}> = {
[P in keyof T]-?: IsFullyWritable<Pick<T, P>> extends true ? P : never;
[P in keyof T]-?: IsFullyWritable<Pick<T, P>> extends true ? P : never;
}[keyof T];
/** Mark some properties which only the former including as optional and set the value to never */
declare type Without<T, U> = {
[P in Exclude<keyof T, keyof U>]?: never;
[P in Exclude<keyof T, keyof U>]?: never;
};
/** get the XOR type which could make 2 types exclude each other */
export declare type XOR<T, U> = T | U extends object ? (Without<T, U> & U) | (Without<U, T> & T) : T | U;
/** Functional programming essentials */
export declare type Head<T extends AnyArray> = T["length"] extends 0 ? never : T[0];
export declare type Tail<T extends AnyArray> = T["length"] extends 0
? never
: ((...t: T) => void) extends (first: any, ...rest: infer Rest) => void
? Rest
: never;
export {};

@@ -14,3 +14,3 @@ {

],
"version": "6.0.3",
"version": "6.0.4",
"main": "dist/index.js",

@@ -23,3 +23,4 @@ "types": "dist/index.d.ts",

"build": "rm -rf ./dist && tsc -p tsconfig.prod.json --outDir ./dist",
"prepublishOnly": "yarn test && yarn build",
"formatDeclarations": "prettier --ignore-path *.js --write dist/*.d.ts",
"prepublishOnly": "yarn test && yarn build && yarn formatDeclarations",
"test": "prettier -c **/*.ts && tsc --noEmit",

@@ -26,0 +27,0 @@ "test:fix": "prettier --write **/*.ts && tsc --noEmit"

@@ -29,7 +29,7 @@ <p align="center">

- [Deep* wrapper types](#Deep-wrapper-types)
- DeepPartial
- DeepRequired
- DeepReadonly
- DeepNonNullable
- DeepNullable
- DeepPartial
- DeepRequired
- DeepReadonly
- DeepNonNullable
- DeepNullable
- [Writable & DeepWritable](#Writable)

@@ -57,2 +57,5 @@ - [Buildable](#Buildable)

- [XOR](#XOR)
- [Functional type essentials](#functional-type-essentials)
- Head
- Tail
- [Contributors](#Contributors)

@@ -611,2 +614,3 @@

Gets the XOR (Exclusive-OR) type which could make 2 types exclude each other.
```typescript

@@ -632,2 +636,15 @@ type A = {a: string}

### Functional type essentials
`Head` & `Tail`: useful for functional programming, or as building blocks for more complex functional types.
```typescript
function tail<T extends any[]>(array: T): Tail<T> {
return array.slice(1) as Tail<T>;
}
type FirstParameter<FnT extends (...args: any) => any> =
FnT extends ((...args: infer ArgsT) => any) ? Head<ArgsT> : never;
```
## Contributors

@@ -670,2 +687,3 @@

<td align="center"><a href="https://github.com/leaumar"><img src="https://avatars2.githubusercontent.com/u/3950300?v=4" width="100px;" alt=""/><br /><sub><b>Marnick L'Eau</b></sub></a><br /><a href="https://github.com/krzkaczor/ts-essentials/commits?author=leaumar" title="Code">πŸ’»</a> <a href="#ideas-leaumar" title="Ideas, Planning, & Feedback">πŸ€”</a> <a href="https://github.com/krzkaczor/ts-essentials/commits?author=leaumar" title="Documentation">πŸ“–</a></td>
<td align="center"><a href="https://github.com/kubk"><img src="https://avatars1.githubusercontent.com/u/22447849?v=4" width="100px;" alt=""/><br /><sub><b>kubk</b></sub></a><br /><a href="https://github.com/krzkaczor/ts-essentials/commits?author=kubk" title="Code">πŸ’»</a></td>
</tr>

@@ -672,0 +690,0 @@ </table>

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚑️ by Socket Inc