{"version":3,"file":"path.cjs","names":["escapeRegExp"],"sources":["../../../src/common/data/path.ts"],"sourcesContent":["// https://github.com/sindresorhus/filenamify/blob/main/filenamify.js\n/* eslint-disable no-control-regex */\n\nimport { escapeRegExp } from './regexp'\n\nconst MAX_FILENAME_LENGTH = 100\n\n// const reControlChars = /[\\u0000-\\u001F\\u0080-\\u009F]/g\nconst reRelativePath = /^\\.+/\nconst reTrailingPeriods = /\\.+$/\nconst reFilenameIllegal = /[<>:\"/\\\\|?*\\u0000-\\u001F\\u0080-\\u009F]+/g // https://superuser.com/questions/358855/what-characters-are-safe-in-cross-platform-file-names-for-linux-windows-and-os/358861#358861\n\nfunction filenameReservedRegex() {\n  return reFilenameIllegal // /[<>:\"/\\\\|?*\\u0000-\\u001F]/g\n}\n\nfunction windowsReservedNameRegex() {\n  return /^(con|prn|aux|nul|com\\d|lpt\\d)$/i\n}\n\n/** Ensure a valid file name. Unsupported characters get a `replacement`, default: `_` */\nexport function toValidFilename(string: string, replacement = '_'): string | never {\n  if (typeof string !== 'string')\n    throw new TypeError('Expected a string')\n\n  if (filenameReservedRegex().test(replacement))\n    throw new Error('Replacement string cannot contain reserved filename characters')\n\n  const reReplacement = `(${escapeRegExp(replacement)})+`\n\n  string = string\n    .replace(filenameReservedRegex(), replacement)\n    .replace(reRelativePath, replacement)\n    .replace(reTrailingPeriods, '')\n    .replace(new RegExp(reReplacement, 'gm'), replacement) // collapse\n    .trim()\n\n  string = windowsReservedNameRegex().test(string) ? string + replacement : string\n\n  return string.slice(0, MAX_FILENAME_LENGTH)\n}\n"],"mappings":";;;;AAKA,MAAM,sBAAsB;AAG5B,MAAM,iBAAiB;AACvB,MAAM,oBAAoB;AAC1B,MAAM,oBAAoB;AAE1B,SAAS,wBAAwB;AAC/B,QAAO;;AAGT,SAAS,2BAA2B;AAClC,QAAO;;;AAIT,SAAgB,gBAAgB,QAAgB,cAAc,KAAqB;AACjF,KAAI,OAAO,WAAW,SACpB,OAAM,IAAI,UAAU,oBAAoB;AAE1C,KAAI,uBAAuB,CAAC,KAAK,YAAY,CAC3C,OAAM,IAAI,MAAM,iEAAiE;CAEnF,MAAM,gBAAgB,IAAIA,wCAAa,YAAY,CAAC;AAEpD,UAAS,OACN,QAAQ,uBAAuB,EAAE,YAAY,CAC7C,QAAQ,gBAAgB,YAAY,CACpC,QAAQ,mBAAmB,GAAG,CAC9B,QAAQ,IAAI,OAAO,eAAe,KAAK,EAAE,YAAY,CACrD,MAAM;AAET,UAAS,0BAA0B,CAAC,KAAK,OAAO,GAAG,SAAS,cAAc;AAE1E,QAAO,OAAO,MAAM,GAAG,oBAAoB"}