-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from rawpixel-vincent/test-ci
clean tests, exports and ci
- Loading branch information
Showing
14 changed files
with
6,961 additions
and
606 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{ | ||
"env": { | ||
"browser": true, | ||
"es6": true, | ||
"node": true | ||
}, | ||
"extends": ["eslint:recommended", "prettier"], | ||
"overrides": [], | ||
"parserOptions": { | ||
"ecmaVersion": 14, | ||
"sourceType": "module" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
name: tests | ||
|
||
on: | ||
push: | ||
branches: ['main'] | ||
pull_request: | ||
branches: ['main'] | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
|
||
strategy: | ||
matrix: | ||
node-version: ['20', 'latest'] | ||
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/ | ||
|
||
steps: | ||
- uses: actions/checkout@v4 | ||
- name: Use Node.js ${{ matrix.node-version }} | ||
uses: actions/setup-node@v4 | ||
with: | ||
node-version: ${{ matrix.node-version }} | ||
cache: 'npm' | ||
- run: npm install --include=dev | ||
- run: npm run test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
node_modules | ||
node_modules | ||
.tap |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"printWidth": 80, | ||
"singleQuote": true, | ||
"trailingComma": "all" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
import { sl } from './types.js'; | ||
|
||
export interface IStringList<T extends unknown> | ||
extends Omit< | ||
Array<T>, | ||
| sl.specs.ImplementedMethod | ||
| sl.specs.OmitedMutableMethod | ||
| sl.specs.NativeMethodWithTypeOverride | ||
> { | ||
// Custom Methods | ||
withPrefix<P extends string>( | ||
prefix: P, | ||
): IStringList<sl.utils.StringConcat<P, T extends string ? T : string>>; | ||
withSuffix<P extends string>( | ||
suffix: P, | ||
): IStringList<sl.utils.StringConcat<T extends string ? T : string, P>>; | ||
mutable(): string[]; | ||
|
||
// Implemented methods to return the frozen array, typed as IStringList. | ||
toSorted(compareFn?: (a: T, b: T) => number): IStringList<T>; | ||
toReversed(): IStringList<T>; | ||
concat<PP extends T, P extends string = string>( | ||
...arg: P[] | ||
): IStringList<Record<P, P>[keyof Record<P, P>] | PP>; | ||
|
||
// Readonly overrides | ||
readonly length: number; | ||
readonly [n: number]: T | undefined; | ||
|
||
// Supported Methods | ||
at(n: number): T; | ||
|
||
// Type override to prevent string not in type T issue | ||
includes<PP = T>(val: PP, fromIndex?: number): boolean; | ||
indexOf<PP = T>(searchElement: PP, fromIndex?: number): number; | ||
lastIndexOf<PP = T>(searchElement: PP, fromIndex?: number): number; | ||
|
||
find<PP = T>( | ||
predictate: ( | ||
val: PP extends T ? T : PP, | ||
i: number, | ||
obj: IStringList<T>, | ||
) => val is PP extends T ? T : PP, | ||
): T; | ||
find( | ||
predictate: ( | ||
val: string | undefined, | ||
i: number, | ||
obj: IStringList<T>, | ||
) => boolean, | ||
): T; | ||
findIndex<PP = T>( | ||
predictate: (val: PP extends T ? PP : string) => boolean, | ||
): number; | ||
findIndex( | ||
predictate: ( | ||
val: string | undefined, | ||
i: number, | ||
obj: IStringList<T>, | ||
) => boolean, | ||
): number; | ||
|
||
some<PP = T>( | ||
predictate: (val: PP extends T ? PP : string) => boolean, | ||
): boolean; | ||
every<PP = T>( | ||
predictate: (val: PP extends T ? PP : string) => boolean, | ||
): boolean; | ||
|
||
// Return Type overrides | ||
filter<S extends T>( | ||
predicate: (value: T, index: number, array: IStringList<T>) => value is S, | ||
thisArg?: any, | ||
): S[]; | ||
filter( | ||
predicate: (value: string, index: number, array: IStringList<T>) => boolean, | ||
thisArg?: any, | ||
): string[]; | ||
toSpliced(start: number, deleteCount: number, ...items: string[]): string[]; | ||
} | ||
|
||
export class StringLiteralList<T extends string> { | ||
constructor(...list: T[]); | ||
} | ||
|
||
export interface ArrayInPlaceMutation { | ||
push: 'push'; | ||
slice: 'slice'; | ||
sort: 'sort'; | ||
unshift: 'unshift'; | ||
shift: 'shift'; | ||
copyWithin: 'copyWithin'; | ||
pop: 'pop'; | ||
fill: 'fill'; | ||
splice: 'splice'; | ||
reverse: 'reverse'; | ||
} | ||
|
||
export const ARRAY_IN_PLACE_MUTATION: ArrayInPlaceMutation; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
export class StringLiteralList extends Array { | ||
concat() { | ||
return Object.freeze( | ||
new StringLiteralList(...super.concat.apply(this, arguments)), | ||
); | ||
} | ||
|
||
toSorted() { | ||
return Object.freeze( | ||
new StringLiteralList(...super.toSorted.apply(this, arguments)), | ||
); | ||
} | ||
|
||
toReversed() { | ||
return Object.freeze( | ||
new StringLiteralList(...super.toReversed.apply(this, arguments)), | ||
); | ||
} | ||
|
||
withPrefix(prefix) { | ||
return Object.freeze( | ||
new StringLiteralList(...super.map((e) => `${prefix}${e}`)), | ||
); | ||
} | ||
|
||
withSuffix(suffix) { | ||
return Object.freeze( | ||
new StringLiteralList(...super.map((e) => `${e}${suffix}`)), | ||
); | ||
} | ||
|
||
// Get the native array | ||
mutable() { | ||
return Array.from(this); | ||
} | ||
|
||
// Methods returning the native array | ||
map() { | ||
const mut = this.mutable(); | ||
return mut.map.apply(mut, arguments); | ||
} | ||
filter() { | ||
const mut = this.mutable(); | ||
return mut.filter.apply(mut, arguments); | ||
} | ||
reduce() { | ||
const mut = this.mutable(); | ||
return mut.reduce.apply(mut, arguments); | ||
} | ||
reduceRight() { | ||
const mut = this.mutable(); | ||
return mut.reduceRight.apply(mut, arguments); | ||
} | ||
flat() { | ||
const mut = this.mutable(); | ||
return mut.flat.apply(mut, arguments); | ||
} | ||
flatMap() { | ||
const mut = this.mutable(); | ||
return mut.flatMap.apply(mut, arguments); | ||
} | ||
toSpliced() { | ||
const mut = this.mutable(); | ||
return mut.toSpliced.apply(mut, arguments); | ||
} | ||
} | ||
|
||
export const ARRAY_IN_PLACE_MUTATION = Object.freeze({ | ||
push: 'push', | ||
slice: 'slice', | ||
sort: 'sort', | ||
unshift: 'unshift', | ||
shift: 'shift', | ||
copyWithin: 'copyWithin', | ||
pop: 'pop', | ||
fill: 'fill', | ||
splice: 'splice', | ||
reverse: 'reverse', | ||
}); | ||
Object.values(ARRAY_IN_PLACE_MUTATION).forEach((el) => { | ||
StringLiteralList.prototype[el] = () => { | ||
throw new Error(`Array method ${el} is not supported by StringLiteralList`); | ||
}; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.