{"version":3,"file":"getRelativePath-WX4HB169.cjs","names":[],"sources":["../src/utils/trimExtName.ts","../src/parsers/defineParser.ts","../src/utils/getRelativePath.ts"],"sourcesContent":["export function trimExtName(text: string): string {\n  return text.replace(/\\.[^/.]+$/, '')\n}\n","import type { Parser, UserParser } from './types.ts'\n\n/**\n * Defines a Fabric parser with type safety.\n *\n * Use this function to create parsers that transform files based on\n * their extension.\n *\n * @param parser - The parser configuration object\n * @returns A typed parser ready to use with Fabric\n *\n * @example\n * ```ts\n * import { defineParser } from '@kubb/fabric-core'\n *\n * export const jsonParser = defineParser({\n *   name: 'json-parser',\n *   extensions: ['.json'],\n *   async parse(source, meta) {\n *     const data = JSON.parse(source)\n *     return data\n *   }\n * })\n * ```\n */\nexport function defineParser<TOptions = unknown, TMeta extends object = any>(parser: UserParser<TOptions, TMeta>): Parser<TOptions, TMeta> {\n  return {\n    type: 'parser',\n    ...parser,\n  }\n}\n","import { normalize, relative } from 'node:path'\n\nfunction slash(path: string, platform: 'windows' | 'mac' | 'linux' = 'linux') {\n  const isWindowsPath = /^\\\\\\\\\\?\\\\/.test(path)\n  const normalizedPath = normalize(path)\n\n  if (['linux', 'mac'].includes(platform) && !isWindowsPath) {\n    // linux and mac\n    return normalizedPath.replaceAll(/\\\\/g, '/').replace('../', '')\n  }\n\n  // windows\n  return normalizedPath.replaceAll(/\\\\/g, '/').replace('../', '')\n}\n\nexport function getRelativePath(rootDir?: string | null, filePath?: string | null, platform: 'windows' | 'mac' | 'linux' = 'linux'): string {\n  if (!rootDir || !filePath) {\n    throw new Error(`Root and file should be filled in when retrieving the relativePath, ${rootDir || ''} ${filePath || ''}`)\n  }\n\n  const relativePath = relative(rootDir, filePath)\n\n  // On Windows, paths are separated with a \"\\\"\n  // However, web browsers use \"/\" no matter the platform\n  const slashedPath = slash(relativePath, platform)\n\n  if (slashedPath.startsWith('../')) {\n    return slashedPath\n  }\n\n  return `./${slashedPath}`\n}\n"],"mappings":";;;AAAA,SAAgB,YAAY,MAAsB;AAChD,QAAO,KAAK,QAAQ,aAAa,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;ACwBtC,SAAgB,aAA6D,QAA8D;AACzI,QAAO;EACL,MAAM;EACN,GAAG;EACJ;;;;AC3BH,SAAS,MAAM,MAAc,WAAwC,SAAS;CAC5E,MAAM,gBAAgB,YAAY,KAAK,KAAK;CAC5C,MAAM,kBAAA,GAAA,UAAA,WAA2B,KAAK;AAEtC,KAAI,CAAC,SAAS,MAAM,CAAC,SAAS,SAAS,IAAI,CAAC,cAE1C,QAAO,eAAe,WAAW,OAAO,IAAI,CAAC,QAAQ,OAAO,GAAG;AAIjE,QAAO,eAAe,WAAW,OAAO,IAAI,CAAC,QAAQ,OAAO,GAAG;;AAGjE,SAAgB,gBAAgB,SAAyB,UAA0B,WAAwC,SAAiB;AAC1I,KAAI,CAAC,WAAW,CAAC,SACf,OAAM,IAAI,MAAM,uEAAuE,WAAW,GAAG,GAAG,YAAY,KAAK;CAO3H,MAAM,cAAc,OAAA,GAAA,UAAA,UAJU,SAAS,SAAS,EAIR,SAAS;AAEjD,KAAI,YAAY,WAAW,MAAM,CAC/B,QAAO;AAGT,QAAO,KAAK"}