From 5a828febbfcde69a2c48dbe6f7a829445ad39cce Mon Sep 17 00:00:00 2001 From: rawpixel-vincent Date: Sun, 3 Mar 2024 02:31:12 +0700 Subject: [PATCH] fix types exports --- dist/index.cjs => index.cjs | 0 package-lock.json | 8 +-- package.json | 7 +- stringList.js | 2 +- stringList.test.js | 2 - types.d.ts | 123 ++++++++++++++++++++++++++++-------- 6 files changed, 103 insertions(+), 39 deletions(-) rename dist/index.cjs => index.cjs (100%) diff --git a/dist/index.cjs b/index.cjs similarity index 100% rename from dist/index.cjs rename to index.cjs diff --git a/package-lock.json b/package-lock.json index 3aaceb8..9c2b272 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { - "name": "string-list", - "version": "1.0.0", + "name": "string-literal-list", + "version": "1.0.1", "lockfileVersion": 3, "requires": true, "packages": { "": { - "name": "string-list", - "version": "1.0.0", + "name": "string-literal-list", + "version": "1.0.1", "license": "MIT", "devDependencies": { "esbuild": "latest", diff --git a/package.json b/package.json index cd74b16..3048d0a 100644 --- a/package.json +++ b/package.json @@ -1,19 +1,18 @@ { "name": "string-literal-list", - "version": "1.0.0", + "version": "1.0.1", "description": "an array for strings", "main": "index.js", "exports": { ".": { "import": "./index.js", - "require": "./dist/index.cjs" + "require": "./index.cjs" } }, - "types": "types.d.ts", "license": "MIT", "scripts": { "test": "node stringList.test.js && tsc --project ./jsconfig.json", - "build": "esbuild --target=esnext --keep-names --format=cjs index.js --outfile=dist/index.cjs" + "build": "esbuild --target=esnext --keep-names --format=cjs ./index.js --outfile=./index.cjs" }, "author": "Vincent Baronnet", "type": "module", diff --git a/stringList.js b/stringList.js index ddb7ec1..2665a7d 100644 --- a/stringList.js +++ b/stringList.js @@ -1,4 +1,4 @@ -'use strict'; +/// /** * @type {Readonly} diff --git a/stringList.test.js b/stringList.test.js index 160d67d..37e4a4d 100644 --- a/stringList.test.js +++ b/stringList.test.js @@ -1,5 +1,3 @@ -'use strict'; - import stringList from './index.js'; let d = stringList('foo', 'bar'); diff --git a/types.d.ts b/types.d.ts index d18dc25..caa58b2 100644 --- a/types.d.ts +++ b/types.d.ts @@ -1,27 +1,73 @@ - type StringConcat< T1 extends string | number | bigint | boolean, - T2 extends string | number | bigint | boolean + T2 extends string | number | bigint | boolean, > = `${T1}${T2}`; -type MutableMethod = 'push' | 'slice' | 'sort' | 'unshift' | 'shift' | 'copyWithin' | 'pop' | 'fill' | 'splice' | 'reverse'; - -type ImplementedMethod = 'indexOf' | 'lastIndexOf' | 'mutable' | 'concat' | 'at' | 'withPrefix' | 'withSuffix' | 'toReversed' | 'toSorted'; - -type SupportedMethod = 'includes' | 'toSpliced' | 'length' | 'find' | 'findIndex' | 'some' | 'every' | 'filter'; - -type SupportedMethodWithNativeType = 'map' | 'reduce' | 'reduceRight' | 'entries' | 'keys' | 'values' | 'toLocaleString' | 'toString' | 'forEach' | 'flat' | 'flatMap' | 'join'; +type MutableMethod = + | 'push' + | 'slice' + | 'sort' + | 'unshift' + | 'shift' + | 'copyWithin' + | 'pop' + | 'fill' + | 'splice' + | 'reverse'; + +type ImplementedMethod = + | 'indexOf' + | 'lastIndexOf' + | 'mutable' + | 'concat' + | 'at' + | 'withPrefix' + | 'withSuffix' + | 'toReversed' + | 'toSorted'; + +type SupportedMethod = + | 'includes' + | 'toSpliced' + | 'length' + | 'find' + | 'findIndex' + | 'some' + | 'every' + | 'filter'; + +type SupportedMethodWithNativeType = + | 'map' + | 'reduce' + | 'reduceRight' + | 'entries' + | 'keys' + | 'values' + | 'toLocaleString' + | 'toString' + | 'forEach' + | 'flat' + | 'flatMap' + | 'join'; declare global { namespace isl { - - - interface ISL extends Omit, ImplementedMethod | MutableMethod | SupportedMethod> { + interface ISL + extends Omit< + Array, + ImplementedMethod | MutableMethod | SupportedMethod + > { toSorted(compareFn?: (a: T, b: T) => number): ISL; toReversed(): ISL; - concat(...arg: P[]): (ISL<(Record)[keyof (Record)] | PP>); - withPrefix

(prefix: P): T extends string ? ISL<(StringConcat)> : never; - withSuffix

(suffix: P): T extends string ? ISL<(StringConcat)> : never; + concat( + ...arg: P[] + ): ISL[keyof Record] | PP>; + withPrefix

( + prefix: P, + ): T extends string ? ISL> : never; + withSuffix

( + suffix: P, + ): T extends string ? ISL> : never; mutable(): string[]; at(n: number): T?; @@ -35,23 +81,44 @@ declare global { indexOf(searchElement: PP, fromIndex?: number): number; lastIndexOf(searchElement: PP, fromIndex?: number): number; - find(predictate: (val: PP extends T ? PP : string, i: number, obj: ISL) => val is PP): T; + find( + predictate: ( + val: PP extends T ? PP : string, + i: number, + obj: ISL, + ) => val is PP, + ): T; find(predictate: (val?: string, i: number, obj: ISL) => boolean): T; - findIndex(predictate: (val: PP extends T ? PP : string) => boolean): number; - findIndex(predictate: (val?: string, i: number, obj: ISL) => boolean): number; - - - some(predictate: (val: PP extends T ? PP : string) => boolean): boolean; - every(predictate: (val: PP extends T ? PP : string) => boolean): boolean; - + findIndex( + predictate: (val: PP extends T ? PP : string) => boolean, + ): number; + findIndex( + predictate: (val?: string, i: number, obj: ISL) => boolean, + ): number; + + some( + predictate: (val: PP extends T ? PP : string) => boolean, + ): boolean; + every( + predictate: (val: PP extends T ? PP : string) => boolean, + ): boolean; // Return Type overrides - filter(predicate: (value: T, index: number, array: ISL) => value is S, thisArg?: any): S[]; - filter(predicate: (value: string, index: number, array: ISL) => boolean, thisArg?: any): string[]; - toSpliced(start: number, deleteCount: number, ...items: string[]): string[]; + filter( + predicate: (value: T, index: number, array: ISL) => value is S, + thisArg?: any, + ): S[]; + filter( + predicate: (value: string, index: number, array: ISL) => boolean, + thisArg?: any, + ): string[]; + toSpliced( + start: number, + deleteCount: number, + ...items: string[] + ): string[]; } } } - -export { } +export { };