next-csrf
Version:
CSRF mitigation library for Next.js
1 lines • 2.29 kB
JSON
{"ast":null,"code":"\"use strict\";\n\nexports.__esModule = true;\nexports.removePathTrailingSlash = removePathTrailingSlash;\nexports.normalizePathTrailingSlash = void 0;\n/**\n* Removes the trailing slash of a path if there is one. Preserves the root path `/`.\n*/\n\nfunction removePathTrailingSlash(path) {\n return path.endsWith('/') && path !== '/' ? path.slice(0, -1) : path;\n}\n/**\n* Normalizes the trailing slash of a path according to the `trailingSlash` option\n* in `next.config.js`.\n*/\n\n\nconst normalizePathTrailingSlash = process.env.__NEXT_TRAILING_SLASH ? path => {\n if (/\\.[^/]+\\/?$/.test(path)) {\n return removePathTrailingSlash(path);\n } else if (path.endsWith('/')) {\n return path;\n } else {\n return path + '/';\n }\n} : removePathTrailingSlash;\nexports.normalizePathTrailingSlash = normalizePathTrailingSlash;","map":{"version":3,"sources":["../../client/normalize-trailing-slash.ts"],"names":["path","normalizePathTrailingSlash","process","removePathTrailingSlash"],"mappings":";;;;;AAAA;;;;AAGO,SAAA,uBAAA,CAAA,IAAA,EAAuD;AAC5D,SAAOA,IAAI,CAAJA,QAAAA,CAAAA,GAAAA,KAAsBA,IAAI,KAA1BA,GAAAA,GAAqCA,IAAI,CAAJA,KAAAA,CAAAA,CAAAA,EAAc,CAAnDA,CAAqCA,CAArCA,GAAP,IAAA;AAGF;AAAA;;;;;;AAIO,MAAMC,0BAA0B,GAAGC,OAAO,CAAPA,GAAAA,CAAAA,qBAAAA,GACrCF,IAAD,IAA0B;AACxB,MAAI,cAAA,IAAA,CAAJ,IAAI,CAAJ,EAA8B;AAC5B,WAAOG,uBAAuB,CAA9B,IAA8B,CAA9B;AADF,GAAA,MAEO,IAAIH,IAAI,CAAJA,QAAAA,CAAJ,GAAIA,CAAJ,EAAwB;AAC7B,WAAA,IAAA;AADK,GAAA,MAEA;AACL,WAAOA,IAAI,GAAX,GAAA;AAEH;AATqCE,CAAAA,GAAnC,uBAAA","sourcesContent":["/**\n * Removes the trailing slash of a path if there is one. Preserves the root path `/`.\n */\nexport function removePathTrailingSlash(path: string): string {\n return path.endsWith('/') && path !== '/' ? path.slice(0, -1) : path\n}\n\n/**\n * Normalizes the trailing slash of a path according to the `trailingSlash` option\n * in `next.config.js`.\n */\nexport const normalizePathTrailingSlash = process.env.__NEXT_TRAILING_SLASH\n ? (path: string): string => {\n if (/\\.[^/]+\\/?$/.test(path)) {\n return removePathTrailingSlash(path)\n } else if (path.endsWith('/')) {\n return path\n } else {\n return path + '/'\n }\n }\n : removePathTrailingSlash\n"]},"metadata":{},"sourceType":"script"}