@ybgnb/file-naming 1.0.0 → 1.0.1
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/dist/index.d.ts +9 -0
- package/dist/index.js +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -157,6 +157,15 @@ interface ResolveFilePathResult {
|
|
|
157
157
|
* 路径片段(按路径分隔符拆分后的各级目录/文件名,不对应命名字段)
|
|
158
158
|
*/
|
|
159
159
|
segments: string[];
|
|
160
|
+
/**
|
|
161
|
+
* 相对路径的目录
|
|
162
|
+
* @example test/
|
|
163
|
+
*/
|
|
164
|
+
dir: '' | string;
|
|
165
|
+
/**
|
|
166
|
+
* 文件名
|
|
167
|
+
*/
|
|
168
|
+
fileName: string;
|
|
160
169
|
}
|
|
161
170
|
|
|
162
171
|
/**
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var F=(t,e)=>({[t]:{label:e??t,resolve:()=>t}}),m=t=>Object.assign({},...t.map(e=>F(e)));var
|
|
1
|
+
var F=(t,e)=>({[t]:{label:e??t,resolve:()=>t}}),m=t=>Object.assign({},...t.map(e=>F(e)));var n={serialNumber:{label:"\u5E8F\u53F7",resolve:({total:t,serialNumber:e,extendedFormats:r})=>r.serialNumberFormat==="natural"?String(e):String(e).padStart(String(t).length,"0")},total:{label:"\u603B\u6570",resolve:({total:t})=>String(t)},space:{label:"\u7A7A\u683C",resolve:()=>" "},fileSeparator:{label:"/",resolve:()=>"/"},...m(["-","_",".",",",";","\uFF08","\uFF09","(",")","[","]","{","}","+","=","~","!","@","#","$","%","^","&","\u201C","\u201D","\uFF1A"])},x=Object.keys(n);var f=/[<>:"/\\|?*\u0000-\u001F]/g,g=new Set(["CON","PRN","AUX","NUL","COM1","COM2","COM3","COM4","COM5","COM6","COM7","COM8","COM9","LPT1","LPT2","LPT3","LPT4","LPT5","LPT6","LPT7","LPT8","LPT9"]);function l(t){let e=t.trim();return e=e.replace(f,"_"),e=e.replace(/[. ]+$/,""),e.length===0?"":(g.has(e.toUpperCase())&&(e=`_${e}`),e)}var p=class{constructor(e){let{dateFormat:r,timeFormat:a,serialNumberFormat:i}=e.extendedFormats??{};this.strategy={fields:e.fields,extendedFormats:{dateFormat:r??"YYYY-MM-DD",timeFormat:a??"HH-mm-ss",serialNumberFormat:i??"zeroPad"}},this.pathSegmentTransformer=e.pathSegmentTransformer??l}buildPathSegments(e){let r=[],a="";for(let i of e){if(i==="/"){a&&(r.push(a),a="");continue}a+=i}return a&&r.push(a),r}resolveOne(e){let r={total:1,serialNumber:1,extendedFormats:this.strategy.extendedFormats,resolveDate:new Date,data:e},a=this.strategy.fields.map(s=>typeof s=="string"?n[s]?n[s].resolve(r):"":s.resolve(r)),o=this.buildPathSegments(a).filter(Boolean).map(this.pathSegmentTransformer).filter(Boolean);return{segments:o,relativePath:o.join("/"),fileName:o[o.length-1],dir:o.length>1?o.slice(0,-1).join("/"):""}}resolve(e){return Array.isArray(e)?e.map(r=>this.resolveOne(r)):this.resolveOne(e)}};var M={"YYYY-MM-DD":"2026-07-02",YYYY_MM_DD:"2026_07_02",YYYYMMDD:"20260702","YY-MM-DD":"26-07-02",YY_MM_DD:"26_07_02",YYMMDD:"260702"},S={HHmmss:"143045","HH-mm-ss":"14-30-45",HH_mm_ss:"14_30_45",HHmm:"1430","HH-mm":"14-30",HH_mm:"14_30"},T={natural:"\u81EA\u7136\u6570",zeroPad:"\u524D\u5BFC\u96F6\u586B\u5145"};export{p as FileNamer,x as allBaseFileNamingFields,n as baseFileNamingFieldMap,F as createCharNamingField,m as createCharNamingFields,M as dateFormatMap,l as defaultSanitizePathSegment,T as serialNumberFormatMap,S as timeFormatMap};
|