UNPKG

@baqhub/sdk

Version:

The official JavaScript SDK for the BAQ federated app platform.

29 lines (28 loc) 972 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.FileName = void 0; function parseFileName(fileName) { const fileNameRegexp = /^(.+?)(\.[^.]+)?$/; const [, name, extension] = fileName.match(fileNameRegexp) || ["", "", ""]; return [name, extension]; } const allowedCharacter = "a-zA-Z0-9. ()[\\]{}()_-"; const disallowedCharacterRegexp = new RegExp(`[^${allowedCharacter}]`, "g"); const validFileNameRegexp = new RegExp(`^(?!([.]+$))[${allowedCharacter}]+$`); function isValidFileName(fileName) { return Boolean(fileName.match(validFileNameRegexp)); } function normalizeFileName(fileName) { const normalizedFileName = fileName .replaceAll(disallowedCharacterRegexp, "") .trim(); if (!isValidFileName(normalizedFileName)) { return null; } return normalizedFileName; } exports.FileName = { parse: parseFileName, isValid: isValidFileName, normalize: normalizeFileName, };