uuid#validate TypeScript Examples

The following examples show how to use uuid#validate. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: common.ts    From denote-md-backend with MIT License 6 votes vote down vote up
CreateUuidField = (name: string, location: TLocation = 'params'): IField => {
  return {
    name,
    location,
    type: 'string',
    require: true,
    validator: (v: string) => validate(v),
    message: `Invalid UUID value`,
  };
}
Example #2
Source File: generateId.ts    From Nishan with MIT License 6 votes vote down vote up
/**
 * Generates notion specific id, using the passed id or a new one
 * @param id The optional id that would be returned if its valid
 */
export function generateId (id?: string) {
	if (id) {
		// Checks if the passed id is valid or not
		// transform to regular id then back to uuid to validate
		const is_valid = validate(NotionIdz.Transform.toUuid(NotionIdz.Transform.toId(id)));
		// if valid no point in creating a new one, return it
		if (is_valid) return id;
		else {
			// else if the passed id is not valid, log to console and return a mew one
			console.log('Invalid uuid provided');
			return v4();
		}
		// if no id parameter was passed return a new id
	} else return v4();
}
Example #3
Source File: FileService.ts    From node-experience with MIT License 6 votes vote down vote up
async getPresignedGetObject(payload: PresignedFileRepPayload): Promise<string>
    {
        const filename = payload.name;
        const expiry = payload.expiry;
        const isPublic = payload.isPublic;
        let file: IFileDomain;

        if (validate(filename))
        {
            file = await this.getOne(filename);
        }
        else
        {
            file = await this.repository.getOneBy({ filename, isPublic });
        }

        return await this.getFileUrl(file, expiry);
    }
Example #4
Source File: request-id.middleware.ts    From nestjs-starter-rest-api with MIT License 6 votes vote down vote up
RequestIdMiddleware = (
  req: Request,
  res: Response,
  next: () => void,
): void => {
  /** set request id, if not being set yet */
  if (
    !req.headers[REQUEST_ID_TOKEN_HEADER] ||
    !validate(req.header(REQUEST_ID_TOKEN_HEADER))
  ) {
    req.headers[REQUEST_ID_TOKEN_HEADER] = uuidv4();
  }

  /** set res id in response from req */
  res.set(REQUEST_ID_TOKEN_HEADER, req.headers[REQUEST_ID_TOKEN_HEADER]);
  next();
}
Example #5
Source File: uuid.value-object.ts    From domain-driven-hexagon with MIT License 5 votes vote down vote up
protected validate({ value }: DomainPrimitive<string>): void {
    if (!validate(value)) {
      throw new ArgumentInvalidException('Incorrect UUID format');
    }
  }
Example #6
Source File: twee-project.ts    From twee3-language-tools with MIT License 5 votes vote down vote up
export async function tweeProjectConfig(context: vscode.ExtensionContext) {
	const passages = (context.workspaceState.get("passages", []) as Passage[]);
	const storyDataPassage = passages.find(p => p.name === "StoryData");

	if (storyDataPassage) {
		let data: StoryData;
		try {
			data = JSON.parse(await storyDataPassage.getContent());

			const errors: string[] = [];

			if (!data.ifid) errors.push("IFID not found!");
			else if (!validate(data.ifid)) errors.push("Invalid IFID!");

			const storyDataErrorConfig = vscode.workspace.getConfiguration("twee3LanguageTools.twee-3.error.storyData");

			if (!data.format && storyDataErrorConfig.get("format")) errors.push("Story Format name not found!");
			if (!data["format-version"] && storyDataErrorConfig.get("formatVersion")) errors.push("Story Format version not found!");

			if (errors.length) throw errors;

			context.workspaceState.update("StoryData", data);
		} catch (errors) {
			if (errors instanceof Array) errors.forEach((err: string) => vscode.window.showErrorMessage("Malformed StoryData: " + err));
			else vscode.window.showErrorMessage("Malformed StoryData JSON: " + (errors as Error).message);
	
			return;
		}

		let format = data.format.toLowerCase() + "-" + data["format-version"].split(".")[0];

		/* SC v3 - v2 alias hook */
		if (format === "sugarcube-3") format = "sugarcube-2";
		/* will be removed when v2 doesn't work for v3 anymore (>_<) */

		const config = vscode.workspace.getConfiguration("twee3LanguageTools.storyformat");
		if (config.get("current") !== format) {
			await config.update("current", format)
			vscode.window.showInformationMessage("Storyformat set to " + format);
		}
	}
}