-
Notifications
You must be signed in to change notification settings - Fork 14
/
validation.ts
44 lines (39 loc) · 1.3 KB
/
validation.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
/**
* JavaScript and Node.js SDK for OpenFGA
*
* API version: 1.x
* Website: https://openfga.dev
* Documentation: https://openfga.dev/docs
* Support: https://openfga.dev/community
* License: [Apache-2.0](https://github.com/openfga/js-sdk/blob/main/LICENSE)
*
* NOTE: This file was auto generated by OpenAPI Generator (https://openapi-generator.tech). DO NOT EDIT.
*/
import { FgaRequiredParamError } from "./errors";
/**
*
* @throws { FgaRequiredParamError }
* @export
*/
export const assertParamExists = function (functionName: string, paramName: string, paramValue: unknown) {
if (paramValue === null || paramValue === undefined) {
throw new FgaRequiredParamError(functionName, paramName, `Required parameter ${paramName} was null or undefined when calling ${functionName}.`);
}
};
/**
*
* @export
*/
export const isWellFormedUriString = (uri: string): boolean => {
try {
const uriResult = new URL(uri);
return ((uriResult.toString() === uri || uriResult.toString() === `${uri}/`) &&
(uriResult.protocol === "https:" || uriResult.protocol === "http:"));
} catch (err) {
return false;
}
};
export const isWellFormedUlidString = (ulid: string): boolean => {
const regex = /^[0-7][0-9A-HJKMNP-TV-Z]{25}$/;
return !!(typeof ulid === "string" && ulid.match(regex)?.length);
};