-
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.
feat: added stripParenthesis(val) utility
- Loading branch information
1 parent
a96c31c
commit 45c989d
Showing
11 changed files
with
101 additions
and
55 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
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
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,15 @@ | ||
import { stripLeading, stripTrailing } from "inferred-types/dist/runtime/index" | ||
import { StripSurround, Trim } from "inferred-types/dist/types/index" | ||
|
||
|
||
/** | ||
* **stripParenthesis**`(val)` | ||
* | ||
* A runtime utility which strips leading and trailing whitespace as well | ||
* as any leading or trailing parenthesis characters. | ||
*/ | ||
export const stripParenthesis = < | ||
T extends string | ||
>(val: T) => { | ||
return stripTrailing(stripLeading(val.trim(), "("), ")").trim() as unknown as Trim<StripSurround<Trim<T>, "("|")">> | ||
} |
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
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
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,29 @@ | ||
import { Equal, Expect } from "@type-challenges/utils"; | ||
import { describe, expect, it } from "vitest"; | ||
import { stripParenthesis } from "inferred-types"; | ||
|
||
// Note: while type tests clearly fail visible inspection, they pass from Vitest | ||
// standpoint so always be sure to run `tsc --noEmit` over your test files to | ||
// gain validation that no new type vulnerabilities have cropped up. | ||
|
||
describe("stripParenthesis(val)", () => { | ||
|
||
it("happy path", () => { | ||
const t1 = stripParenthesis("foo bar"); | ||
const t2 = stripParenthesis("(foo bar)"); | ||
const t3 = stripParenthesis(" (foo bar) "); | ||
|
||
expect(t1).toEqual("foo bar"); | ||
expect(t2).toEqual("foo bar"); | ||
expect(t3).toEqual("foo bar"); | ||
|
||
|
||
// @ts-ignore | ||
type cases = [ | ||
Expect<Equal<typeof t1, "foo bar">>, | ||
Expect<Equal<typeof t2, "foo bar">>, | ||
Expect<Equal<typeof t3, "foo bar">>, | ||
]; | ||
}); | ||
|
||
}); |