Skip to content

Commit

Permalink
update exported type
Browse files Browse the repository at this point in the history
  • Loading branch information
rawpixel-vincent committed Mar 31, 2024
1 parent 9f0cbb0 commit baeb6b7
Show file tree
Hide file tree
Showing 11 changed files with 1,030 additions and 996 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "string-literal-list",
"version": "1.22.0",
"version": "1.23.0",
"description": "an array for string literal",
"main": "stringList.cjs",
"module": "stringList.js",
Expand All @@ -11,14 +11,14 @@
"types": "stringList.d.ts",
"exports": {
".": {
"types": "./stringList.js",
"types": "./stringList.d.ts",
"require": "./stringList.cjs",
"node": "./stringList.js",
"import": "./stringList.min.js",
"default": "./stringList.js"
},
"./strict.js": {
"types": "./strict.js",
"types": "./strict.d.ts",
"require": "./strict.cjs",
"node": "./strict.js",
"import": "./strict.min.js",
Expand All @@ -28,7 +28,7 @@
"default": "./types/index.js"
},
"./stringList.js": {
"types": "./stringList.js",
"types": "./stringList.d.ts",
"require": "./stringList.cjs",
"node": "./stringList.js",
"import": "./stringList.min.js",
Expand Down
12 changes: 5 additions & 7 deletions strict.d.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import { IStringList } from './types/list.js';
export declare function stringList<
TT extends readonly string[] = readonly never[],
>(...strings: TT): StringLiteralList.list.IStringList<TT, false, false>;

export function stringList<TT extends readonly string[] = readonly never[]>(
export declare function sl<TT extends readonly string[] = readonly never[]>(
...strings: TT
): IStringList<TT, false, false>;

export function sl<TT extends readonly string[] = readonly never[]>(
...strings: TT
): IStringList<TT, false, false>;
): StringLiteralList.list.IStringList<TT, false, false>;
12 changes: 5 additions & 7 deletions stringList.d.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import { IStringList } from './types/list.js';
export declare function stringList<
TT extends readonly string[] = readonly never[],
>(...strings: TT): StringLiteralList.list.IStringList<TT, true, false>;

export function stringList<TT extends readonly string[] = readonly never[]>(
export declare function sl<TT extends readonly string[] = readonly never[]>(
...strings: TT
): IStringList<TT, true, false>;

export function sl<TT extends readonly string[] = readonly never[]>(
...strings: TT
): IStringList<TT, true, false>;
): StringLiteralList.list.IStringList<TT, true, false>;
10 changes: 4 additions & 6 deletions stringListFunction.d.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
/// <reference path="./types/index.d.ts" />
/// <reference path="./types/list.d.ts" />

import { IStringList } from './types/list.js';

export function stringListMutable<
export declare function stringListMutable<
TT extends readonly string[] = readonly never[],
>(...list: TT): IStringList<TT, true, false>;
>(...list: TT): StringLiteralList.list.IStringList<TT, true, false>;

export function stringListReadonly<
export declare function stringListReadonly<
TT extends readonly string[] = readonly never[],
>(...list: TT): IStringList<TT, false, false>;
>(...list: TT): StringLiteralList.list.IStringList<TT, false, false>;
151 changes: 75 additions & 76 deletions types/generic.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,92 +2,91 @@
import './index.js';

declare global {
export namespace StringLiteralList {
export namespace generic {
/**
* Returns a tuple of the given length with the given type.
*/
export type TupleOf<
L extends number,
T = unknown,
result extends any[] = [],
> = result['length'] extends L ? result : TupleOf<L, T, [...result, T]>;
export namespace StringLiteralList {}
export namespace StringLiteralList.generic {
/**
* Returns a tuple of the given length with the given type.
*/
export type TupleOf<
L extends number,
T = unknown,
result extends any[] = [],
> = result['length'] extends L ? result : TupleOf<L, T, [...result, T]>;

export type Subtract<A extends number, B extends number> = number extends
| A
| B
? number
: TupleOf<A> extends [...infer U, ...TupleOf<B>]
? U['length']
: 0;
export type Subtract<A extends number, B extends number> = number extends
| A
| B
? number
: TupleOf<A> extends [...infer U, ...TupleOf<B>]
? U['length']
: 0;

export type IsNegative<T extends number> = number extends T
? boolean
: `${T}` extends `-${number}`
? true
: false;
export type IsNegative<T extends number> = number extends T
? boolean
: `${T}` extends `-${number}`
? true
: false;

export type Abs<T extends number> =
`${T}` extends `-${infer U extends number}` ? U : T;
export type Abs<T extends number> =
`${T}` extends `-${infer U extends number}` ? U : T;

/**
* Returns true if input number type is a literal
*/
export type IsNumberLiteral<T extends number> = [T] extends [number]
? [number] extends [T]
? false
: true
: false;
/**
* Returns true if input number type is a literal
*/
export type IsNumberLiteral<T extends number> = [T] extends [number]
? [number] extends [T]
? false
: true
: false;

export type IsBooleanLiteral<T extends boolean> = [T] extends [boolean]
? [boolean] extends [T]
? false
: true
: false;
export type IsBooleanLiteral<T extends boolean> = [T] extends [boolean]
? [boolean] extends [T]
? false
: true
: false;

/**
* Returns true if any elements in boolean array are the literal true (not false or boolean)
*/
export type Any<Arr extends boolean[]> = Arr extends [
infer Head extends boolean,
...infer Rest extends boolean[],
]
? IsBooleanLiteral<Head> extends true
? Head extends true
? true
: Any<Rest>
/**
* Returns true if any elements in boolean array are the literal true (not false or boolean)
*/
export type Any<Arr extends boolean[]> = Arr extends [
infer Head extends boolean,
...infer Rest extends boolean[],
]
? IsBooleanLiteral<Head> extends true
? Head extends true
? true
: Any<Rest>
: false;
: Any<Rest>
: false;

export type Reject<
tuple,
cond,
output extends any[] = [],
> = tuple extends [infer first, ...infer rest]
? Reject<rest, cond, first extends cond ? output : [...output, first]>
: output;
export type Reject<tuple, cond, output extends any[] = []> = tuple extends [
infer first,
...infer rest,
]
? Reject<rest, cond, first extends cond ? output : [...output, first]>
: output;

/**
* Returns true if every element in boolean array is the literal true (not false or boolean)
*/
export type All<Arr extends boolean[]> =
IsBooleanLiteral<Arr[number]> extends true
? Arr extends [
infer Head extends boolean,
...infer Rest extends boolean[],
]
? Head extends true
? Any<Rest>
: false // Found `false` in array
: true // Empty array (or all elements have already passed test)
: false; // Array/Tuple contains `boolean` type
/**
* Returns true if every element in boolean array is the literal true (not false or boolean)
*/
export type All<Arr extends boolean[]> =
IsBooleanLiteral<Arr[number]> extends true
? Arr extends [
infer Head extends boolean,
...infer Rest extends boolean[],
]
? Head extends true
? Any<Rest>
: false // Found `false` in array
: true // Empty array (or all elements have already passed test)
: false; // Array/Tuple contains `boolean` type

export type UnionToIntersection<U> = (
U extends never ? never : (arg: U) => never
) extends (arg: infer I) => void
? I
: never;
}
export type UnionToIntersection<U> = (
U extends never ? never : (arg: U) => never
) extends (arg: infer I) => void
? I
: never;
}
}

export {};
13 changes: 1 addition & 12 deletions types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,7 @@
import { ArrayInPlaceMutation } from '../StringLiteralList.js';

declare global {
export namespace StringLiteralList {
// @ts-ignore
export * as tuple from './tuple.js';
// @ts-ignore
export * as list from './list.js';
// @ts-ignore
export * as record from './record.js';
// @ts-ignore
export * as string from './string.js';
// @ts-ignore
export * as generic from './generic.js';
}
export namespace StringLiteralList {}

export namespace specs {
/**
Expand Down
Loading

0 comments on commit baeb6b7

Please sign in to comment.