swc/bundler/tests/.cache/untrusted/38301ffafa532c11f9fe7d936fc884ef4a4c4059.ts
강동윤 bbaf619f63
fix(bundler): Fix bugs (#1437)
swc_bundler:
 - [x] Fix wrapped esms. (denoland/deno#9307)
 - [x] Make test secure.
2021-03-02 17:33:03 +09:00

64 lines
1.6 KiB
TypeScript

// Loaded from https://raw.githubusercontent.com/colinhacks/zod/654680afc2ede388e71e09104eac5a0088fe3207/deno/lib/helpers/util.ts
export const INVALID = Symbol("invalid_data");
export namespace util {
export type AssertEqual<T, Expected> = T extends Expected
? Expected extends T
? true
: false
: false;
export function assertNever(_x: never): never {
throw new Error();
}
export type Omit<T, K extends keyof T> = Pick<T, Exclude<keyof T, K>>;
export type OmitKeys<T, K extends string> = Pick<T, Exclude<keyof T, K>>;
export type MakePartial<T, K extends keyof T> = Omit<T, K> &
Partial<Pick<T, K>>;
export const arrayToEnum = <T extends string, U extends [T, ...T[]]>(
items: U
): { [k in U[number]]: k } => {
const obj: any = {};
for (const item of items) {
obj[item] = item;
}
return obj as any;
};
export const getValidEnumValues = (obj: any) => {
const validKeys = Object.keys(obj).filter(
(k: any) => typeof obj[obj[k]] !== "number"
);
const filtered: any = {};
for (const k of validKeys) {
filtered[k] = obj[k];
}
return getValues(filtered);
};
export const getValues = (obj: any) => {
return Object.keys(obj).map(function (e) {
return obj[e];
});
};
export const objectValues = (obj: any) => {
return Object.keys(obj).map(function (e) {
return obj[e];
});
};
export const find = <T>(
arr: T[],
checker: (arg: T) => any
): T | undefined => {
for (const item of arr) {
if (checker(item)) return item;
}
return undefined;
};
}