Skip to content

Commit

Permalink
馃 Merge PR #69629 [purify] Add package purify by @ffflorian
Browse files Browse the repository at this point in the history
  • Loading branch information
ffflorian committed May 18, 2024
1 parent 2352fc2 commit bf6faab
Show file tree
Hide file tree
Showing 5 changed files with 125 additions and 0 deletions.
5 changes: 5 additions & 0 deletions types/purify/.npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
*
!**/*.d.ts
!**/*.d.cts
!**/*.d.mts
!**/*.d.*.ts
42 changes: 42 additions & 0 deletions types/purify/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
export as namespace purify;

export function alphaNumeric<T = string>(rawValue: string | number, defaultValue?: T): string | T;
export function alphaNumericWithDot<T = string>(rawValue: string | number, defaultValue?: T): string | T;
export function boolean(rawValue: boolean | string, defaultValue?: boolean): boolean;
export function domain<T = string>(rawValue: string, defaultValue?: T): string | T;
export function domainIdn<T = string>(rawValue: string, defaultValue?: T): string | T;
export function email<T = string>(rawValue: string, defaultValue?: T): string | T;
export function emailIdn<T = string>(rawValue: string, defaultValue?: T): string | T;
export function float<T = number>(rawValue: string | number, defaultValue?: T): number | T;
export function integer<T = any>(rawValue: string | number, defaultValue?: T): number | T;
export function integerInRange<T = number>(
rawValue: string | number,
lower: number,
upper: number,
defaultValue?: T,
): number | T;
export function json<T = any>(rawValue: string, defaultValue?: T): T;
export function lowerCaseUuid<T = string>(rawValue: string, defaultValue?: T): string | T;
export function nonEmptyAlphaNumeric<T = string>(rawValue: string | number, defaultValue?: T): string | T;
export function nonEmptyAlphaNumericWithDot<T = string>(rawValue: string | number, defaultValue?: T): string | T;
export function nonEmptyPrintableAscii<T = string>(rawValue: string, defaultValue?: T): string | T;
export function nonEmptyPrintableUnicode<T = string>(rawValue: string, defaultValue?: T): string | T;
export function nonEmptyVisibleAscii<T = string>(rawValue: string, defaultValue?: T): string | T;
export function nonEmptyVisibleUnicode<T = string>(rawValue: string, defaultValue?: T): string | T;
export function positiveFloat<T = number>(rawValue: string | number, defaultValue?: T): number | T;
export function positiveFloatOrZero<T = number>(rawValue: string | number, defaultValue?: T): number | T;
export function positiveInteger<T = number>(rawValue: string | number, defaultValue?: T): number | T;
export function positiveIntegerOrZero<T = number>(rawValue: string | number, defaultValue?: T): number | T;
export function printableAscii<T = string>(rawValue: string, defaultValue?: T): string | T;
export function printableUnicode<T = string>(rawValue: string, defaultValue?: T): string | T;
export function upperCaseUuid<T = string>(rawValue: string, defaultValue?: T): string | T;
export function url<T = string>(rawValue: string, defaultValue?: T): string | T;
export function urlWithLocalhost<T = string>(rawValue: string, defaultValue?: T): string | T;
export function uuid<T = string>(rawValue: string, defaultValue?: T): string | T;
export function visibleAscii<T = string>(rawValue: string, defaultValue?: T): string | T;
export function visibleUnicode<T = string>(rawValue: string, defaultValue?: T): string | T;

export const domainName: typeof domain;
export const domainNameIdn: typeof domainIdn;
export const emailAddress: typeof email;
export const emailAddressIdn: typeof emailIdn;
17 changes: 17 additions & 0 deletions types/purify/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"private": true,
"name": "@types/purify",
"version": "3.5.9999",
"projects": [
"https://github.com/One-com/purify#readme"
],
"devDependencies": {
"@types/purify": "workspace:."
},
"owners": [
{
"name": "Florian Imdahl",
"githubUsername": "ffflorian"
}
]
}
42 changes: 42 additions & 0 deletions types/purify/purify-tests.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import * as purify from "purify";

purify.alphaNumeric("hello", "world"); // $ExpectType string
purify.alphaNumericWithDot("hello", "world"); // $ExpectType string
purify.boolean("true"); // $ExpectType boolean
// @ts-expect-error
purify.boolean("true", "default");
purify.domainName("example.com");
purify.domainNameIdn("example.com"); // $ExpectType string
purify.email("hello@example.com", "mail@example.com"); // $ExpectType string
purify.emailIdn("hello@example.com", "mail@example.com"); // $ExpectType string
purify.float("10", 0); // $ExpectType number
purify.integer(-5, "world"); // $ExpectType number | "world"
purify.integerInRange("100", 0, 10); // $ExpectType number
purify.json<{ hello: string }>("{\"hello\": \"world\"}"); // $ExpectType {hello: string}
purify.lowerCaseUuid("693563fb-77c2-42f1-be5c-f302f98dc919", false); // $ExpectType string | false
purify.nonEmptyAlphaNumeric("hello", "world"); // $ExpectType string
purify.nonEmptyPrintableAscii("hello", "world"); // $ExpectType string
purify.nonEmptyPrintableUnicode("hello", false); // $ExpectType string | false
purify.nonEmptyVisibleAscii("hello", "world"); // $ExpectType string
purify.nonEmptyVisibleUnicode("hello", "world"); // $ExpectType string
purify.positiveFloat("hello", "world"); // $ExpectType number | "world"
purify.positiveFloatOrZero("hello", false); // $ExpectType number | false
purify.positiveInteger("10", "10"); // $ExpectType number | "10"
purify.positiveInteger("10", 5); // $ExpectType number
purify.positiveInteger("10"); // $ExpectType number
// @ts-expect-error
purify.positiveInteger(false);
purify.positiveInteger(-10, 1); // $ExpectType number
purify.positiveIntegerOrZero(100); // $ExpectType number
purify.printableAscii("hello", "world"); // $ExpectType string
// @ts-expect-error
purify.printableAscii(100, "world");
purify.printableUnicode("hello", "world"); // $ExpectType string
purify.upperCaseUuid("E9DC6DBC-A1E1-46B0-948C-6A7DD760D7DA", "world"); // $ExpectType string
purify.url("http://example.com", "world"); // $ExpectType string
purify.urlWithLocalhost("http://example.com", "world");
purify.uuid("e92623af-9769-4477-9ff4-d98a7c3677f0", false); // $ExpectType string | false
purify.visibleAscii("hello"); // $ExpectType string
// @ts-expect-error
purify.visibleAscii(false); // $ExpectType string
purify.visibleUnicode("hello", "world"); // $ExpectType string
19 changes: 19 additions & 0 deletions types/purify/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"compilerOptions": {
"module": "node16",
"lib": [
"es6"
],
"noImplicitAny": true,
"noImplicitThis": true,
"strictFunctionTypes": true,
"strictNullChecks": true,
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true
},
"files": [
"index.d.ts",
"purify-tests.ts"
]
}

0 comments on commit bf6faab

Please sign in to comment.