clear-excel 1.0.2 → 1.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (71) hide show
  1. package/CHANGELOG.md +28 -0
  2. package/README.md +26 -6
  3. package/dist/api/sanitize-excel-file.d.ts +0 -1
  4. package/dist/api/sanitize-excel-file.js +176 -0
  5. package/dist/api/sanitize-excel-file.js.map +1 -0
  6. package/dist/api/sanitize-excel.d.ts +0 -1
  7. package/dist/api/sanitize-excel.js +25 -0
  8. package/dist/api/sanitize-excel.js.map +1 -0
  9. package/dist/biff/workbook.d.ts +0 -1
  10. package/dist/biff/workbook.js +169 -0
  11. package/dist/biff/workbook.js.map +1 -0
  12. package/dist/constants.d.ts +0 -1
  13. package/dist/constants.js +28 -0
  14. package/dist/constants.js.map +1 -0
  15. package/dist/errors.d.ts +0 -1
  16. package/dist/errors.js +38 -0
  17. package/dist/errors.js.map +1 -0
  18. package/dist/formats.d.ts +0 -1
  19. package/dist/formats.js +16 -0
  20. package/dist/formats.js.map +1 -0
  21. package/dist/index.d.ts +0 -1
  22. package/dist/index.js +4 -2776
  23. package/dist/index.js.map +1 -1
  24. package/dist/ooxml/cleanup.d.ts +0 -1
  25. package/dist/ooxml/cleanup.js +30 -0
  26. package/dist/ooxml/cleanup.js.map +1 -0
  27. package/dist/ooxml/constants.d.ts +0 -1
  28. package/dist/ooxml/constants.js +19 -0
  29. package/dist/ooxml/constants.js.map +1 -0
  30. package/dist/ooxml/parts.d.ts +1 -1
  31. package/dist/ooxml/parts.js +94 -0
  32. package/dist/ooxml/parts.js.map +1 -0
  33. package/dist/ooxml/relationships.d.ts +0 -1
  34. package/dist/ooxml/relationships.js +132 -0
  35. package/dist/ooxml/relationships.js.map +1 -0
  36. package/dist/ooxml/styles.d.ts +0 -1
  37. package/dist/ooxml/styles.js +67 -0
  38. package/dist/ooxml/styles.js.map +1 -0
  39. package/dist/ooxml/workbook.d.ts +0 -1
  40. package/dist/ooxml/workbook.js +119 -0
  41. package/dist/ooxml/workbook.js.map +1 -0
  42. package/dist/ooxml/xml.d.ts +26 -2
  43. package/dist/ooxml/xml.js +304 -0
  44. package/dist/ooxml/xml.js.map +1 -0
  45. package/dist/options.d.ts +0 -1
  46. package/dist/options.js +80 -0
  47. package/dist/options.js.map +1 -0
  48. package/dist/types.d.ts +0 -1
  49. package/dist/types.js +2 -0
  50. package/dist/types.js.map +1 -0
  51. package/dist/zip/central-directory.d.ts +0 -1
  52. package/dist/zip/central-directory.js +131 -0
  53. package/dist/zip/central-directory.js.map +1 -0
  54. package/package.json +17 -25
  55. package/dist/api/sanitize-excel-file.d.ts.map +0 -1
  56. package/dist/api/sanitize-excel.d.ts.map +0 -1
  57. package/dist/biff/workbook.d.ts.map +0 -1
  58. package/dist/constants.d.ts.map +0 -1
  59. package/dist/errors.d.ts.map +0 -1
  60. package/dist/formats.d.ts.map +0 -1
  61. package/dist/index.d.ts.map +0 -1
  62. package/dist/ooxml/cleanup.d.ts.map +0 -1
  63. package/dist/ooxml/constants.d.ts.map +0 -1
  64. package/dist/ooxml/parts.d.ts.map +0 -1
  65. package/dist/ooxml/relationships.d.ts.map +0 -1
  66. package/dist/ooxml/styles.d.ts.map +0 -1
  67. package/dist/ooxml/workbook.d.ts.map +0 -1
  68. package/dist/ooxml/xml.d.ts.map +0 -1
  69. package/dist/options.d.ts.map +0 -1
  70. package/dist/types.d.ts.map +0 -1
  71. package/dist/zip/central-directory.d.ts.map +0 -1
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAyBA,MAAM,cAAc,GAAyD,MAAM,CAAC,MAAM,CAAC;IACzF,oBAAoB,EAAE,kBAAkB;IACxC,yBAAyB,EACvB,sFAAsF;IACxF,eAAe,EAAE,qCAAqC;IACtD,gBAAgB,EAAE,uCAAuC;IACzD,kBAAkB,EAAE,kDAAkD;IACtE,mBAAmB,EAAE,iDAAiD;IACtE,aAAa,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ERR_INVALID_ARGUMENT\"\n | \"ERR_UNSUPPORTED_EXTENSION\"\n | \"ERR_INVALID_XLS\"\n | \"ERR_INVALID_XLSX\"\n | \"ERR_LIMIT_EXCEEDED\"\n | \"ERR_WORKSHEET_COUNT\"\n | \"ERR_SAME_PATH\"\n | \"ERR_OUTPUT_EXISTS\"\n | \"ERR_FILE_READ\"\n | \"ERR_FILE_WRITE\";\n\nexport interface ExcelSanitizationErrorOptions {\n cause?: unknown;\n details?: Readonly<Record<string, unknown>>;\n}\n\ninterface CreateErrorOptions extends ExcelSanitizationErrorOptions {\n message?: string;\n}\n\nexport type SafetyLimitName = keyof ExcelSanitizationLimits | \"partBytes\";\n\nconst ERROR_MESSAGES: Readonly<Record<ExcelSanitizationErrorCode, string>> = Object.freeze({\n ERR_INVALID_ARGUMENT: \"Invalid argument\",\n ERR_UNSUPPORTED_EXTENSION:\n \"Supported extensions are .xls, .xlsx, and .xlsm; input and output formats must match\",\n ERR_INVALID_XLS: \"Invalid or unsupported XLS workbook\",\n ERR_INVALID_XLSX: \"Invalid or unsupported OOXML workbook\",\n ERR_LIMIT_EXCEEDED: \"Excel workbook exceeds a configured safety limit\",\n ERR_WORKSHEET_COUNT: \"The workbook must contain exactly one worksheet\",\n ERR_SAME_PATH: \"Input and output paths must be different\",\n ERR_OUTPUT_EXISTS: \"The output file already exists\",\n ERR_FILE_READ: \"Unable to read the input Excel file\",\n ERR_FILE_WRITE: \"Unable to write the sanitized Excel file\",\n});\n\nexport class ExcelSanitizationError extends Error {\n override readonly name = \"ExcelSanitizationError\";\n readonly code: ExcelSanitizationErrorCode;\n readonly details?: Readonly<Record<string, unknown>>;\n\n constructor(\n code: ExcelSanitizationErrorCode,\n message: string,\n options: ExcelSanitizationErrorOptions = {},\n ) {\n super(message, options.cause === undefined ? undefined : { cause: options.cause });\n this.code = code;\n if (options.details !== undefined) {\n this.details = Object.freeze({ ...options.details });\n }\n }\n}\n\nexport function createError(\n code: ExcelSanitizationErrorCode,\n options: CreateErrorOptions = {},\n): ExcelSanitizationError {\n return new ExcelSanitizationError(code, options.message ?? ERROR_MESSAGES[code], options);\n}\n\nexport function limitExceeded(\n limit: SafetyLimitName,\n configured: number,\n actual: number,\n partName?: string,\n): ExcelSanitizationError {\n return createError(\"ERR_LIMIT_EXCEEDED\", {\n details: {\n limit,\n configured,\n actual,\n ...(partName === undefined ? {} : { partName }),\n },\n });\n}\n"]}
package/dist/formats.d.ts CHANGED
@@ -2,4 +2,3 @@ export type ExcelFileFormat = "xls" | "xlsx" | "xlsm";
2
2
  export declare function excelFileFormat(name: unknown): ExcelFileFormat | undefined;
3
3
  export declare function isExcelFilename(name: unknown): name is string;
4
4
  export declare function isXlsxFilename(name: unknown): name is string;
5
- //# sourceMappingURL=formats.d.ts.map
@@ -0,0 +1,16 @@
1
+ export function excelFileFormat(name) {
2
+ if (typeof name !== "string") {
3
+ return undefined;
4
+ }
5
+ const extension = /\.(xls|xlsx|xlsm)$/i.exec(name)?.[1]?.toLowerCase();
6
+ return extension === "xls" || extension === "xlsx" || extension === "xlsm"
7
+ ? extension
8
+ : undefined;
9
+ }
10
+ export function isExcelFilename(name) {
11
+ return excelFileFormat(name) !== undefined;
12
+ }
13
+ export function isXlsxFilename(name) {
14
+ return excelFileFormat(name) === "xlsx";
15
+ }
16
+ //# sourceMappingURL=formats.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"formats.js","sourceRoot":"","sources":["../src/formats.ts"],"names":[],"mappings":"AAEA,MAAM,UAAU,eAAe,CAAC,IAAa;IAC3C,IAAI,OAAO,IAAI,KAAK,QAAQ,EAAE,CAAC;QAC7B,OAAO,SAAS,CAAC;IACnB,CAAC;IACD,MAAM,SAAS,GAAG,qBAAqB,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,WAAW,EAAE,CAAC;IACvE,OAAO,SAAS,KAAK,KAAK,IAAI,SAAS,KAAK,MAAM,IAAI,SAAS,KAAK,MAAM;QACxE,CAAC,CAAC,SAAS;QACX,CAAC,CAAC,SAAS,CAAC;AAChB,CAAC;AAED,MAAM,UAAU,eAAe,CAAC,IAAa;IAC3C,OAAO,eAAe,CAAC,IAAI,CAAC,KAAK,SAAS,CAAC;AAC7C,CAAC;AAED,MAAM,UAAU,cAAc,CAAC,IAAa;IAC1C,OAAO,eAAe,CAAC,IAAI,CAAC,KAAK,MAAM,CAAC;AAC1C,CAAC","sourcesContent":["export type ExcelFileFormat = \"xls\" | \"xlsx\" | \"xlsm\";\n\nexport function excelFileFormat(name: unknown): ExcelFileFormat | undefined {\n if (typeof name !== \"string\") {\n return undefined;\n }\n const extension = /\\.(xls|xlsx|xlsm)$/i.exec(name)?.[1]?.toLowerCase();\n return extension === \"xls\" || extension === \"xlsx\" || extension === \"xlsm\"\n ? extension\n : undefined;\n}\n\nexport function isExcelFilename(name: unknown): name is string {\n return excelFileFormat(name) !== undefined;\n}\n\nexport function isXlsxFilename(name: unknown): name is string {\n return excelFileFormat(name) === \"xlsx\";\n}\n"]}
package/dist/index.d.ts CHANGED
@@ -5,4 +5,3 @@ export { ExcelSanitizationError } from "./errors.js";
5
5
  export type { ExcelSanitizationErrorCode, ExcelSanitizationErrorOptions } from "./errors.js";
6
6
  export type { ExcelFileFormat } from "./formats.js";
7
7
  export type { ExcelSanitizationLimits, SanitizeExcelFileOptions, SanitizeExcelOptions, } from "./types.js";
8
- //# sourceMappingURL=index.d.ts.map