presetter 3.1.1 → 3.4.0
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 +7 -7
- package/lib/content.d.ts +49 -7
- package/lib/content.js +127 -133
- package/lib/directive.js +67 -196
- package/lib/error.js +12 -36
- package/lib/executable/entry.js +55 -73
- package/lib/executable/error.js +24 -55
- package/lib/executable/index.js +5 -23
- package/lib/index.d.ts +1 -0
- package/lib/index.js +21 -69
- package/lib/io.d.ts +2 -3
- package/lib/io.js +78 -172
- package/lib/package.js +58 -149
- package/lib/preset.d.ts +6 -6
- package/lib/preset.js +149 -297
- package/lib/resolution.d.ts +4 -0
- package/lib/resolution.js +35 -0
- package/lib/run.js +59 -127
- package/lib/scripts.js +52 -128
- package/lib/template.d.ts +4 -1
- package/lib/template.js +85 -141
- package/lib/types.d.ts +24 -7
- package/lib/types.js +2 -1
- package/package.json +10 -2
- package/lib/content.js.map +0 -1
- package/lib/directive.js.map +0 -1
- package/lib/error.js.map +0 -1
- package/lib/executable/entry.js.map +0 -1
- package/lib/executable/error.js.map +0 -1
- package/lib/executable/index.js.map +0 -1
- package/lib/index.js.map +0 -1
- package/lib/io.js.map +0 -1
- package/lib/package.js.map +0 -1
- package/lib/preset.js.map +0 -1
- package/lib/run.js.map +0 -1
- package/lib/scripts.js.map +0 -1
- package/lib/template.js.map +0 -1
- package/lib/types.js.map +0 -1
package/lib/template.js.map
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"sources":["../source/template.ts"],"names":["filter","subject","ignores","fieldsToIgnore","ignore","Array","isArray","_","key","includes","distilled","Object","fromEntries","entries","moreRules","reduce","furtherDistilled","ignoreTree","map","value","filterByPath","path","isJSON","every","merge","source","replacement","replace","keys","assign","replaceArray","undefined","index","Set","values","template","content","parameter"],"mappings":";;;;;;;;;;AAeA;;;;AAfA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAiBO,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AP;AACD,GAFM,MAEA,IAAIf,MAAM,CAACc,OAAD,CAAV,EAAqB;AAC1B,WAAOzB,MAAM,CAACC,WAAP,CACLD,MAAM,CAACE,OAAP,CAAeuB,OAAf,EAAwBlB,GAAxB,CAA4B,CAAC,CAACV,GAAD,EAAMW,KAAN,CAAD,KAAkB;AAC5C,aAAO,CAACgB,QAAQ,CAAC3B,GAAD,EAAM6B,SAAN,CAAT,EAA2BF,QAAQ,CAAChB,KAAD,EAAQkB,SAAR,CAAnC,CAAP;AACD,KAFD,CADK,CAAP;AAKD,GANM,MAMA;AACL,WAAOD,OAAP;AACD;AACF;AAED","sourcesContent":["/*\n * *** MIT LICENSE ***\n * -------------------------------------------------------------------------\n * This code may be modified and distributed under the MIT license.\n * See the LICENSE file for details.\n * -------------------------------------------------------------------------\n *\n * @summary Collection of template related helpers\n *\n * @author Alvis HT Tang <alvis@hilbert.space>\n * @license MIT\n * @copyright Copyright (c) 2020 - All Rights Reserved.\n * -------------------------------------------------------------------------\n */\n\nimport pupa from 'pupa';\n\nimport type { IgnorePath, IgnoreRule } from './types';\n\n/**\n * filter fields in an object according to the given rules\n * @param subject an object to be filtered\n * @param ignores a list of ignore rules\n * @returns filtered content\n */\nexport function filter<C extends Record<string, unknown>>(\n subject: C,\n ...ignores: IgnoreRule[]\n): C;\nexport function filter(subject: unknown[], ...ignores: IgnoreRule[]): unknown[];\nexport function filter(\n subject: Record<string, unknown> | unknown[],\n ...ignores: IgnoreRule[]\n): Record<string, unknown> | unknown[] {\n // compute the list of fields in config to be ignored\n const fieldsToIgnore = ignores.filter(\n (ignore): ignore is string | number => typeof ignore !== 'object',\n );\n\n // filter the unwanted item in an array\n if (Array.isArray(subject)) {\n return subject.filter((_, key) => !fieldsToIgnore.includes(key));\n }\n\n // filter the unwanted fields below\n const distilled = Object.fromEntries(\n Object.entries(subject).filter(([key, _]) => !fieldsToIgnore.includes(key)),\n );\n\n // compute the left over and process them further below\n const moreRules = ignores.filter(\n (ignore): ignore is Record<string, IgnorePath> =>\n typeof ignore !== 'string',\n );\n\n // continue filtering the left over\n return moreRules.reduce(\n (furtherDistilled, ignoreTree) =>\n Object.fromEntries(\n Object.entries(furtherDistilled).map(\n ([key, value]): [string, unknown] => [\n key,\n filterByPath(value, ignoreTree[key]),\n ],\n ),\n ),\n distilled,\n );\n}\n\n/**\n * filter a value according to the supplied ignore rules\n * @param value value to be filtered\n * @param path ignore rule to be applied\n * @returns filtered value\n */\nfunction filterByPath(value: unknown, path?: IgnorePath): unknown {\n return path && typeof value === 'object'\n ? filter(\n value as Record<string, unknown>,\n // NOTE\n // if rule is an array, it means that it contains a list of fields to be ignored\n // otherwise, it contains rules in a tree form\n ...(Array.isArray(path) ? path : [path]),\n )\n : value;\n}\n\n/**\n * indicate whether the supplied value is a JSON object\n * @param subject the subject to be tested\n * @returns true if the subject is a JSON object\n */\nexport function isJSON(subject: unknown): subject is Record<string, any> {\n return [\n typeof subject === 'object',\n !Array.isArray(subject),\n subject !== null,\n ].every((value) => value);\n}\n\n/* eslint-disable @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-return */\n\n/**\n * deep merge an object\n * @param source default object if no additional property is supplied\n * @param replacement properties to be merged with the default\n * @returns merged object\n */\nexport function merge<Source extends Record<string, any> | unknown[]>(\n source: Source,\n replacement?: Record<string, any> | unknown[],\n): Source {\n if (Array.isArray(source)) {\n return replace(source, replacement);\n }\n\n const keys = [...Object.keys(source), ...Object.keys(replacement ?? {})];\n\n const entries: Array<[string, any]> = keys.map((key) => [\n key,\n replace(source[key], replacement?.[key]),\n ]);\n\n return Object.assign(\n {},\n ...entries.map(([key, value]) => ({\n [key]: value,\n })),\n );\n}\n\n/**\n * replace source according to the replacement instruction\n * @param source source value if there's no replacement\n * @param replacement value to be merged with the default\n * @returns merged value\n */\nfunction replace(source: unknown, replacement: unknown): any {\n // LOGIC\n // S\\R | Array | Object | Primitive\n // Array | EXTEND | AMEND | replace\n // Object | replace | MERGE | replace\n // Primitive | replace | replace | replace\n\n if (Array.isArray(source)) {\n return replaceArray(source, replacement);\n } else if (isJSON(source) && isJSON(replacement)) {\n // deep merge any objects\n return merge(source, replacement);\n }\n\n // primitive values\n return replacement === undefined ? source : replacement;\n}\n\n/**\n * replace an array source according to the replacement instruction\n * @param source source value if there's no replacement\n * @param replacement value to be merged with the default\n * @returns merged value\n */\nfunction replaceArray(source: unknown[], replacement: unknown): any {\n if (isJSON(replacement)) {\n // overwrite a list\n return source.map((value, index) => replace(value, replacement[index]));\n } else if (Array.isArray(replacement)) {\n // extend a list uniquely\n return [...new Set([...source, ...replacement]).values()];\n } else {\n // primitive values\n return replacement ?? source;\n }\n}\n\n/**\n * replace parameters in the template\n * @param content template content\n * @param parameter variables to be substituted in the template\n */\nexport function template(\n content: string,\n parameter: Record<string, string>,\n): string;\nexport function template<Content extends Record<string, unknown> | unknown[]>(\n content: Content,\n parameter: Record<string, string>,\n): Content;\nexport function template(\n content: unknown,\n parameter: Record<string, string>,\n): unknown;\nexport function template(\n content: string | Record<string, unknown> | unknown | unknown[],\n parameter: Record<string, string>,\n): string | Record<string, unknown> | unknown | unknown[] {\n if (typeof content === 'string') {\n return pupa(content, parameter);\n } else if (Array.isArray(content)) {\n return content.map((value) => template(value, parameter));\n } else if (isJSON(content)) {\n return Object.fromEntries(\n Object.entries(content).map(([key, value]) => {\n return [template(key, parameter), template(value, parameter)];\n }),\n );\n } else {\n return content;\n }\n}\n\n/* eslint-enable @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-return */\n"],"file":"template.js"}
|
package/lib/types.js.map
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"sources":[],"names":[],"mappings":"","sourcesContent":[],"file":"types.js"}
|