@node-minify/utils 8.0.5-beta.0 → 8.0.6

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.
package/README.md CHANGED
@@ -1,4 +1,4 @@
1
- <p align="center"><img src="/static/node-minify.png" width="348" alt="node-minify"></p>
1
+ <p align="center"><img src="/static/node-minify.svg" width="348" alt="node-minify"></p>
2
2
 
3
3
  <p align="center">A very light minifier Node.js module.</p>
4
4
 
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { Options, Dictionary, Settings, MinifierOptions } from '@node-minify/types';
1
+ import { OptionsPossible, Settings, MinifierOptions } from '@node-minify/types';
2
2
 
3
3
  /*!
4
4
  * node-minify
@@ -6,30 +6,26 @@ import { Options, Dictionary, Settings, MinifierOptions } from '@node-minify/typ
6
6
  * MIT Licensed
7
7
  */
8
8
 
9
- interface Utils {
9
+ type Utils = {
10
10
  readFile: (file: string) => string;
11
11
  writeFile: ({ file, content, index }: WriteFile) => string;
12
12
  deleteFile: (file: string) => void;
13
- buildArgs: (options: Options & Dictionary<string | boolean | [] | {
14
- url: string;
15
- } | {
16
- filename: string;
17
- } | undefined>) => any;
13
+ buildArgs: (options: Record<string, OptionsPossible>) => any;
18
14
  clone: (obj: object) => object;
19
15
  getFilesizeInBytes: (file: string) => string;
20
16
  getFilesizeGzippedInBytes: (file: string) => Promise<string>;
21
17
  prettyBytes: (num: number) => string;
22
- setFileNameMin: (file: string, output: string, publicFolder: string, replaceInPlace: boolean) => string;
18
+ setFileNameMin: (file: string, output: string, publicFolder?: string, replaceInPlace?: boolean) => string;
23
19
  compressSingleFile: (settings: Settings) => string | Promise<string>;
24
20
  getContentFromFiles: (input: string | string[]) => string;
25
21
  runSync: ({ settings, content, index }: MinifierOptions) => string;
26
22
  runAsync: ({ settings, content, index }: MinifierOptions) => Promise<string>;
27
- }
28
- interface WriteFile {
23
+ };
24
+ type WriteFile = {
29
25
  file: string;
30
26
  content: any;
31
27
  index?: number;
32
- }
28
+ };
33
29
  declare const utils: Utils;
34
30
 
35
31
  export { utils };
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts"],"sourcesContent":["/*!\n * node-minify\n * Copyright(c) 2011-2023 Rodolphe Stoclin\n * MIT Licensed\n */\n\n/**\n * Module dependencies.\n */\nimport { readFileSync, lstatSync, statSync, existsSync, writeFileSync, unlinkSync, createReadStream } from 'node:fs';\nimport gzipSize from 'gzip-size';\nimport { Dictionary, MinifierOptions, Settings, Options } from '@node-minify/types';\n\ninterface Utils {\n readFile: (file: string) => string;\n writeFile: ({ file, content, index }: WriteFile) => string;\n deleteFile: (file: string) => void;\n buildArgs: (\n options: Options & Dictionary<string | boolean | [] | { url: string } | { filename: string } | undefined>\n ) => any;\n clone: (obj: object) => object;\n getFilesizeInBytes: (file: string) => string;\n getFilesizeGzippedInBytes: (file: string) => Promise<string>;\n prettyBytes: (num: number) => string;\n setFileNameMin: (file: string, output: string, publicFolder: string, replaceInPlace: boolean) => string;\n compressSingleFile: (settings: Settings) => string | Promise<string>;\n getContentFromFiles: (input: string | string[]) => string;\n runSync: ({ settings, content, index }: MinifierOptions) => string;\n runAsync: ({ settings, content, index }: MinifierOptions) => Promise<string>;\n}\n\ninterface WriteFile {\n file: string;\n content: any;\n index?: number;\n}\n\nconst utils = {} as Utils;\n\n/**\n * Read content from file.\n *\n * @param {String} file\n * @returns {String}\n */\nutils.readFile = (file: string) => readFileSync(file, 'utf8');\n\n/**\n * Write content into file.\n *\n * @param {String} file\n * @param {String} content\n * @param {Number} index - index of the file being processed\n * @returns {String}\n */\nutils.writeFile = ({ file, content, index }: WriteFile) => {\n const _file = index !== undefined ? file[index] : file;\n if (!existsSync(_file) || (existsSync(_file) && !lstatSync(_file).isDirectory())) {\n writeFileSync(_file, content, 'utf8');\n }\n\n return content;\n};\n\n/**\n * Delete file.\n *\n * @param {String} file\n * @returns {String}\n */\nutils.deleteFile = (file: string) => unlinkSync(file);\n\n/**\n * Builds arguments array based on an object.\n *\n * @param {Object} options\n * @returns {Array}\n */\nutils.buildArgs = (options: Dictionary<string | boolean | [] | { url: string } | { filename: string } | undefined>) => {\n const args: (string | boolean | [] | { url: string } | { filename: string } | undefined)[] = [];\n Object.keys(options).forEach((key: string) => {\n if (options[key] && options[key] !== false) {\n args.push('--' + key);\n }\n\n if (options[key] && options[key] !== true) {\n args.push(options[key]);\n }\n });\n\n return args;\n};\n\n/**\n * Clone an object.\n *\n * @param {Object} obj\n * @returns {Object}\n */\nutils.clone = (obj: object) => JSON.parse(JSON.stringify(obj));\n\n/**\n * Get the file size in bytes.\n *\n * @returns {String}\n */\nutils.getFilesizeInBytes = (file: string) => {\n const stats = statSync(file);\n const fileSizeInBytes = stats.size;\n return utils.prettyBytes(fileSizeInBytes);\n};\n\n/**\n * Get the gzipped file size in bytes.\n *\n * @returns {Promise.<String>}\n */\nutils.getFilesizeGzippedInBytes = (file: string) => {\n return new Promise(resolve => {\n const source = createReadStream(file);\n source.pipe(gzipSize.stream()).on('gzip-size', size => {\n resolve(utils.prettyBytes(size));\n });\n });\n};\n\n/**\n * Get the size in human readable.\n * From https://github.com/sindresorhus/pretty-bytes\n *\n * @returns {String}\n */\nutils.prettyBytes = (num: number) => {\n const UNITS = ['B', 'kB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];\n\n if (!Number.isFinite(num)) {\n throw new TypeError(`Expected a finite number, got ${typeof num}: ${num}`);\n }\n\n const neg = num < 0;\n\n if (neg) {\n num = -num;\n }\n\n if (num < 1) {\n return (neg ? '-' : '') + num + ' B';\n }\n\n const exponent = Math.min(Math.floor(Math.log(num) / Math.log(1000)), UNITS.length - 1);\n const numStr = Number((num / Math.pow(1000, exponent)).toPrecision(3));\n const unit = UNITS[exponent];\n\n return (neg ? '-' : '') + numStr + ' ' + unit;\n};\n\n/**\n * Set the file name as minified.\n * eg. file.js returns file.min.js\n *\n * @param {String} file\n * @param {String} output\n * @param {String} publicFolder\n * @param {Boolean} replaceInPlace\n * @returns {String}\n */\nutils.setFileNameMin = (file: string, output: string, publicFolder: string, replaceInPlace: boolean) => {\n const filePath = file.substr(0, file.lastIndexOf('/') + 1);\n const fileWithoutPath = file.substr(file.lastIndexOf('/') + 1);\n let fileWithoutExtension = fileWithoutPath.substr(0, fileWithoutPath.lastIndexOf('.'));\n if (publicFolder) {\n fileWithoutExtension = publicFolder + fileWithoutExtension;\n }\n if (replaceInPlace) {\n fileWithoutExtension = filePath + fileWithoutExtension;\n }\n return output.replace('$1', fileWithoutExtension);\n};\n\n/**\n * Compress a single file.\n *\n * @param {Object} settings\n */\nutils.compressSingleFile = (settings: Settings): Promise<string> | string => {\n const content = settings.content ? settings.content : settings.input ? utils.getContentFromFiles(settings.input) : '';\n return settings.sync ? utils.runSync({ settings, content }) : utils.runAsync({ settings, content });\n};\n\n/**\n * Concatenate all input files and get the data.\n *\n * @param {String|Array} input\n * @return {String}\n */\nutils.getContentFromFiles = (input: string | string[]) => {\n if (!Array.isArray(input)) {\n return readFileSync(input, 'utf8');\n }\n\n return input\n .map(path =>\n !existsSync(path) || (existsSync(path) && !lstatSync(path).isDirectory()) ? readFileSync(path, 'utf8') : ''\n )\n .join('\\n');\n};\n\n/**\n * Run compressor in sync.\n *\n * @param {Object} settings\n * @param {String} content\n * @param {Number} index - index of the file being processed\n * @return {String}\n */\nutils.runSync = ({ settings, content, index }: MinifierOptions): string =>\n settings && typeof settings.compressor !== 'string'\n ? typeof settings.compressor === 'function'\n ? settings.compressor({ settings, content, callback: null, index })\n : ''\n : '';\n\n/**\n * Run compressor in async.\n *\n * @param {Object} settings\n * @param {String} content\n * @param {Number} index - index of the file being processed\n * @return {Promise}\n */\nutils.runAsync = ({ settings, content, index }: MinifierOptions): Promise<string> => {\n return new Promise((resolve, reject) => {\n settings && settings.compressor && typeof settings.compressor !== 'string'\n ? settings.compressor({\n settings,\n content,\n callback: (err: unknown, result?: string) => {\n if (err) {\n return reject(err);\n }\n resolve(result || '');\n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AQ,MAAM,oBAAoB,SAAS,KAAK,IAAI;AACnH,SAAO,SAAS,OAAO,MAAM,QAAQ,EAAE,UAAU,QAAQ,CAAC,IAAI,MAAM,SAAS,EAAE,UAAU,QAAQ,CAAC;AACpG;AAQA,MAAM,sBAAsB,CAAC,UAA6B;AACxD,MAAI,CAAC,MAAM,QAAQ,KAAK,GAAG;AACzB,eAAO,6BAAa,OAAO,MAAM;AAAA,EACnC;AAEA,SAAO,MACJ;AAAA,IAAI,UACH,KAAC,2BAAW,IAAI,SAAM,2BAAW,IAAI,KAAK,KAAC,0BAAU,IAAI,EAAE,YAAY,QAAK,6BAAa,MAAM,MAAM,IAAI;AAAA,EAC3G,EACC,KAAK,IAAI;AACd;AAUA,MAAM,UAAU,CAAC,EAAE,UAAU,SAAS,MAAM,MAC1C,YAAY,OAAO,SAAS,eAAe,WACvC,OAAO,SAAS,eAAe,aAC7B,SAAS,WAAW,EAAE,UAAU,SAAS,UAAU,MAAM,MAAM,CAAC,IAChE,KACF;AAUN,MAAM,WAAW,CAAC,EAAE,UAAU,SAAS,MAAM,MAAwC;AACnF,SAAO,IAAI,QAAQ,CAAC,SAAS,WAAW;AACtC,gBAAY,SAAS,cAAc,OAAO,SAAS,eAAe,WAC9D,SAAS,WAAW;AAAA,MAClB;AAAA,MACA;AAAA,MACA,UAAU,CAAC,KAAc,WAAoB;AAC3C,YAAI,KAAK;AACP,iBAAO,OAAO,GAAG;AAAA,QACnB;AACA,gBAAQ,UAAU,EAAE;AAAA,MACtB;AAAA,MACA;AAAA,IACF,CAAC,IACD;AAAA,EACN,CAAC;AACH;","names":["gzipSize"]}
1
+ {"version":3,"sources":["../src/index.ts"],"sourcesContent":["/*!\n * node-minify\n * Copyright(c) 2011-2023 Rodolphe Stoclin\n * MIT Licensed\n */\n\n/**\n * Module dependencies.\n */\nimport { readFileSync, lstatSync, statSync, existsSync, writeFileSync, unlinkSync, createReadStream } from 'node:fs';\nimport gzipSize from 'gzip-size';\nimport { MinifierOptions, Settings, OptionsPossible } from '@node-minify/types';\n\ntype Utils = {\n readFile: (file: string) => string;\n writeFile: ({ file, content, index }: WriteFile) => string;\n deleteFile: (file: string) => void;\n buildArgs: (options: Record<string, OptionsPossible>) => any;\n clone: (obj: object) => object;\n getFilesizeInBytes: (file: string) => string;\n getFilesizeGzippedInBytes: (file: string) => Promise<string>;\n prettyBytes: (num: number) => string;\n setFileNameMin: (file: string, output: string, publicFolder?: string, replaceInPlace?: boolean) => string;\n compressSingleFile: (settings: Settings) => string | Promise<string>;\n getContentFromFiles: (input: string | string[]) => string;\n runSync: ({ settings, content, index }: MinifierOptions) => string;\n runAsync: ({ settings, content, index }: MinifierOptions) => Promise<string>;\n};\n\ntype WriteFile = {\n file: string;\n content: any;\n index?: number;\n};\n\nconst utils = {} as Utils;\n\n/**\n * Read content from file.\n *\n * @param {String} file\n * @returns {String}\n */\nutils.readFile = (file: string): string => readFileSync(file, 'utf8');\n\n/**\n * Write content into file.\n *\n * @param {String} file\n * @param {String} content\n * @param {Number} index - index of the file being processed\n * @returns {String}\n */\nutils.writeFile = ({ file, content, index }: WriteFile): string => {\n const _file = index !== undefined ? file[index] : file;\n if (!existsSync(_file) || (existsSync(_file) && !lstatSync(_file).isDirectory())) {\n writeFileSync(_file, content, 'utf8');\n }\n\n return content;\n};\n\n/**\n * Delete file.\n *\n * @param {String} file\n */\nutils.deleteFile = (file: string) => unlinkSync(file);\n\n/**\n * Builds arguments array based on an object.\n *\n * @param {Object} options\n * @returns {Array}\n */\nutils.buildArgs = (options: Record<string, OptionsPossible>): OptionsPossible[] => {\n const args: OptionsPossible[] = [];\n Object.keys(options).forEach((key: string) => {\n if (options[key] && options[key] !== false) {\n args.push('--' + key);\n }\n\n if (options[key] && options[key] !== true) {\n args.push(options[key]);\n }\n });\n\n return args;\n};\n\n/**\n * Clone an object.\n *\n * @param {Object} obj\n * @returns {Object}\n */\nutils.clone = (obj: object): object => JSON.parse(JSON.stringify(obj));\n\n/**\n * Get the file size in bytes.\n *\n * @returns {String}\n */\nutils.getFilesizeInBytes = (file: string): string => {\n const stats = statSync(file);\n const fileSizeInBytes = stats.size;\n return utils.prettyBytes(fileSizeInBytes);\n};\n\n/**\n * Get the gzipped file size in bytes.\n *\n * @returns {Promise.<String>}\n */\nutils.getFilesizeGzippedInBytes = (file: string): Promise<string> => {\n return new Promise(resolve => {\n const source = createReadStream(file);\n source.pipe(gzipSize.stream()).on('gzip-size', size => {\n resolve(utils.prettyBytes(size));\n });\n });\n};\n\n/**\n * Get the size in human readable.\n * From https://github.com/sindresorhus/pretty-bytes\n *\n * @returns {String}\n */\nutils.prettyBytes = (num: number): string => {\n const UNITS = ['B', 'kB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];\n\n if (!Number.isFinite(num)) {\n throw new TypeError(`Expected a finite number, got ${typeof num}: ${num}`);\n }\n\n const neg = num < 0;\n\n if (neg) {\n num = -num;\n }\n\n if (num < 1) {\n return (neg ? '-' : '') + num + ' B';\n }\n\n const exponent = Math.min(Math.floor(Math.log(num) / Math.log(1000)), UNITS.length - 1);\n const numStr = Number((num / Math.pow(1000, exponent)).toPrecision(3));\n const unit = UNITS[exponent];\n\n return (neg ? '-' : '') + numStr + ' ' + unit;\n};\n\n/**\n * Set the file name as minified.\n * eg. file.js returns file.min.js\n *\n * @param {String} file\n * @param {String} output\n * @param {String} publicFolder\n * @param {Boolean} replaceInPlace\n * @returns {String}\n */\nutils.setFileNameMin = (file: string, output: string, publicFolder?: string, replaceInPlace?: boolean): string => {\n const filePath = file.substr(0, file.lastIndexOf('/') + 1);\n const fileWithoutPath = file.substr(file.lastIndexOf('/') + 1);\n let fileWithoutExtension = fileWithoutPath.substr(0, fileWithoutPath.lastIndexOf('.'));\n if (publicFolder) {\n fileWithoutExtension = publicFolder + fileWithoutExtension;\n }\n if (replaceInPlace) {\n fileWithoutExtension = filePath + fileWithoutExtension;\n }\n return output.replace('$1', fileWithoutExtension);\n};\n\n/**\n * Compress a single file.\n *\n * @param {Object} settings\n */\nutils.compressSingleFile = (settings: Settings): Promise<string> | string => {\n const content = settings.content ? settings.content : settings.input ? utils.getContentFromFiles(settings.input) : '';\n return settings.sync ? utils.runSync({ settings, content }) : utils.runAsync({ settings, content });\n};\n\n/**\n * Concatenate all input files and get the data.\n *\n * @param {String|Array} input\n * @return {String}\n */\nutils.getContentFromFiles = (input: string | string[]): string => {\n if (!Array.isArray(input)) {\n return readFileSync(input, 'utf8');\n }\n\n return input\n .map(path =>\n !existsSync(path) || (existsSync(path) && !lstatSync(path).isDirectory()) ? readFileSync(path, 'utf8') : ''\n )\n .join('\\n');\n};\n\n/**\n * Run compressor in sync.\n *\n * @param {Object} settings\n * @param {String} content\n * @param {Number} index - index of the file being processed\n * @return {String}\n */\nutils.runSync = ({ settings, content, index }: MinifierOptions): string =>\n settings && typeof settings.compressor !== 'string'\n ? typeof settings.compressor === 'function'\n ? settings.compressor({ settings, content, callback: null, index })\n : ''\n : '';\n\n/**\n * Run compressor in async.\n *\n * @param {Object} settings\n * @param {String} content\n * @param {Number} index - index of the file being processed\n * @return {Promise}\n */\nutils.runAsync = ({ settings, content, index }: MinifierOptions): Promise<string> => {\n return new Promise((resolve, reject) => {\n settings && settings.compressor && typeof settings.compressor !== 'string'\n ? settings.compressor({\n settings,\n content,\n callback: (err: unknown, result?: string) => {\n if (err) {\n return reject(err);\n }\n resolve(result || '');\n },\n index\n })\n : null;\n });\n};\n\n/**\n * Expose `utils`.\n */\nexport { utils };\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AASA,qBAA2G;AAC3G,uBAAqB;AAyBrB,IAAM,QAAQ,CAAC;AAQf,MAAM,WAAW,CAAC,aAAyB,6BAAa,MAAM,MAAM;AAUpE,MAAM,YAAY,CAAC,EAAE,MAAM,SAAS,MAAM,MAAyB;AACjE,QAAM,QAAQ,UAAU,SAAY,KAAK,KAAK,IAAI;AAClD,MAAI,KAAC,2BAAW,KAAK,S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,QAAK,6BAAa,MAAM,MAAM,IAAI;AAAA,EAC3G,EACC,KAAK,IAAI;AACd;AAUA,MAAM,UAAU,CAAC,EAAE,UAAU,SAAS,MAAM,MAC1C,YAAY,OAAO,SAAS,eAAe,WACvC,OAAO,SAAS,eAAe,aAC7B,SAAS,WAAW,EAAE,UAAU,SAAS,UAAU,MAAM,MAAM,CAAC,IAChE,KACF;AAUN,MAAM,WAAW,CAAC,EAAE,UAAU,SAAS,MAAM,MAAwC;AACnF,SAAO,IAAI,QAAQ,CAAC,SAAS,WAAW;AACtC,gBAAY,SAAS,cAAc,OAAO,SAAS,eAAe,WAC9D,SAAS,WAAW;AAAA,MAClB;AAAA,MACA;AAAA,MACA,UAAU,CAAC,KAAc,WAAoB;AAC3C,YAAI,KAAK;AACP,iBAAO,OAAO,GAAG;AAAA,QACnB;AACA,gBAAQ,UAAU,EAAE;AAAA,MACtB;AAAA,MACA;AAAA,IACF,CAAC,IACD;AAAA,EACN,CAAC;AACH;","names":["gzipSize"]}
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts"],"sourcesContent":["/*!\n * node-minify\n * Copyright(c) 2011-2023 Rodolphe Stoclin\n * MIT Licensed\n */\n\n/**\n * Module dependencies.\n */\nimport { readFileSync, lstatSync, statSync, existsSync, writeFileSync, unlinkSync, createReadStream } from 'node:fs';\nimport gzipSize from 'gzip-size';\nimport { Dictionary, MinifierOptions, Settings, Options } from '@node-minify/types';\n\ninterface Utils {\n readFile: (file: string) => string;\n writeFile: ({ file, content, index }: WriteFile) => string;\n deleteFile: (file: string) => void;\n buildArgs: (\n options: Options & Dictionary<string | boolean | [] | { url: string } | { filename: string } | undefined>\n ) => any;\n clone: (obj: object) => object;\n getFilesizeInBytes: (file: string) => string;\n getFilesizeGzippedInBytes: (file: string) => Promise<string>;\n prettyBytes: (num: number) => string;\n setFileNameMin: (file: string, output: string, publicFolder: string, replaceInPlace: boolean) => string;\n compressSingleFile: (settings: Settings) => string | Promise<string>;\n getContentFromFiles: (input: string | string[]) => string;\n runSync: ({ settings, content, index }: MinifierOptions) => string;\n runAsync: ({ settings, content, index }: MinifierOptions) => Promise<string>;\n}\n\ninterface WriteFile {\n file: string;\n content: any;\n index?: number;\n}\n\nconst utils = {} as Utils;\n\n/**\n * Read content from file.\n *\n * @param {String} file\n * @returns {String}\n */\nutils.readFile = (file: string) => readFileSync(file, 'utf8');\n\n/**\n * Write content into file.\n *\n * @param {String} file\n * @param {String} content\n * @param {Number} index - index of the file being processed\n * @returns {String}\n */\nutils.writeFile = ({ file, content, index }: WriteFile) => {\n const _file = index !== undefined ? file[index] : file;\n if (!existsSync(_file) || (existsSync(_file) && !lstatSync(_file).isDirectory())) {\n writeFileSync(_file, content, 'utf8');\n }\n\n return content;\n};\n\n/**\n * Delete file.\n *\n * @param {String} file\n * @returns {String}\n */\nutils.deleteFile = (file: string) => unlinkSync(file);\n\n/**\n * Builds arguments array based on an object.\n *\n * @param {Object} options\n * @returns {Array}\n */\nutils.buildArgs = (options: Dictionary<string | boolean | [] | { url: string } | { filename: string } | undefined>) => {\n const args: (string | boolean | [] | { url: string } | { filename: string } | undefined)[] = [];\n Object.keys(options).forEach((key: string) => {\n if (options[key] && options[key] !== false) {\n args.push('--' + key);\n }\n\n if (options[key] && options[key] !== true) {\n args.push(options[key]);\n }\n });\n\n return args;\n};\n\n/**\n * Clone an object.\n *\n * @param {Object} obj\n * @returns {Object}\n */\nutils.clone = (obj: object) => JSON.parse(JSON.stringify(obj));\n\n/**\n * Get the file size in bytes.\n *\n * @returns {String}\n */\nutils.getFilesizeInBytes = (file: string) => {\n const stats = statSync(file);\n const fileSizeInBytes = stats.size;\n return utils.prettyBytes(fileSizeInBytes);\n};\n\n/**\n * Get the gzipped file size in bytes.\n *\n * @returns {Promise.<String>}\n */\nutils.getFilesizeGzippedInBytes = (file: string) => {\n return new Promise(resolve => {\n const source = createReadStream(file);\n source.pipe(gzipSize.stream()).on('gzip-size', size => {\n resolve(utils.prettyBytes(size));\n });\n });\n};\n\n/**\n * Get the size in human readable.\n * From https://github.com/sindresorhus/pretty-bytes\n *\n * @returns {String}\n */\nutils.prettyBytes = (num: number) => {\n const UNITS = ['B', 'kB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];\n\n if (!Number.isFinite(num)) {\n throw new TypeError(`Expected a finite number, got ${typeof num}: ${num}`);\n }\n\n const neg = num < 0;\n\n if (neg) {\n num = -num;\n }\n\n if (num < 1) {\n return (neg ? '-' : '') + num + ' B';\n }\n\n const exponent = Math.min(Math.floor(Math.log(num) / Math.log(1000)), UNITS.length - 1);\n const numStr = Number((num / Math.pow(1000, exponent)).toPrecision(3));\n const unit = UNITS[exponent];\n\n return (neg ? '-' : '') + numStr + ' ' + unit;\n};\n\n/**\n * Set the file name as minified.\n * eg. file.js returns file.min.js\n *\n * @param {String} file\n * @param {String} output\n * @param {String} publicFolder\n * @param {Boolean} replaceInPlace\n * @returns {String}\n */\nutils.setFileNameMin = (file: string, output: string, publicFolder: string, replaceInPlace: boolean) => {\n const filePath = file.substr(0, file.lastIndexOf('/') + 1);\n const fileWithoutPath = file.substr(file.lastIndexOf('/') + 1);\n let fileWithoutExtension = fileWithoutPath.substr(0, fileWithoutPath.lastIndexOf('.'));\n if (publicFolder) {\n fileWithoutExtension = publicFolder + fileWithoutExtension;\n }\n if (replaceInPlace) {\n fileWithoutExtension = filePath + fileWithoutExtension;\n }\n return output.replace('$1', fileWithoutExtension);\n};\n\n/**\n * Compress a single file.\n *\n * @param {Object} settings\n */\nutils.compressSingleFile = (settings: Settings): Promise<string> | string => {\n const content = settings.content ? settings.content : settings.input ? utils.getContentFromFiles(settings.input) : '';\n return settings.sync ? utils.runSync({ settings, content }) : utils.runAsync({ settings, content });\n};\n\n/**\n * Concatenate all input files and get the data.\n *\n * @param {String|Array} input\n * @return {String}\n */\nutils.getContentFromFiles = (input: string | string[]) => {\n if (!Array.isArray(input)) {\n return readFileSync(input, 'utf8');\n }\n\n return input\n .map(path =>\n !existsSync(path) || (existsSync(path) && !lstatSync(path).isDirectory()) ? readFileSync(path, 'utf8') : ''\n )\n .join('\\n');\n};\n\n/**\n * Run compressor in sync.\n *\n * @param {Object} settings\n * @param {String} content\n * @param {Number} index - index of the file being processed\n * @return {String}\n */\nutils.runSync = ({ settings, content, index }: MinifierOptions): string =>\n settings && typeof settings.compressor !== 'string'\n ? typeof settings.compressor === 'function'\n ? settings.compressor({ settings, content, callback: null, index })\n : ''\n : '';\n\n/**\n * Run compressor in async.\n *\n * @param {Object} settings\n * @param {String} content\n * @param {Number} index - index of the file being processed\n * @return {Promise}\n */\nutils.runAsync = ({ settings, content, index }: MinifierOptions): Promise<string> => {\n return new Promise((resolve, reject) => {\n settings && settings.compressor && typeof settings.compressor !== 'string'\n ? settings.compressor({\n settings,\n content,\n callback: (err: unknown, result?: string) => {\n if (err) {\n return reject(err);\n }\n resolve(result || '');\n },\n index\n })\n : null;\n });\n};\n\n/**\n * Expose `utils`.\n */\nexport { utils };\n"],"mappings":";AASA,SAAS,cAAc,WAAW,UAAU,YAAY,eAAe,YAAY,wBAAwB;AAC3G,OAAO,cAAc;AA2BrB,IAAM,QAAQ,CAAC;AAQf,MAAM,WAAW,CAAC,SAAiB,aAAa,MAAM,MAAM;AAU5D,MAAM,YAAY,CAAC,EAAE,MAAM,SAAS,MAAM,MAAiB;AACzD,QAAM,QAAQ,UAAU,SAAY,KAAK,KAAK,IAAI;AAClD,MAAI,CAAC,WAAW,KAAK,KAAM,WAAW,KAAK,KAAK,CAAC,UAAU,KAAK,EAAE,YAAY,GAAI;AAChF,kBAAc,OAAO,SAAS,MAAM;AAAA,EACtC;AAEA,SAAO;AACT;AAQA,MAAM,aAAa,CAAC,SAAiB,WAAW,IAAI;AAQpD,MAAM,YAAY,CAAC,YAAoG;AACrH,QAAM,OAAuF,CAAC;AAC9F,SAAO,KAAK,OAAO,EAAE,QAAQ,CAAC,QAAgB;AAC5C,QAAI,QAAQ,GAAG,KAAK,QAAQ,GAAG,MAAM,OAA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C,gBAAY,SAAS,cAAc,OAAO,SAAS,eAAe,WAC9D,SAAS,WAAW;AAAA,MAClB;AAAA,MACA;AAAA,MACA,UAAU,CAAC,KAAc,WAAoB;AAC3C,YAAI,KAAK;AACP,iBAAO,OAAO,GAAG;AAAA,QACnB;AACA,gBAAQ,UAAU,EAAE;AAAA,MACtB;AAAA,MACA;AAAA,IACF,CAAC,IACD;AAAA,EACN,CAAC;AACH;","names":[]}
1
+ {"version":3,"sources":["../src/index.ts"],"sourcesContent":["/*!\n * node-minify\n * Copyright(c) 2011-2023 Rodolphe Stoclin\n * MIT Licensed\n */\n\n/**\n * Module dependencies.\n */\nimport { readFileSync, lstatSync, statSync, existsSync, writeFileSync, unlinkSync, createReadStream } from 'node:fs';\nimport gzipSize from 'gzip-size';\nimport { MinifierOptions, Settings, OptionsPossible } from '@node-minify/types';\n\ntype Utils = {\n readFile: (file: string) => string;\n writeFile: ({ file, content, index }: WriteFile) => string;\n deleteFile: (file: string) => void;\n buildArgs: (options: Record<string, OptionsPossible>) => any;\n clone: (obj: object) => object;\n getFilesizeInBytes: (file: string) => string;\n getFilesizeGzippedInBytes: (file: string) => Promise<string>;\n prettyBytes: (num: number) => string;\n setFileNameMin: (file: string, output: string, publicFolder?: string, replaceInPlace?: boolean) => string;\n compressSingleFile: (settings: Settings) => string | Promise<string>;\n getContentFromFiles: (input: string | string[]) => string;\n runSync: ({ settings, content, index }: MinifierOptions) => string;\n runAsync: ({ settings, content, index }: MinifierOptions) => Promise<string>;\n};\n\ntype WriteFile = {\n file: string;\n content: any;\n index?: number;\n};\n\nconst utils = {} as Utils;\n\n/**\n * Read content from file.\n *\n * @param {String} file\n * @returns {String}\n */\nutils.readFile = (file: string): string => readFileSync(file, 'utf8');\n\n/**\n * Write content into file.\n *\n * @param {String} file\n * @param {String} content\n * @param {Number} index - index of the file being processed\n * @returns {String}\n */\nutils.writeFile = ({ file, content, index }: WriteFile): string => {\n const _file = index !== undefined ? file[index] : file;\n if (!existsSync(_file) || (existsSync(_file) && !lstatSync(_file).isDirectory())) {\n writeFileSync(_file, content, 'utf8');\n }\n\n return content;\n};\n\n/**\n * Delete file.\n *\n * @param {String} file\n */\nutils.deleteFile = (file: string) => unlinkSync(file);\n\n/**\n * Builds arguments array based on an object.\n *\n * @param {Object} options\n * @returns {Array}\n */\nutils.buildArgs = (options: Record<string, OptionsPossible>): OptionsPossible[] => {\n const args: OptionsPossible[] = [];\n Object.keys(options).forEach((key: string) => {\n if (options[key] && options[key] !== false) {\n args.push('--' + key);\n }\n\n if (options[key] && options[key] !== true) {\n args.push(options[key]);\n }\n });\n\n return args;\n};\n\n/**\n * Clone an object.\n *\n * @param {Object} obj\n * @returns {Object}\n */\nutils.clone = (obj: object): object => JSON.parse(JSON.stringify(obj));\n\n/**\n * Get the file size in bytes.\n *\n * @returns {String}\n */\nutils.getFilesizeInBytes = (file: string): string => {\n const stats = statSync(file);\n const fileSizeInBytes = stats.size;\n return utils.prettyBytes(fileSizeInBytes);\n};\n\n/**\n * Get the gzipped file size in bytes.\n *\n * @returns {Promise.<String>}\n */\nutils.getFilesizeGzippedInBytes = (file: string): Promise<string> => {\n return new Promise(resolve => {\n const source = createReadStream(file);\n source.pipe(gzipSize.stream()).on('gzip-size', size => {\n resolve(utils.prettyBytes(size));\n });\n });\n};\n\n/**\n * Get the size in human readable.\n * From https://github.com/sindresorhus/pretty-bytes\n *\n * @returns {String}\n */\nutils.prettyBytes = (num: number): string => {\n const UNITS = ['B', 'kB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];\n\n if (!Number.isFinite(num)) {\n throw new TypeError(`Expected a finite number, got ${typeof num}: ${num}`);\n }\n\n const neg = num < 0;\n\n if (neg) {\n num = -num;\n }\n\n if (num < 1) {\n return (neg ? '-' : '') + num + ' B';\n }\n\n const exponent = Math.min(Math.floor(Math.log(num) / Math.log(1000)), UNITS.length - 1);\n const numStr = Number((num / Math.pow(1000, exponent)).toPrecision(3));\n const unit = UNITS[exponent];\n\n return (neg ? '-' : '') + numStr + ' ' + unit;\n};\n\n/**\n * Set the file name as minified.\n * eg. file.js returns file.min.js\n *\n * @param {String} file\n * @param {String} output\n * @param {String} publicFolder\n * @param {Boolean} replaceInPlace\n * @returns {String}\n */\nutils.setFileNameMin = (file: string, output: string, publicFolder?: string, replaceInPlace?: boolean): string => {\n const filePath = file.substr(0, file.lastIndexOf('/') + 1);\n const fileWithoutPath = file.substr(file.lastIndexOf('/') + 1);\n let fileWithoutExtension = fileWithoutPath.substr(0, fileWithoutPath.lastIndexOf('.'));\n if (publicFolder) {\n fileWithoutExtension = publicFolder + fileWithoutExtension;\n }\n if (replaceInPlace) {\n fileWithoutExtension = filePath + fileWithoutExtension;\n }\n return output.replace('$1', fileWithoutExtension);\n};\n\n/**\n * Compress a single file.\n *\n * @param {Object} settings\n */\nutils.compressSingleFile = (settings: Settings): Promise<string> | string => {\n const content = settings.content ? settings.content : settings.input ? utils.getContentFromFiles(settings.input) : '';\n return settings.sync ? utils.runSync({ settings, content }) : utils.runAsync({ settings, content });\n};\n\n/**\n * Concatenate all input files and get the data.\n *\n * @param {String|Array} input\n * @return {String}\n */\nutils.getContentFromFiles = (input: string | string[]): string => {\n if (!Array.isArray(input)) {\n return readFileSync(input, 'utf8');\n }\n\n return input\n .map(path =>\n !existsSync(path) || (existsSync(path) && !lstatSync(path).isDirectory()) ? readFileSync(path, 'utf8') : ''\n )\n .join('\\n');\n};\n\n/**\n * Run compressor in sync.\n *\n * @param {Object} settings\n * @param {String} content\n * @param {Number} index - index of the file being processed\n * @return {String}\n */\nutils.runSync = ({ settings, content, index }: MinifierOptions): string =>\n settings && typeof settings.compressor !== 'string'\n ? typeof settings.compressor === 'function'\n ? settings.compressor({ settings, content, callback: null, index })\n : ''\n : '';\n\n/**\n * Run compressor in async.\n *\n * @param {Object} settings\n * @param {String} content\n * @param {Number} index - index of the file being processed\n * @return {Promise}\n */\nutils.runAsync = ({ settings, content, index }: MinifierOptions): Promise<string> => {\n return new Promise((resolve, reject) => {\n settings && settings.compressor && typeof settings.compressor !== 'string'\n ? settings.compressor({\n settings,\n content,\n callback: (err: unknown, result?: string) => {\n if (err) {\n return reject(err);\n }\n resolve(result || '');\n },\n index\n })\n : null;\n });\n};\n\n/**\n * Expose `utils`.\n */\nexport { utils };\n"],"mappings":";AASA,SAAS,cAAc,WAAW,UAAU,YAAY,eAAe,YAAY,wBAAwB;AAC3G,OAAO,cAAc;AAyBrB,IAAM,QAAQ,CAAC;AAQf,MAAM,WAAW,CAAC,SAAyB,aAAa,MAAM,MAAM;AAUpE,MAAM,YAAY,CAAC,EAAE,MAAM,SAAS,MAAM,MAAyB;AACjE,QAAM,QAAQ,UAAU,SAAY,KAAK,KAAK,IAAI;AAClD,MAAI,CAAC,WAAW,KAAK,KAAM,WAAW,KAAK,KAAK,CAAC,UAAU,KAAK,EAAE,YAAY,GAAI;AAChF,kBAAc,OAAO,SAAS,MAAM;AAAA,EACtC;AAEA,SAAO;AACT;AAOA,MAAM,aAAa,CAAC,SAAiB,WAAW,IAAI;AAQpD,MAAM,YAAY,CAAC,YAAgE;AACjF,QAAM,OAA0B,CAAC;AACjC,SAAO,KAAK,OAAO,EAAE,QAAQ,CAAC,QAAgB;AAC5C,QAAI,QAAQ,GAAG,KAAK,QAAQ,GAAG,MAAM,OAAO;AAC1C,WAAK,KAAK,OAAO,GAAG;AAAA,IACtB;AAEA,QAAI,QAAQ,GAAG,KAAK,QAAQ,GAAG,MAAM,MAAM;AACzC,WAAK,KAAK,QAAQ,GAAG,CAAC;AAAA,IACxB;AAAA,EACF,CAAC;AAED,SAAO;AACT;AAQA,MAAM,QAAQ,CAAC,QAAwB,KAAK,MAAM,KAAK,UAAU,GAAG,CAAC;AAOrE,MAAM,qBAAqB,CAAC,SAAyB;AACnD,QAAM,QAAQ,SAAS,IAAI;AAC3B,QAAM,kBAAkB,MAAM;AAC9B,SAAO,MAAM,YAAY,eAAe;AAC1C;AAOA,MAAM,4BAA4B,CAAC,SAAkC;AACnE,SA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;AAOA,MAAM,qBAAqB,CAAC,aAAiD;AAC3E,QAAM,UAAU,SAAS,UAAU,SAAS,UAAU,SAAS,QAAQ,MAAM,oBAAoB,SAAS,KAAK,IAAI;AACnH,SAAO,SAAS,OAAO,MAAM,QAAQ,EAAE,UAAU,QAAQ,CAAC,IAAI,MAAM,SAAS,EAAE,UAAU,QAAQ,CAAC;AACpG;AAQA,MAAM,sBAAsB,CAAC,UAAqC;AAChE,MAAI,CAAC,MAAM,QAAQ,KAAK,GAAG;AACzB,WAAO,aAAa,OAAO,MAAM;AAAA,EACnC;AAEA,SAAO,MACJ;AAAA,IAAI,UACH,CAAC,WAAW,IAAI,KAAM,WAAW,IAAI,KAAK,CAAC,UAAU,IAAI,EAAE,YAAY,IAAK,aAAa,MAAM,MAAM,IAAI;AAAA,EAC3G,EACC,KAAK,IAAI;AACd;AAUA,MAAM,UAAU,CAAC,EAAE,UAAU,SAAS,MAAM,MAC1C,YAAY,OAAO,SAAS,eAAe,WACvC,OAAO,SAAS,eAAe,aAC7B,SAAS,WAAW,EAAE,UAAU,SAAS,UAAU,MAAM,MAAM,CAAC,IAChE,KACF;AAUN,MAAM,WAAW,CAAC,EAAE,UAAU,SAAS,MAAM,MAAwC;AACnF,SAAO,IAAI,QAAQ,CAAC,SAAS,WAAW;AACtC,gBAAY,SAAS,cAAc,OAAO,SAAS,eAAe,WAC9D,SAAS,WAAW;AAAA,MAClB;AAAA,MACA;AAAA,MACA,UAAU,CAAC,KAAc,WAAoB;AAC3C,YAAI,KAAK;AACP,iBAAO,OAAO,GAAG;AAAA,QACnB;AACA,gBAAQ,UAAU,EAAE;AAAA,MACtB;AAAA,MACA;AAAA,IACF,CAAC,IACD;AAAA,EACN,CAAC;AACH;","names":[]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@node-minify/utils",
3
- "version": "8.0.5-beta.0",
3
+ "version": "8.0.6",
4
4
  "description": "utils for @node-minify",
5
5
  "keywords": [
6
6
  "compressor",
@@ -48,7 +48,7 @@
48
48
  "gzip-size": "6.0.0"
49
49
  },
50
50
  "devDependencies": {
51
- "@node-minify/types": "8.0.3-beta.0"
51
+ "@node-minify/types": "8.0.6"
52
52
  },
53
- "gitHead": "22a7b887ea22743702b1dc5a613755ae20838a73"
53
+ "gitHead": "9fb532af458cb6416ecfb7abfb9cc0a3b9cb42e1"
54
54
  }