-
-
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.
✨ Add String.trimStart and String.trimEnd functions
- Loading branch information
1 parent
5b6c8c3
commit 08bd098
Showing
5 changed files
with
129 additions
and
20 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
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,54 @@ | ||
// Copyright 2021-present the Core-fn authors. All rights reserved. MIT license. | ||
import { Space } from "../deps.ts"; | ||
|
||
/** | ||
* Infer the string with the right ends of trimmed. | ||
* | ||
* @typeParam T - Any string | ||
* @returns String right ends of trimmed | ||
* | ||
* @remarks | ||
* The definition of space | ||
* - `''` | ||
* - `\n` | ||
* - `\t` | ||
* | ||
* @example | ||
* ```ts | ||
* TrimEnd<'hello \n\t'> // 'hello' | ||
* ``` | ||
* | ||
* @category `String` | ||
* | ||
* @beta | ||
*/ | ||
type TrimEnd<T extends string> = T extends `${infer R}${Space}` ? TrimEnd<R> | ||
: T; | ||
|
||
/** | ||
* Removes space from right ends of the string. | ||
* | ||
* @param val - input string | ||
* @returns The result of `val.trimEnd()` | ||
* | ||
* @remarks | ||
* The definition of space | ||
* - `''` | ||
* - `\n` | ||
* - `\t` | ||
* | ||
* @example | ||
* ```ts | ||
* trimEnd('hello ') // 'hello' | ||
* trimEnd('hello \n\t') // 'hello' | ||
* ``` | ||
* | ||
* @category `String` | ||
* | ||
* @beta | ||
*/ | ||
const trimEnd = <T extends string>(val: T): TrimEnd<T> => | ||
val.trimEnd() as TrimEnd<T>; | ||
|
||
export { trimEnd }; | ||
export type { TrimEnd }; |
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,53 @@ | ||
// Copyright 2021-present the Core-fn authors. All rights reserved. MIT license. | ||
import { Space } from "../deps.ts"; | ||
|
||
/** | ||
* Infer the string with the left ends of trimmed. | ||
* | ||
* @returns String left ends of trimmed | ||
* | ||
* @remarks | ||
* The definition of space | ||
* - `''` | ||
* - `\n` | ||
* - `\t` | ||
* | ||
* @example | ||
* ```ts | ||
* TrimStart<' \n\thello'> // 'hello' | ||
* ``` | ||
* | ||
* @category `String` | ||
* | ||
* @beta | ||
*/ | ||
type TrimStart<T extends string> = T extends `${Space}${infer R}` ? TrimStart<R> | ||
: T; | ||
|
||
/** | ||
* Removes the leading white space and line terminator characters from a string. | ||
* | ||
* @param val - input string | ||
* @returns The result of `val.trimStart()` | ||
* | ||
* @remarks | ||
* The definition of space | ||
* - `''` | ||
* - `\n` | ||
* - `\t` | ||
* | ||
* @example | ||
* ```ts | ||
* trimStart(' hello') // 'hello' | ||
* trimStart(' \n\thello') // 'hello' | ||
* ``` | ||
* | ||
* @category `String` | ||
* | ||
* @beta | ||
*/ | ||
const trimStart = <T extends string>(val: T): TrimStart<T> => | ||
val.trimStart() as TrimStart<T>; | ||
|
||
export { trimStart }; | ||
export type { TrimStart }; |
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