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

ts-gems

Package Overview
Dependencies
Maintainers
1
Versions
51
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ts-gems - npm Package Compare versions

Comparing version 0.0.3 to 1.0.0

lib/deep-modify.d.ts

84

lib/common.d.ts

@@ -1,9 +0,74 @@

export type Primitive = string | number | boolean | null | bigint | symbol | undefined;
export type Builtin = Primitive | Function | Date | Error | RegExp;
export type NonObj = Primitive | Function;
export type NonSymbol = Exclude<Builtin, symbol>;
/**
* BasicPrimitive
* @desc Type representing [`BasicPrimitive`](https://www.typescriptlang.org/docs/handbook/release-notes/overview.html#smarter-type-alias-preservation) types in TypeScript
*/
type BasicPrimitive = number | string | boolean;
/**
* Primitive
* @desc Type representing [`Primitive`](https://developer.mozilla.org/en-US/docs/Glossary/Primitive) types
* in TypeScript: `string | number | bigint | boolean | symbol | null | undefined`
*/
export type Primitive = BasicPrimitive | null | bigint | symbol | undefined;
/**
* JsonTypes
* @desc Type representing JSON types in TypeScript
*/
type JsonType = BasicPrimitive | null | object | (BasicPrimitive | object)[]
/**
* Builtin
* @desc Type representing Builtin types in JavaScript
*/
export type Builtin = Primitive | Function | String | Number | Date | Error | RegExp | JSON | Math |
ArrayBuffer | DataView | Int8Array | Uint8Array | Uint8ClampedArray | Int16Array | Uint16Array |
Int32Array | Uint32Array | Float32Array | Float64Array;
/**
* Maybe
* @desc Type representing T | undefined
*/
export type Maybe<T> = T | undefined;
export type Nullable<T> = T | undefined | null;
/**
* Nullish
* @desc Type representing [nullish values][https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-7.html#nullish-coalescing] in TypeScript: `null | undefined`
*/
export type Nullish<T = null> = T | undefined | null;
/**
* Falsy
* @desc Type representing falsy values in TypeScript: `false | "" | 0 | null | undefined`
*/
export type Falsy = false | '' | 0 | null | undefined;
export type Awaited<T> = T extends PromiseLike<infer U> ? U : T;
export type Thunk<T, Args extends any[] = any[]> = T | ((...args: Args) => T);
export type AsyncThunk<T, Args extends any[] = any[]> = Thunk<T> | ((...args: Args) => Promise<T>);
/**
* PropertyType
* @desc Returns the type of property at a given key `K`
*/
export type PropertyType<T, K extends keyof T> = T[K];
/**
* $ElementType
* @desc Returns the type of elements inside of array, tuple or object of type `T`, that matches the given index type `K`
*/
export type ElementType<T extends { [P in K & any]: any },
K extends keyof T | number> = T[K];
/**
* Class
* @desc Represents constructor of type T
*/
export interface Type<T = any> {

@@ -13,8 +78,7 @@ new(...args: any[]): T;

export type Awaited<T> = T extends PromiseLike<infer PT> ? PT : T;
/**
* Class
* @desc Represents Class constructor of type T
*/
export type Class<Args extends any[] = any[], Instance = {}, Static = {}> =
(new(...args: Args) => Instance) & Static;
export type Thunk<T, Args extends any[] = any[]> = T | ((...args: Args) => T);
export type AsyncThunk<T, Args extends any[] = any[]> = T | ((...args: Args) => T) | ((...args: Args) => Promise<T>);

6

lib/index.d.ts
export * from "./common";
export * from "./keys";
export * from "./type-check";
export * from "./modify";
export * from "./omit";
export * from "./pick";
export * from "./type-check";
export * from "./deep-pick";
export * from "./deep-omit";

@@ -1,12 +0,27 @@

import {IfEquals, IsUndefined} from './type-check';
import {IfEquals, IfCompatible, IfUndefined, IfAny, IfJson} from './type-check';
/**
* Gets optional keys of an object
* KeyOf
* @desc Returns the union type of all the keys in a type
*/
export type OptionalKeys<T> = {
export type KeysOf<T> = keyof T;
/**
* ValuesOf
* @desc Returns the union type of all the values in a type
*/
export type ValuesOf<T> = T[keyof T];
/**
* OptionalKeys
* @desc Returns optional keys of an object
*/
export type OptionalKeys<T> = ValuesOf<{
[K in keyof T]-?: {} extends Pick<T, K> ? K : never;
}[keyof T];
}>;
/**
* Gets required keys of an object
* RequiredKeys
* @desc Returns required keys of an object
*/

@@ -16,34 +31,60 @@ export type RequiredKeys<T> = Exclude<keyof T, OptionalKeys<T>>;

/**
* Gets Function keys of an object
* @desc Returns readonly keys of an object
*/
export type FunctionKeys<T> = {
[K in keyof T]-?: IsUndefined<T[K]> extends false ?
T[K] extends Function ? K : never : never;
}[keyof T];
export type ReadonlyKeys<T> = ValuesOf<{
[K in keyof T]-?: IfEquals<{ [Q in K]: T[K] }, { -readonly [Q in K]: T[K] }, never, K>
}>;
/**
* Gets readonly keys of an object
* @desc Returns non function keys of an object
*/
export type ReadonlyKeys<T> = {
[K in keyof T]-?: IfEquals<{ [Q in K]: T[K] }, { -readonly [Q in K]: T[K] }, never, K>
}[keyof T];
export type NonFunctionKeys<T> = Exclude<keyof T, FunctionKeys<T>>;
/**
* Gets readable keys of an object
* @desc Returns non function keys of an object
*/
export type ReadableKeys<T> = Exclude<keyof T, FunctionKeys<T>>;
export type JsonKeys<T> = ValuesOf<{
[K in keyof T]-?: IfUndefined<T[K]> extends false ?
K extends symbol ? never :
IfJson<T[K]> extends true ?
K : never : never;
}>;
/**
* Gets writable keys of an object
* @desc Returns writable keys of an object
*/
export type WritableKeys<T> = Exclude<{
[K in keyof T]-?: IfEquals<{ [Q in K]: T[K] }, { -readonly [Q in K]: T[K] }, K>
}[keyof T], FunctionKeys<T>>;
export type WritableKeys<T> = Exclude<keyof T, ReadonlyKeys<T>>;
/**
* Gets keys that matches V of T
* @desc Returns writable json keys of an object
*/
type _TypeKeys<T, V> = {
[K in keyof T]: IfEquals<T[K], V, K, never>
}[keyof T];
export type TypeKeys<T, V> = _TypeKeys<Required<T>, V>;
export type WritableJsonKeys<T> = Extract<{
[K in keyof T]-?: IfEquals<{ [Q in K]: T[K] }, { -readonly [Q in K]: T[K] }, K, never>
}[keyof T], JsonKeys<T>>;
/**
* @desc Returns Function keys of an object
*/
export type FunctionKeys<T> = ValuesOf<{
[K in keyof T]-?: IfUndefined<T[K]> extends false ?
IfAny<T[K]> extends false ?
T[K] extends Function ? K
: never : never : never;
}>;
/**
* @desc Returns keys that match given type
*/
export type KeysCompatible<T, U> = ValuesOf<{
[K in keyof T]-?: IfCompatible<T[K], U, K, never>;
}>;
/**
* @desc Returns keys that equals given type
*/
export type KeysEquals<T, U> = ValuesOf<{
[K in keyof T]-?: IfEquals<T[K], U, K, never>;
}>;

@@ -1,5 +0,1 @@

/** Like Partial but recursive */
import {Builtin} from './common';
import {IsTuple} from './type-check';
/**

@@ -16,89 +12,1 @@ * Make all properties in T writable

export type Buildable<T> = Partial<Writable<T>>;
/**
* Combination of DeepPartial and DeepWritable
*/
export type DeepBuildable<T> = DeepPartial<DeepWritable<T>>;
/**
* Make all properties in T optional deeply
*/
export type DeepPartial<T> =
T extends Builtin ? T
: T extends Map<infer K, infer V> ? Map<K, DeepPartial<V>>
: T extends ReadonlyMap<infer K, infer V> ? ReadonlyMap<K, DeepPartial<V>>
: T extends WeakMap<infer K, infer V> ? WeakMap<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 (infer U)[] ? true extends IsTuple<T>
? { [K in keyof T]?: DeepPartial<T[K]> } : (DeepPartial<U>)[]
: T extends Promise<infer U> ? Promise<DeepPartial<U>>
: Partial<T>;
/**
* Make all properties in T required deeply
*/
export type DeepRequired<T> =
T extends Builtin ? T
: T extends Map<infer K, infer V> ? Map<K, DeepRequired<V>>
: T extends ReadonlyMap<infer K, infer V> ? ReadonlyMap<K, DeepRequired<V>>
: T extends WeakMap<infer K, infer V> ? WeakMap<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 (infer U)[] ? true extends IsTuple<T>
? { [K in keyof T]?: DeepRequired<T[K]> } : (DeepRequired<U>)[]
: T extends Promise<infer U> ? Promise<DeepRequired<U>>
: Required<T>;
/**
* Make all properties in T readonly deeply
*/
export type DeepReadonly<T> =
T extends Builtin ? T
: T extends Map<infer K, infer V> ? Map<K, DeepReadonly<V>>
: T extends ReadonlyMap<infer K, infer V> ? ReadonlyMap<K, DeepReadonly<V>>
: T extends WeakMap<infer K, infer V> ? WeakMap<K, DeepReadonly<V>>
: T extends Set<infer U> ? Set<DeepReadonly<U>>
: T extends ReadonlySet<infer U> ? ReadonlySet<DeepReadonly<U>>
: T extends WeakSet<infer U> ? WeakSet<DeepReadonly<U>>
: T extends (infer U)[] ? true extends IsTuple<T>
? { [K in keyof T]?: DeepReadonly<T[K]> } : (DeepReadonly<U>)[]
: T extends Promise<infer U> ? Promise<DeepReadonly<U>>
: Readonly<T>;
/**
* Make all properties in T writable deeply
*/
export type DeepWritable<T> =
T extends Builtin ? T
: T extends Map<infer K, infer V> ? Map<K, DeepWritable<V>>
: T extends ReadonlyMap<infer K, infer V> ? ReadonlyMap<K, DeepWritable<V>>
: T extends WeakMap<infer K, infer V> ? WeakMap<K, DeepWritable<V>>
: T extends Set<infer U> ? Set<DeepWritable<U>>
: T extends ReadonlySet<infer U> ? ReadonlySet<DeepWritable<U>>
: T extends WeakSet<infer U> ? WeakSet<DeepWritable<U>>
: T extends (infer U)[] ? true extends IsTuple<T>
? { [K in keyof T]?: DeepWritable<T[K]> } : (DeepWritable<U>)[]
: T extends Promise<infer U> ? Promise<DeepWritable<U>>
: Writable<T>;
/**
* Make all properties in T nullable deeply
*/
export type DeepNullable<T> =
T extends Builtin ? T
: T extends Map<infer K, infer V> ? Map<K, DeepNullable<V>>
: T extends ReadonlyMap<infer K, infer V> ? ReadonlyMap<K, DeepNullable<V>>
: T extends WeakMap<infer K, infer V> ? WeakMap<K, DeepNullable<V>>
: T extends Set<infer U> ? Set<DeepNullable<U>>
: T extends ReadonlySet<infer U> ? ReadonlySet<DeepNullable<U>>
: T extends WeakSet<infer U> ? WeakSet<DeepNullable<U>>
: T extends (infer U)[] ? true extends IsTuple<T>
? { [K in keyof T]?: DeepNullable<T[K]> } : (DeepNullable<U>)[]
: T extends Promise<infer U> ? Promise<DeepNullable<U>>
: T extends {}
? { [K in keyof T]: DeepNullable<T[K]> }
: T | null | undefined;

@@ -1,110 +0,162 @@

import {NonObj} from './common';
import {Primitive, Type} from './common';
type NonObj = Primitive | Function;
/**
* Returns Y if typeof T is "never", N otherwise
* Returns Y if typeof T is "any", N otherwise
*/
export type IsExtends<T, U> = [T] extends [U] ? true : false;
export type IfAny<T, Y = true, N = false> =
0 extends 1 & T ? Y : N;
/**
* Returns Y if typeof T is "never", N otherwise
* Returns "Y" if "T" is "never", "N" otherwise
*/
export type IfNever<T, Y, N = never> = [T] extends [never] ? Y : N;
export type IfNever<T, Y = true, N = false> =
[T] extends [never] ? Y : N;
/**
* Returns true if typeof T is "never", false otherwise
* Returns Y if T is undefined, N otherwise
*/
export type IsNever<T> = IfNever<T, true, false>;
export type IfUndefined<T, Y = true, N = false> =
IfEquals<T, undefined, Y, N>;
/**
* Returns Y if typeof T is "any", N otherwise
* Returns Y if typeof T is "unknown", N otherwise
*/
export type IfAny<T, Y = T, N = never> = 0 extends (1 & T) ? Y : N;
export type IfUnknown<T, Y = true, N = false> =
IfEquals<T, unknown, Y, N>;
/**
* Returns true if typeof T is "any", false otherwise
* Returns Y if typeof T is null, N otherwise
*/
export type IsAny<T> = IfAny<T, true, false>;
export type IfNull<T, Y = true, N = false> =
IfEquals<T, null, Y, N>;
/**
* Returns Y if typeof T is "unknown", N otherwise
* Returns Y if typeof T is null, N otherwise
*/
export type IfUnknown<T, Y, N = never> =
unknown extends T ?
IsAny<T> extends false
? IfEmptyObject<T, N, Y>
: N
: N;
/**
* Returns true if typeof T is "unknown", false otherwise
*/
export type IsUnknown<T> = IfUnknown<T, true, false>;
export type IfNullish<T, Y = true, N = false> =
IfNever<T> extends true ? N
: T extends null ? Y
: T extends undefined ? Y : N;
/**
* Returns Y if typeof T is a tuple, N otherwise
*/
export type IfTuple<T, Y = T, N = never> =
IsNever<T> extends true
? N
: T extends any[]
export type IfTuple<T, Y = true, N = false> =
IfEquals<T, [any]> extends true
? T extends [any]
? number extends T['length'] ? N : Y
: N;
: N : N;
export type IfTupleOrAny<T, Y = true, N = false> =
IfAny<T> extends true ? Y : IfTuple<T, Y, N>;
/**
* Returns true if typeof T is a tuple, false otherwise
* Returns Y if typeof T is "Primitive", N otherwise
*/
export type IsTuple<T> = IfTuple<T, true, false>;
export type IfPrimitive<T, Y = true, N = false> =
IfNever<T> extends true ? N :
IfClass<T> extends true ? N :
IfFunction<T> extends true ? N :
T extends Primitive ? Y :
N;
/**
* Returns Y if typeof T is an object, N otherwise
*/
export type IfObject<T, Y = T, N = never> =
IfNever<T, N,
T extends object
? T extends NonObj | any[]
? N
: Y
: N>;
export type IfPrimitiveOrAny<T, Y = true, N = false> =
IfAny<T> extends true ? Y : IfPrimitive<T, Y, N>;
/**
* Returns true if typeof T is an object, false otherwise
* Returns Y if typeof T is JSON like, N otherwise
*/
export type IsObject<T> = IfObject<T, true, false>;
export type IfJson<T, Y = true, N = false> =
IfNever<T> extends true ? N :
IfClass<T> extends true ? N :
IfFunction<T> extends true ? N :
IfUndefined<T> extends true ? N :
IfEquals<T, number> extends true ? Y :
IfEquals<T, string> extends true ? Y :
IfEquals<T, boolean> extends true ? Y :
IfEquals<T, null> extends true ? Y :
IfObject<T, Y> extends true ? Y :
T extends (infer U)[] ? IfJson<U> extends true ? Y : N
: N;
export type IfJsonOrAny<T, Y = true, N = false> =
IfAny<T> extends true ? Y : IfJson<T, Y, N>;
/**
* Returns Y if typeof T is an empty object, N otherwise
*/
export type IfEmptyObject<T extends {}, Y = T, N = never> =
IsNever<T> extends true
? N
: T extends object
? keyof T extends never ? Y : N
: N
export type IfEmptyObject<T, Y = true, N = false> =
IfEquals<T, {}, Y, N>;
/**
* Returns true if typeof T is an empty object, false otherwise
* Returns Y if typeof T is an object, N otherwise
*/
export type IsEmptyObject<T extends {}> = IfEmptyObject<T, true, false>;
export type IfObject<T, Y = true, N = false> =
IfNever<T> extends true ? N
: T extends object
? T extends NonObj | any[]
? N
: Y
: N;
export type IfObjectOrAny<T, Y = true, N = false> =
IfAny<T> extends true ? Y : IfObject<T, Y, N>;
/**
* Returns Y if T1 is exactly same with T2, N otherwise
* Returns Y if typeof T is an empty object, N otherwise
*/
type IfEquals<T1, T2, Y = T1, N = never> =
(<G>() => G extends T1 ? 1 : 2) extends (<G>() => G extends T2 ? 1 : 2) ? Y : N;
export type IfFunction<T, Y = true, N = false> =
IfNever<T> extends true ? N
: IfUndefined<T> extends true ? N
: IfNull<T> extends true ? N
: T extends Function ? Y
: N;
export type IfFunctionOrAny<T, Y = true, N = false> =
IfAny<T> extends true ? Y : IfFunction<T, Y, N>;
/**
* Returns true if T1 is exactly same with T2, false otherwise
* Returns Y if typeof T is an empty object, N otherwise
*/
export type IsEquals<T1, T2> = IfEquals<T1, T2, true, false>;
export type IfClass<T, Y = true, N = false> =
IfNever<T> extends true ? N
: IfUndefined<T> extends true ? N
: IfNull<T> extends true ? N
: T extends Type ? Y
: N;
export type IfClassOrAny<T, Y = true, N = false> =
IfAny<T> extends true ? Y : IfClass<T, Y, N>;
/**
* Returns Y if T1 is exactly same with T2, N otherwise
* Returns "Y" if "T1" is exactly same with "T2", "N" otherwise
*/
export type IfUndefined<T, Y = T, N = never> =
T extends undefined ? Y: N;
type IfEquals<T1, T2, Y = true, N = false> =
(<G>() => G extends T1 ? 1 : 2) extends (<G>() => G extends T2 ? 1 : 2) ? Y : N;
/**
* Returns true if T is undefined type
* Returns "Y" if type "T" matches "U", "N" otherwise
*/
export type IsUndefined<T> = IfUndefined<T, true, false>;
export type IfCompatible<T1, T2, Y = true, N = false> =
IfUndefined<T1> extends true ? IfEquals<T1, T2, Y, N> : IfUndefined<T2> extends true ? N
: IfNever<T1> extends true ? IfEquals<T1, T2, Y, N> : IfNever<T2> extends true ? N
: IfNull<T1> extends true ? IfEquals<T1, T2, Y, N> : IfNull<T2> extends true ? N
: IfUnknown<T1> extends true ? Y : IfUnknown<T2> extends true ? Y
: IfAny<T1> extends true ? Y : IfAny<T2> extends true ? Y
: IfEmptyObject<T1> extends true ? IfObject<T2, Y, N>
: IfEmptyObject<T2> extends true ? IfObject<T1, Y, N>
: IfFunction<T1> extends true ? IfCompatibleFunction<T1, T2, Y, N>
: IfObject<T1> extends true ? [T1] extends [T2] ? Y : N
: [T1] extends [T2] ? Y
: IfPrimitive<T2> extends true ? [T2] extends [T1] ? Y
: N : N;
type IfCompatibleFunction<T1, T2, Y = true, N = false> =
IfFunction<T1> extends false ? N
: IfFunction<T2> extends false ? N
: T1 extends T2
? Y
: N;

@@ -15,3 +15,3 @@ {

],
"version": "0.0.3",
"version": "1.0.0",
"types": "lib/index.d.ts",

@@ -22,4 +22,4 @@ "repository": "git@github.com:panates/ts-gems.git",

"scripts": {
"test:common": "jest --clearCache && jest --config=./test/jest.config.js",
"test:strict-null": "jest --clearCache && jest --config=./test/jest.strict-null.config.js",
"test:common": "jest --clearCache && jest --config=./jest.config.js",
"test:strict-null": "jest --clearCache && jest --config=./jest.strict-null.config.js",
"test": "npm run test:common && npm run test:strict-null",

@@ -37,7 +37,7 @@ "release": "npm run test && npm publish"

"devDependencies": {
"@types/jest": "^27.0.2",
"prettier": "^2.4.1",
"ts-jest": "^27.0.5",
"typescript": "^4.4.3"
"@types/jest": "^27.0.3",
"prettier": "^2.5.1",
"ts-jest": "^27.1.2",
"typescript": "^4.5.4"
}
}
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