-
-
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.
- Loading branch information
1 parent
4dabc80
commit ed088ba
Showing
8 changed files
with
107 additions
and
80 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,87 @@ | ||
// Copyright 2021-present the Fonction authors. All rights reserved. MIT license. | ||
import { slice } from '../deps.ts' | ||
|
||
/** | ||
* @example | ||
* ```ts | ||
* InitString<string> // string | ||
* InitString<''> // '' | ||
* InitString<'a'> // '' | ||
* InitString<'ab'> // 'a' | ||
* InitString<'abcd'> // 'abc' | ||
* ``` | ||
* @internal | ||
*/ | ||
type InitString<T extends string> = T extends `${infer F}${infer R}` | ||
? R extends '' | ||
? '' | ||
: `${F}${InitString<R>}` | ||
: T extends '' | ||
? '' | ||
: string | ||
|
||
/** | ||
* Infer the init types. | ||
* @typeParam T - `string` or any `array` | ||
* | ||
* @example | ||
* ```ts | ||
* // String | ||
* Init<string> // string | ||
* Init<''> // '' | ||
* Init<'hello'> // 'hell' | ||
* ``` | ||
* | ||
* @example | ||
* ```ts | ||
* // Array | ||
* Init<[] | never[] | readonly [] | readonly never[]> // [] | ||
* Init<['hello', 'world']> // 'hello' | ||
* ``` | ||
* | ||
* @category `Array` `String` | ||
* | ||
* @see Related to {@link First} | ||
* | ||
* @public | ||
*/ | ||
type Init<T extends string | readonly unknown[]> = T extends string | ||
? InitString<T> | ||
: T extends readonly never[] | [] | ||
? [] | ||
: T extends readonly [...infer I, unknown] | ||
? I | ||
: T | ||
|
||
/** | ||
* Returns all but the init element of the given list or string. | ||
* @param val - string or any array object | ||
* @returns The result of `val.slice(0, -1)` | ||
* | ||
* @example | ||
* ```ts | ||
* // String | ||
* init('hello') // 'hell' | ||
* init('h') // '' | ||
* init('') // '' | ||
* ``` | ||
* | ||
* @example | ||
* ```ts | ||
* init([1, 2, 3]) // [1, 2] | ||
* init(['hello', 'world']) // ['hello'] | ||
* init(['hello']) // [] | ||
* init([]) // [] | ||
* ``` | ||
* | ||
* @category `Array` `String` | ||
* | ||
* @see Related to {@link tail} | ||
* | ||
* @public | ||
*/ | ||
const init = <T extends string | readonly unknown[]>(val: T): Init<T> => | ||
slice(0, -1, val) as Init<T> | ||
|
||
export { init } | ||
export type { Init } |
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 |
---|---|---|
@@ -1,5 +1,7 @@ | ||
// Copyright 2021-present the Fonction authors. All rights reserved. MIT license. | ||
export type { Head } from './head.ts' | ||
export { head } from './head.ts' | ||
export type { Init } from './init.ts' | ||
export { init } from './init.ts' | ||
export type { Last } from './last.ts' | ||
export { last } from './last.ts' |
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,5 +1,6 @@ | ||
// Copyright 2021-present the Fonction authors. All rights reserved. MIT license. | ||
export { length } from 'https://deno.land/x/[email protected]/mod.ts' | ||
export { length } from 'https://deno.land/x/[email protected]/mod.ts' | ||
export { slice } from 'https://deno.land/x/[email protected]/uncurry/common/slice.ts' | ||
export { curry } from 'https://deno.land/x/[email protected]/mod.ts' | ||
export { equal } from 'https://deno.land/x/[email protected]/mod.ts' | ||
export { | ||
|
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,8 +1,12 @@ | ||
// Copyright 2021-present the Fonction authors. All rights reserved. MIT license. | ||
/* eslint-disable @typescript-eslint/no-empty-function */ | ||
/* eslint-disable @typescript-eslint/no-unused-vars */ | ||
|
||
export { | ||
assert, | ||
assertEquals | ||
} from 'https://deno.land/[email protected]/testing/asserts.ts' | ||
export const assertEqualsType = <T, U extends T = T>(_actual?: U): void => {} | ||
export { length } from 'https://deno.land/x/[email protected]/mod.ts' | ||
export { | ||
isNumber, | ||
|
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 was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.