@isdk/util 0.1.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/README.md +6 -0
- package/dist/chunk-3TCMKKX2.mjs +1 -0
- package/dist/chunk-46TT3NZV.mjs +1 -0
- package/dist/chunk-7APJBRA7.mjs +1 -0
- package/dist/chunk-7AQU3PBW.mjs +1 -0
- package/dist/chunk-D3BCI5SM.mjs +1 -0
- package/dist/chunk-FXF2KJLF.mjs +1 -0
- package/dist/chunk-GGOKSJK4.mjs +1 -0
- package/dist/chunk-JTTOXXPG.mjs +1 -0
- package/dist/chunk-LOMQZH4U.mjs +292 -0
- package/dist/chunk-OTEAFARC.mjs +1 -0
- package/dist/chunk-UJZVJIGI.mjs +1 -0
- package/dist/config-file.d.mts +75 -0
- package/dist/config-file.d.ts +75 -0
- package/dist/config-file.js +1 -0
- package/dist/config-file.mjs +1 -0
- package/dist/config-file.test.d.mts +2 -0
- package/dist/config-file.test.d.ts +2 -0
- package/dist/config-file.test.js +292 -0
- package/dist/config-file.test.mjs +1 -0
- package/dist/front-matter.d.mts +6 -0
- package/dist/front-matter.d.ts +6 -0
- package/dist/front-matter.js +1 -0
- package/dist/front-matter.mjs +1 -0
- package/dist/front-matter.test.d.mts +2 -0
- package/dist/front-matter.test.d.ts +2 -0
- package/dist/front-matter.test.js +1 -0
- package/dist/front-matter.test.mjs +1 -0
- package/dist/get-multi-level-extname.d.mts +9 -0
- package/dist/get-multi-level-extname.d.ts +9 -0
- package/dist/get-multi-level-extname.js +1 -0
- package/dist/get-multi-level-extname.mjs +1 -0
- package/dist/glob.d.mts +28 -0
- package/dist/glob.d.ts +28 -0
- package/dist/glob.js +1 -0
- package/dist/glob.mjs +1 -0
- package/dist/glob.test.d.mts +2 -0
- package/dist/glob.test.d.ts +2 -0
- package/dist/glob.test.js +292 -0
- package/dist/glob.test.mjs +1 -0
- package/dist/include-files.d.mts +31 -0
- package/dist/include-files.d.ts +31 -0
- package/dist/include-files.js +1 -0
- package/dist/include-files.mjs +1 -0
- package/dist/include-files.test.d.mts +2 -0
- package/dist/include-files.test.d.ts +2 -0
- package/dist/include-files.test.js +292 -0
- package/dist/include-files.test.mjs +1 -0
- package/dist/index.d.mts +11 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.js +1 -0
- package/dist/index.mjs +1 -0
- package/dist/is-string-in.d.mts +19 -0
- package/dist/is-string-in.d.ts +19 -0
- package/dist/is-string-in.js +1 -0
- package/dist/is-string-in.mjs +1 -0
- package/dist/magic-string.es-TUA2PMWY.mjs +1 -0
- package/dist/remove-leading-empty-lines.d.mts +18 -0
- package/dist/remove-leading-empty-lines.d.ts +18 -0
- package/dist/remove-leading-empty-lines.js +1 -0
- package/dist/remove-leading-empty-lines.mjs +1 -0
- package/dist/remove-leading-empty-lines.test.d.mts +2 -0
- package/dist/remove-leading-empty-lines.test.d.ts +2 -0
- package/dist/remove-leading-empty-lines.test.js +1 -0
- package/dist/remove-leading-empty-lines.test.mjs +1 -0
- package/dist/traverse-folder.d.mts +56 -0
- package/dist/traverse-folder.d.ts +56 -0
- package/dist/traverse-folder.js +1 -0
- package/dist/traverse-folder.mjs +1 -0
- package/dist/traverse-folder.test.d.mts +2 -0
- package/dist/traverse-folder.test.d.ts +2 -0
- package/dist/traverse-folder.test.js +292 -0
- package/dist/traverse-folder.test.mjs +1 -0
- package/dist/yaml.d.mts +59 -0
- package/dist/yaml.d.ts +59 -0
- package/dist/yaml.js +1 -0
- package/dist/yaml.mjs +1 -0
- package/docs/README.md +10 -0
- package/docs/classes/ConfigFile.md +169 -0
- package/docs/functions/getMultiLevelExtname.md +33 -0
- package/docs/functions/glob.md +56 -0
- package/docs/functions/isStringIn.md +43 -0
- package/docs/functions/normalizeIncludeFiles.md +49 -0
- package/docs/functions/parseFrontMatter.md +33 -0
- package/docs/functions/parseYaml.md +45 -0
- package/docs/functions/registerYamlTag.md +37 -0
- package/docs/functions/removeLeadingEmptyLines.md +39 -0
- package/docs/functions/stringifyYaml.md +45 -0
- package/docs/functions/traverseFolder.md +44 -0
- package/docs/functions/traverseFolderSync.md +44 -0
- package/docs/globals.md +36 -0
- package/docs/interfaces/IncludeFiles.md +25 -0
- package/docs/type-aliases/TraverseFolderHandler.md +33 -0
- package/docs/type-aliases/TraverseFolderSyncHandler.md +33 -0
- package/docs/variables/DefaultAllTextFiles.md +11 -0
- package/package.json +68 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{DefaultAllTextFiles as e,normalizeIncludeFiles as d}from"./chunk-GGOKSJK4.mjs";import{describe as l,globalExpect as n,it as s}from"./chunk-LOMQZH4U.mjs";import{init_esm_shims as o}from"./chunk-UJZVJIGI.mjs";o(),l("normalizeIncludeFiles",(()=>{s("should use default files when no patterns are provided",(()=>{const l=d([]);n(l).toEqual(e)})),s("should handle a simple array of include patterns",(()=>{const e=d(["**/*.ts","**/*.js"]);n(e).toEqual(["**/*.ts","**/*.js"])})),s("should handle an object with include and exclude patterns",(()=>{const e=d({include:["**/*.ts","**/*.js"],exclude:["**/node_modules/**"]});n(e).toEqual(["**/*.ts","**/*.js","!**/node_modules/**"])})),s("should fallback to default files when include is empty",(()=>{const l=d({include:[],exclude:["**/node_modules/**"]});n(l).toEqual([...e,"!**/node_modules/**"])})),s("should handle only exclude patterns with default include",(()=>{const l=d({exclude:["**/dist/**","**/build/**"]});n(l).toEqual([...e,"!**/dist/**","!**/build/**"])})),s("should handle an empty object as input",(()=>{const l=d({});n(l).toEqual(e)})),s("should handle undefined input gracefully",(()=>{const l=d(void 0);n(l).toEqual(e)}))}));
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export { ConfigFile } from './config-file.mjs';
|
|
2
|
+
export { glob } from './glob.mjs';
|
|
3
|
+
export { isStringIn } from './is-string-in.mjs';
|
|
4
|
+
export { DefaultAllTextFiles, IncludeFiles, normalizeIncludeFiles } from './include-files.mjs';
|
|
5
|
+
export { parseFrontMatter } from './front-matter.mjs';
|
|
6
|
+
export { getMultiLevelExtname } from './get-multi-level-extname.mjs';
|
|
7
|
+
export { removeLeadingEmptyLines } from './remove-leading-empty-lines.mjs';
|
|
8
|
+
export { TraverseFolderHandler, TraverseFolderSyncHandler, traverseFolder, traverseFolderSync } from './traverse-folder.mjs';
|
|
9
|
+
export { parseYaml, registerYamlTag, stringifyYaml } from './yaml.mjs';
|
|
10
|
+
import 'fs';
|
|
11
|
+
import 'yaml';
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export { ConfigFile } from './config-file.js';
|
|
2
|
+
export { glob } from './glob.js';
|
|
3
|
+
export { isStringIn } from './is-string-in.js';
|
|
4
|
+
export { DefaultAllTextFiles, IncludeFiles, normalizeIncludeFiles } from './include-files.js';
|
|
5
|
+
export { parseFrontMatter } from './front-matter.js';
|
|
6
|
+
export { getMultiLevelExtname } from './get-multi-level-extname.js';
|
|
7
|
+
export { removeLeadingEmptyLines } from './remove-leading-empty-lines.js';
|
|
8
|
+
export { TraverseFolderHandler, TraverseFolderSyncHandler, traverseFolder, traverseFolderSync } from './traverse-folder.js';
|
|
9
|
+
export { parseYaml, registerYamlTag, stringifyYaml } from './yaml.js';
|
|
10
|
+
import 'fs';
|
|
11
|
+
import 'yaml';
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var e,t=Object.create,r=Object.defineProperty,n=Object.getOwnPropertyDescriptor,i=Object.getOwnPropertyNames,s=Object.getPrototypeOf,o=Object.prototype.hasOwnProperty,f=(e,t,s,f)=>{if(t&&"object"==typeof t||"function"==typeof t)for(let a of i(t))o.call(e,a)||a===s||r(e,a,{get:()=>t[a],enumerable:!(f=n(t,a))||f.enumerable});return e},a=(e,n,i)=>(i=null!=e?t(s(e)):{},f(!n&&e&&e.__esModule?i:r(i,"default",{value:e,enumerable:!0}),e)),c={};((e,t)=>{for(var n in t)r(e,n,{get:t[n],enumerable:!0})})(c,{ConfigFile:()=>F,DefaultAllTextFiles:()=>A,getMultiLevelExtname:()=>y,glob:()=>T,isStringIn:()=>k,normalizeIncludeFiles:()=>L,parseFrontMatter:()=>q,parseYaml:()=>d,registerYamlTag:()=>b,removeLeadingEmptyLines:()=>j,stringifyYaml:()=>h,traverseFolder:()=>M,traverseFolderSync:()=>Y}),module.exports=(e=c,f(r({},"__esModule",{value:!0}),e));var u=require("fs"),l=a(require("path")),m=require("load-config-file"),p=a(require("path"));function y(e,t=1){let r="";for(;t--;){const t=p.default.extname(e);if(!t)break;r=t+r,e=p.default.basename(e,t)}return r}var v=require("yaml"),g=[];function b(e){Array.isArray(e)||(e=[e]);for(const t of e){-1===g.indexOf(t)&&g.push(t)}}function d(e,t){if(t)if(t.customTags){if(Array.isArray(t.customTags))t.customTags=g.concat(t.customTags);else if("function"==typeof t.customTags){const e=t.customTags;t.customTags=t=>e(g.concat(t))}}else t.customTags=g;else t={customTags:g};return(0,v.parse)(e,t)}function h(e,t){if(t)if(t.customTags){if(Array.isArray(t.customTags))t.customTags=g.concat(t.customTags);else if("function"==typeof t.customTags){const e=t.customTags;t.customTags=t=>e(g.concat(t))}}else t.customTags=g;else t={customTags:g};return(0,v.stringify)(e,t)}function j(e){const t=/^\s*(#[^\r\n]*)?[\r\n]+/;let r;for(;null!==(r=t.exec(e))&&((e=e.substring(r[0].length)).startsWith("\n")||e.startsWith("\r")||e.trimStart().startsWith("#")););return e}var x="---";function q(e,t=x){const r=t.length,n=j(e);if(n.startsWith(t)&&("\n"===n[t.length]||"\r"===n[t.length])){let e=n.indexOf("\n"+t,r);if(-1!==e){const i=n.slice(r,e);for(e+=t.length+1;"\n"===n[e]||"\r"===n[e];)e++;const s=n.slice(e);return{data:d(i)||{},content:s}}}return{data:{},content:e}}var F=class{static register(e,t,r){m.Config.register(e,t),"string"==typeof e&&(e=[e]);for(const t of e)this.stringifys[t]=r}static load(e,t){return function(e,{extLevel:t=1,externalFile:r}={}){"."===e[0]&&t++;const n=y(e,t);n&&n.split(".").length>1&&(e=e.slice(0,-n.length));let i=m.Config.loadSync(e);if(!i&&r){if(!l.default.isAbsolute(r)){const t=l.default.dirname(e);r=l.default.join(t,r)}if((0,u.existsSync)(r)){const e=q((0,u.readFileSync)(r,"utf8")).data;Object.keys(e).length&&(i=e)}}return i}(e,t)}static save(e,t,r){return function(e,t,{extLevel:r=1}={}){"."===e[0]&&r++;let n=y(e,r);(!n||n.split(".").length<=1)&&(e+=".yaml",n=".yaml");const i=F.stringifys[n];if(!i)throw new Error(`${e} unsupported mime type: ${n}`);t=i(t);const s=l.default.dirname(e);(0,u.existsSync)(s)||(0,u.mkdirSync)(s,{recursive:!0});return(0,u.writeFileSync)(e,t,{encoding:"utf8"}),e}(e,t,r)}};F.stringifys={},F.register([".yml",".yaml"],d,h),F.register([".json"],(function(e){return JSON.parse(e)}),(e=>JSON.stringify(e,null,2)));var O=require("@isdk/glob"),w=a(require("path"));function T(e,t,r){return r&&(e=w.default.relative(r,e)),(0,O.globMatch)(e,t)}function k(e,t){return"string"==typeof t&&(t=[t]),-1!==t.indexOf(e)}var A=["**/*.((j|t)s?(x)|m(j|t)s)?(x)","**/*.(md|markdown|txt|?(x)htm?(l)|yaml|yml|xml|json|bat|sh|bash|zsh|ini|css|scss|less|sass|py|rb|php|go|java|c|cpp|h|hpp|hxx|rust|zig)"];function L(e,t=A){if(e)if(Array.isArray(e))e=[...e];else{const r=e.include||[],n=e.exclude||[];0===r.length&&r.push(...t),e=[...r];for(const t of n)e.push(`!${t}`)}else e=[...t];return 0===e.length&&e.push(...t),e}var S=require("fs/promises"),z=require("fs"),E=a(require("path"));async function M(e,t){const r=await(0,S.readdir)(e,{withFileTypes:!0,recursive:!0});for(const n of r){const r=E.default.join(e,n.name);if(!0===await t(r,n))break}}function Y(e,t){const r=(0,z.readdirSync)(e,{withFileTypes:!0,recursive:!0});for(const n of r){if(!0===t(E.default.join(e,n.name),n))break}}
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{isStringIn as m}from"./chunk-FXF2KJLF.mjs";import{traverseFolder as o,traverseFolderSync as r}from"./chunk-46TT3NZV.mjs";import{ConfigFile as p}from"./chunk-3TCMKKX2.mjs";import{parseFrontMatter as t}from"./chunk-JTTOXXPG.mjs";import{removeLeadingEmptyLines as c}from"./chunk-D3BCI5SM.mjs";import{parseYaml as f,registerYamlTag as h,stringifyYaml as i}from"./chunk-OTEAFARC.mjs";import{getMultiLevelExtname as j}from"./chunk-7AQU3PBW.mjs";import{glob as k}from"./chunk-7APJBRA7.mjs";import{DefaultAllTextFiles as n,normalizeIncludeFiles as s}from"./chunk-GGOKSJK4.mjs";import{init_esm_shims as u}from"./chunk-UJZVJIGI.mjs";u();export{p as ConfigFile,n as DefaultAllTextFiles,j as getMultiLevelExtname,k as glob,m as isStringIn,s as normalizeIncludeFiles,t as parseFrontMatter,f as parseYaml,h as registerYamlTag,c as removeLeadingEmptyLines,i as stringifyYaml,o as traverseFolder,r as traverseFolderSync};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Checks if a given string exists within an array of strings or a single string.
|
|
3
|
+
*
|
|
4
|
+
* @param str - The string to search for.
|
|
5
|
+
* @param arr - An array of strings or a single string to search within.
|
|
6
|
+
* @returns Returns `true` if the string is found, otherwise `false`.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```typescript
|
|
10
|
+
* const result = isStringIn("apple", ["banana", "apple", "cherry"]);
|
|
11
|
+
* console.log(result); // true
|
|
12
|
+
*
|
|
13
|
+
* const singleResult = isStringIn("hello", "hello");
|
|
14
|
+
* console.log(singleResult); // true
|
|
15
|
+
* ```
|
|
16
|
+
*/
|
|
17
|
+
declare function isStringIn(str: string, arr: string[] | string): boolean;
|
|
18
|
+
|
|
19
|
+
export { isStringIn };
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Checks if a given string exists within an array of strings or a single string.
|
|
3
|
+
*
|
|
4
|
+
* @param str - The string to search for.
|
|
5
|
+
* @param arr - An array of strings or a single string to search within.
|
|
6
|
+
* @returns Returns `true` if the string is found, otherwise `false`.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```typescript
|
|
10
|
+
* const result = isStringIn("apple", ["banana", "apple", "cherry"]);
|
|
11
|
+
* console.log(result); // true
|
|
12
|
+
*
|
|
13
|
+
* const singleResult = isStringIn("hello", "hello");
|
|
14
|
+
* console.log(singleResult); // true
|
|
15
|
+
* ```
|
|
16
|
+
*/
|
|
17
|
+
declare function isStringIn(str: string, arr: string[] | string): boolean;
|
|
18
|
+
|
|
19
|
+
export { isStringIn };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var e,t=Object.defineProperty,r=Object.getOwnPropertyDescriptor,n=Object.getOwnPropertyNames,o=Object.prototype.hasOwnProperty,u={};function f(e,t){return"string"==typeof t&&(t=[t]),-1!==t.indexOf(e)}((e,r)=>{for(var n in r)t(e,n,{get:r[n],enumerable:!0})})(u,{isStringIn:()=>f}),module.exports=(e=u,((e,u,f,c)=>{if(u&&"object"==typeof u||"function"==typeof u)for(let i of n(u))o.call(e,i)||i===f||t(e,i,{get:()=>u[i],enumerable:!(c=r(u,i))||c.enumerable});return e})(t({},"__esModule",{value:!0}),e));
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{isStringIn as m}from"./chunk-FXF2KJLF.mjs";import"./chunk-UJZVJIGI.mjs";export{m as isStringIn};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{init_esm_shims as t}from"./chunk-UJZVJIGI.mjs";t(),t();var i=",".charCodeAt(0),s=";".charCodeAt(0),e="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",r=new Uint8Array(64),n=new Uint8Array(128);for(let t=0;t<64;t++){const i=e.charCodeAt(t);r[t]=i,n[i]=t}function h(t,i,s){let e=i-s;e=e<0?-e<<1|1:e<<1;do{let i=31&e;e>>>=5,e>0&&(i|=32),t.write(r[i])}while(e>0);return i}var o="undefined"!=typeof TextDecoder?new TextDecoder:"undefined"!=typeof Buffer?{decode:t=>Buffer.from(t.buffer,t.byteOffset,t.byteLength).toString()}:{decode(t){let i="";for(let s=0;s<t.length;s++)i+=String.fromCharCode(t[s]);return i}},a=class{constructor(){this.pos=0,this.out="",this.buffer=new Uint8Array(16384)}write(t){const{buffer:i}=this;i[this.pos++]=t,16384===this.pos&&(this.out+=o.decode(i),this.pos=0)}flush(){const{buffer:t,out:i,pos:s}=this;return s>0?i+o.decode(t.subarray(0,s)):i}};var u=class t{constructor(i){this.bits=i instanceof t?i.bits.slice():[]}add(t){this.bits[t>>5]|=1<<(31&t)}has(t){return!!(this.bits[t>>5]&1<<(31&t))}},c=class t{constructor(t,i,s){this.start=t,this.end=i,this.original=s,this.intro="",this.outro="",this.content=s,this.storeName=!1,this.edited=!1,this.previous=null,this.next=null}appendLeft(t){this.outro+=t}appendRight(t){this.intro=this.intro+t}clone(){const i=new t(this.start,this.end,this.original);return i.intro=this.intro,i.outro=this.outro,i.content=this.content,i.storeName=this.storeName,i.edited=this.edited,i}contains(t){return this.start<t&&t<this.end}eachNext(t){let i=this;for(;i;)t(i),i=i.next}eachPrevious(t){let i=this;for(;i;)t(i),i=i.previous}edit(t,i,s){return this.content=t,s||(this.intro="",this.outro=""),this.storeName=i,this.edited=!0,this}prependLeft(t){this.outro=t+this.outro}prependRight(t){this.intro=t+this.intro}reset(){this.intro="",this.outro="",this.edited&&(this.content=this.original,this.storeName=!1,this.edited=!1)}split(i){const s=i-this.start,e=this.original.slice(0,s),r=this.original.slice(s);this.original=e;const n=new t(i,this.end,r);return n.outro=this.outro,this.outro="",this.end=i,this.edited?(n.edit("",!1),this.content=""):this.content=e,n.next=this.next,n.next&&(n.next.previous=n),n.previous=this,this.next=n,n}toString(){return this.intro+this.content+this.outro}trimEnd(t){if(this.outro=this.outro.replace(t,""),this.outro.length)return!0;const i=this.content.replace(t,"");return i.length?(i!==this.content&&(this.split(this.start+i.length).edit("",void 0,!0),this.edited&&this.edit(i,this.storeName,!0)),!0):(this.edit("",void 0,!0),this.intro=this.intro.replace(t,""),!!this.intro.length||void 0)}trimStart(t){if(this.intro=this.intro.replace(t,""),this.intro.length)return!0;const i=this.content.replace(t,"");if(i.length){if(i!==this.content){const t=this.split(this.end-i.length);this.edited&&t.edit(i,this.storeName,!0),this.edit("",void 0,!0)}return!0}return this.edit("",void 0,!0),this.outro=this.outro.replace(t,""),!!this.outro.length||void 0}};function l(){return"undefined"!=typeof globalThis&&"function"==typeof globalThis.btoa?t=>globalThis.btoa(unescape(encodeURIComponent(t))):"function"==typeof Buffer?t=>Buffer.from(t,"utf-8").toString("base64"):()=>{throw new Error("Unsupported environment: `window.btoa` or `Buffer` should be supported.")}}var f=l(),d=class{constructor(t){this.version=3,this.file=t.file,this.sources=t.sources,this.sourcesContent=t.sourcesContent,this.names=t.names,this.mappings=function(t){const e=new a;let r=0,n=0,o=0,u=0;for(let a=0;a<t.length;a++){const c=t[a];if(a>0&&e.write(s),0===c.length)continue;let l=0;for(let t=0;t<c.length;t++){const s=c[t];t>0&&e.write(i),l=h(e,s[0],l),1!==s.length&&(r=h(e,s[1],r),n=h(e,s[2],n),o=h(e,s[3],o),4!==s.length&&(u=h(e,s[4],u)))}}return e.flush()}(t.mappings),void 0!==t.x_google_ignoreList&&(this.x_google_ignoreList=t.x_google_ignoreList),void 0!==t.debugId&&(this.debugId=t.debugId)}toString(){return JSON.stringify(this)}toUrl(){return"data:application/json;charset=utf-8;base64,"+f(this.toString())}};function p(t,i){const s=t.split(/[/\\]/),e=i.split(/[/\\]/);for(s.pop();s[0]===e[0];)s.shift(),e.shift();if(s.length){let t=s.length;for(;t--;)s[t]=".."}return s.concat(e).join("/")}var w=Object.prototype.toString;function g(t){return"[object Object]"===w.call(t)}function m(t){const i=t.split("\n"),s=[];for(let t=0,e=0;t<i.length;t++)s.push(e),e+=i[t].length+1;return function(t){let i=0,e=s.length;for(;i<e;){const r=i+e>>1;t<s[r]?e=r:i=r+1}const r=i-1;return{line:r,column:t-s[r]}}}var b=/\w/,v=class{constructor(t){this.hires=t,this.generatedCodeLine=0,this.generatedCodeColumn=0,this.raw=[],this.rawSegments=this.raw[this.generatedCodeLine]=[],this.pending=null}addEdit(t,i,s,e){if(i.length){const r=i.length-1;let n=i.indexOf("\n",0),h=-1;for(;n>=0&&r>n;){const r=[this.generatedCodeColumn,t,s.line,s.column];e>=0&&r.push(e),this.rawSegments.push(r),this.generatedCodeLine+=1,this.raw[this.generatedCodeLine]=this.rawSegments=[],this.generatedCodeColumn=0,h=n,n=i.indexOf("\n",n+1)}const o=[this.generatedCodeColumn,t,s.line,s.column];e>=0&&o.push(e),this.rawSegments.push(o),this.advance(i.slice(h+1))}else this.pending&&(this.rawSegments.push(this.pending),this.advance(i));this.pending=null}addUneditedChunk(t,i,s,e,r){let n=i.start,h=!0,o=!1;for(;n<i.end;){if("\n"===s[n])e.line+=1,e.column=0,this.generatedCodeLine+=1,this.raw[this.generatedCodeLine]=this.rawSegments=[],this.generatedCodeColumn=0,h=!0,o=!1;else{if(this.hires||h||r.has(n)){const i=[this.generatedCodeColumn,t,e.line,e.column];"boundary"===this.hires?b.test(s[n])?o||(this.rawSegments.push(i),o=!0):(this.rawSegments.push(i),o=!1):this.rawSegments.push(i)}e.column+=1,this.generatedCodeColumn+=1,h=!1}n+=1}this.pending=null}advance(t){if(!t)return;const i=t.split("\n");if(i.length>1){for(let t=0;t<i.length-1;t++)this.generatedCodeLine++,this.raw[this.generatedCodeLine]=this.rawSegments=[];this.generatedCodeColumn=0}this.generatedCodeColumn+=i[i.length-1].length}},E="\n",y={insertLeft:!1,insertRight:!1,storeName:!1},S=class t{constructor(t,i={}){const s=new c(0,t.length,t);Object.defineProperties(this,{original:{writable:!0,value:t},outro:{writable:!0,value:""},intro:{writable:!0,value:""},firstChunk:{writable:!0,value:s},lastChunk:{writable:!0,value:s},lastSearchedChunk:{writable:!0,value:s},byStart:{writable:!0,value:{}},byEnd:{writable:!0,value:{}},filename:{writable:!0,value:i.filename},indentExclusionRanges:{writable:!0,value:i.indentExclusionRanges},sourcemapLocations:{writable:!0,value:new u},storedNames:{writable:!0,value:{}},indentStr:{writable:!0,value:void 0},ignoreList:{writable:!0,value:i.ignoreList},offset:{writable:!0,value:i.offset||0}}),this.byStart[0]=s,this.byEnd[t.length]=s}addSourcemapLocation(t){this.sourcemapLocations.add(t)}append(t){if("string"!=typeof t)throw new TypeError("outro content must be a string");return this.outro+=t,this}appendLeft(t,i){if(t+=this.offset,"string"!=typeof i)throw new TypeError("inserted content must be a string");this._split(t);const s=this.byEnd[t];return s?s.appendLeft(i):this.intro+=i,this}appendRight(t,i){if(t+=this.offset,"string"!=typeof i)throw new TypeError("inserted content must be a string");this._split(t);const s=this.byStart[t];return s?s.appendRight(i):this.outro+=i,this}clone(){const i=new t(this.original,{filename:this.filename,offset:this.offset});let s=this.firstChunk,e=i.firstChunk=i.lastSearchedChunk=s.clone();for(;s;){i.byStart[e.start]=e,i.byEnd[e.end]=e;const t=s.next,r=t&&t.clone();r&&(e.next=r,r.previous=e,e=r),s=t}return i.lastChunk=e,this.indentExclusionRanges&&(i.indentExclusionRanges=this.indentExclusionRanges.slice()),i.sourcemapLocations=new u(this.sourcemapLocations),i.intro=this.intro,i.outro=this.outro,i}generateDecodedMap(t){t=t||{};const i=Object.keys(this.storedNames),s=new v(t.hires),e=m(this.original);return this.intro&&s.advance(this.intro),this.firstChunk.eachNext((t=>{const r=e(t.start);t.intro.length&&s.advance(t.intro),t.edited?s.addEdit(0,t.content,r,t.storeName?i.indexOf(t.original):-1):s.addUneditedChunk(0,t,this.original,r,this.sourcemapLocations),t.outro.length&&s.advance(t.outro)})),{file:t.file?t.file.split(/[/\\]/).pop():void 0,sources:[t.source?p(t.file||"",t.source):t.file||""],sourcesContent:t.includeContent?[this.original]:void 0,names:i,mappings:s.raw,x_google_ignoreList:this.ignoreList?[0]:void 0}}generateMap(t){return new d(this.generateDecodedMap(t))}_ensureindentStr(){void 0===this.indentStr&&(this.indentStr=function(t){const i=t.split("\n"),s=i.filter((t=>/^\t+/.test(t))),e=i.filter((t=>/^ {2,}/.test(t)));if(0===s.length&&0===e.length)return null;if(s.length>=e.length)return"\t";const r=e.reduce(((t,i)=>{const s=/^ +/.exec(i)[0].length;return Math.min(s,t)}),1/0);return new Array(r+1).join(" ")}(this.original))}_getRawIndentString(){return this._ensureindentStr(),this.indentStr}getIndentString(){return this._ensureindentStr(),null===this.indentStr?"\t":this.indentStr}indent(t,i){const s=/^[^\r\n]/gm;if(g(t)&&(i=t,t=void 0),void 0===t&&(this._ensureindentStr(),t=this.indentStr||"\t"),""===t)return this;const e={};if((i=i||{}).exclude){("number"==typeof i.exclude[0]?[i.exclude]:i.exclude).forEach((t=>{for(let i=t[0];i<t[1];i+=1)e[i]=!0}))}let r=!1!==i.indentStart;const n=i=>r?`${t}${i}`:(r=!0,i);this.intro=this.intro.replace(s,n);let h=0,o=this.firstChunk;for(;o;){const i=o.end;if(o.edited)e[h]||(o.content=o.content.replace(s,n),o.content.length&&(r="\n"===o.content[o.content.length-1]));else for(h=o.start;h<i;){if(!e[h]){const i=this.original[h];"\n"===i?r=!0:"\r"!==i&&r&&(r=!1,h===o.start||(this._splitChunk(o,h),o=o.next),o.prependRight(t))}h+=1}h=o.end,o=o.next}return this.outro=this.outro.replace(s,n),this}insert(){throw new Error("magicString.insert(...) is deprecated. Use prependRight(...) or appendLeft(...)")}insertLeft(t,i){return y.insertLeft||(console.warn("magicString.insertLeft(...) is deprecated. Use magicString.appendLeft(...) instead"),y.insertLeft=!0),this.appendLeft(t,i)}insertRight(t,i){return y.insertRight||(console.warn("magicString.insertRight(...) is deprecated. Use magicString.prependRight(...) instead"),y.insertRight=!0),this.prependRight(t,i)}move(t,i,s){if(t+=this.offset,i+=this.offset,(s+=this.offset)>=t&&s<=i)throw new Error("Cannot move a selection inside itself");this._split(t),this._split(i),this._split(s);const e=this.byStart[t],r=this.byEnd[i],n=e.previous,h=r.next,o=this.byStart[s];if(!o&&r===this.lastChunk)return this;const a=o?o.previous:this.lastChunk;return n&&(n.next=h),h&&(h.previous=n),a&&(a.next=e),o&&(o.previous=r),e.previous||(this.firstChunk=r.next),r.next||(this.lastChunk=e.previous,this.lastChunk.next=null),e.previous=a,r.next=o||null,a||(this.firstChunk=e),o||(this.lastChunk=r),this}overwrite(t,i,s,e){return e=e||{},this.update(t,i,s,{...e,overwrite:!e.contentOnly})}update(t,i,s,e){if(t+=this.offset,i+=this.offset,"string"!=typeof s)throw new TypeError("replacement content must be a string");if(0!==this.original.length){for(;t<0;)t+=this.original.length;for(;i<0;)i+=this.original.length}if(i>this.original.length)throw new Error("end is out of bounds");if(t===i)throw new Error("Cannot overwrite a zero-length range – use appendLeft or prependRight instead");this._split(t),this._split(i),!0===e&&(y.storeName||(console.warn("The final argument to magicString.overwrite(...) should be an options object. See https://github.com/rich-harris/magic-string"),y.storeName=!0),e={storeName:!0});const r=void 0!==e&&e.storeName,n=void 0!==e&&e.overwrite;if(r){const s=this.original.slice(t,i);Object.defineProperty(this.storedNames,s,{writable:!0,value:!0,enumerable:!0})}const h=this.byStart[t],o=this.byEnd[i];if(h){let t=h;for(;t!==o;){if(t.next!==this.byStart[t.end])throw new Error("Cannot overwrite across a split point");t=t.next,t.edit("",!1)}h.edit(s,r,!n)}else{const e=new c(t,i,"").edit(s,r);o.next=e,e.previous=o}return this}prepend(t){if("string"!=typeof t)throw new TypeError("outro content must be a string");return this.intro=t+this.intro,this}prependLeft(t,i){if(t+=this.offset,"string"!=typeof i)throw new TypeError("inserted content must be a string");this._split(t);const s=this.byEnd[t];return s?s.prependLeft(i):this.intro=i+this.intro,this}prependRight(t,i){if(t+=this.offset,"string"!=typeof i)throw new TypeError("inserted content must be a string");this._split(t);const s=this.byStart[t];return s?s.prependRight(i):this.outro=i+this.outro,this}remove(t,i){if(t+=this.offset,i+=this.offset,0!==this.original.length){for(;t<0;)t+=this.original.length;for(;i<0;)i+=this.original.length}if(t===i)return this;if(t<0||i>this.original.length)throw new Error("Character is out of bounds");if(t>i)throw new Error("end must be greater than start");this._split(t),this._split(i);let s=this.byStart[t];for(;s;)s.intro="",s.outro="",s.edit(""),s=i>s.end?this.byStart[s.end]:null;return this}reset(t,i){if(t+=this.offset,i+=this.offset,0!==this.original.length){for(;t<0;)t+=this.original.length;for(;i<0;)i+=this.original.length}if(t===i)return this;if(t<0||i>this.original.length)throw new Error("Character is out of bounds");if(t>i)throw new Error("end must be greater than start");this._split(t),this._split(i);let s=this.byStart[t];for(;s;)s.reset(),s=i>s.end?this.byStart[s.end]:null;return this}lastChar(){if(this.outro.length)return this.outro[this.outro.length-1];let t=this.lastChunk;do{if(t.outro.length)return t.outro[t.outro.length-1];if(t.content.length)return t.content[t.content.length-1];if(t.intro.length)return t.intro[t.intro.length-1]}while(t=t.previous);return this.intro.length?this.intro[this.intro.length-1]:""}lastLine(){let t=this.outro.lastIndexOf(E);if(-1!==t)return this.outro.substr(t+1);let i=this.outro,s=this.lastChunk;do{if(s.outro.length>0){if(t=s.outro.lastIndexOf(E),-1!==t)return s.outro.substr(t+1)+i;i=s.outro+i}if(s.content.length>0){if(t=s.content.lastIndexOf(E),-1!==t)return s.content.substr(t+1)+i;i=s.content+i}if(s.intro.length>0){if(t=s.intro.lastIndexOf(E),-1!==t)return s.intro.substr(t+1)+i;i=s.intro+i}}while(s=s.previous);return t=this.intro.lastIndexOf(E),-1!==t?this.intro.substr(t+1)+i:this.intro+i}slice(t=0,i=this.original.length-this.offset){if(t+=this.offset,i+=this.offset,0!==this.original.length){for(;t<0;)t+=this.original.length;for(;i<0;)i+=this.original.length}let s="",e=this.firstChunk;for(;e&&(e.start>t||e.end<=t);){if(e.start<i&&e.end>=i)return s;e=e.next}if(e&&e.edited&&e.start!==t)throw new Error(`Cannot use replaced character ${t} as slice start anchor.`);const r=e;for(;e;){!e.intro||r===e&&e.start!==t||(s+=e.intro);const n=e.start<i&&e.end>=i;if(n&&e.edited&&e.end!==i)throw new Error(`Cannot use replaced character ${i} as slice end anchor.`);const h=r===e?t-e.start:0,o=n?e.content.length+i-e.end:e.content.length;if(s+=e.content.slice(h,o),!e.outro||n&&e.end!==i||(s+=e.outro),n)break;e=e.next}return s}snip(t,i){const s=this.clone();return s.remove(0,t),s.remove(i,s.original.length),s}_split(t){if(this.byStart[t]||this.byEnd[t])return;let i=this.lastSearchedChunk;const s=t>i.end;for(;i;){if(i.contains(t))return this._splitChunk(i,t);i=s?this.byStart[i.end]:this.byEnd[i.start]}}_splitChunk(t,i){if(t.edited&&t.content.length){const s=m(this.original)(i);throw new Error(`Cannot split a chunk that has already been edited (${s.line}:${s.column} – "${t.original}")`)}const s=t.split(i);return this.byEnd[i]=t,this.byStart[i]=s,this.byEnd[s.end]=s,t===this.lastChunk&&(this.lastChunk=s),this.lastSearchedChunk=t,!0}toString(){let t=this.intro,i=this.firstChunk;for(;i;)t+=i.toString(),i=i.next;return t+this.outro}isEmpty(){let t=this.firstChunk;do{if(t.intro.length&&t.intro.trim()||t.content.length&&t.content.trim()||t.outro.length&&t.outro.trim())return!1}while(t=t.next);return!0}length(){let t=this.firstChunk,i=0;do{i+=t.intro.length+t.content.length+t.outro.length}while(t=t.next);return i}trimLines(){return this.trim("[\\r\\n]")}trim(t){return this.trimStart(t).trimEnd(t)}trimEndAborted(t){const i=new RegExp((t||"\\s")+"+$");if(this.outro=this.outro.replace(i,""),this.outro.length)return!0;let s=this.lastChunk;do{const t=s.end,e=s.trimEnd(i);if(s.end!==t&&(this.lastChunk===s&&(this.lastChunk=s.next),this.byEnd[s.end]=s,this.byStart[s.next.start]=s.next,this.byEnd[s.next.end]=s.next),e)return!0;s=s.previous}while(s);return!1}trimEnd(t){return this.trimEndAborted(t),this}trimStartAborted(t){const i=new RegExp("^"+(t||"\\s")+"+");if(this.intro=this.intro.replace(i,""),this.intro.length)return!0;let s=this.firstChunk;do{const t=s.end,e=s.trimStart(i);if(s.end!==t&&(s===this.lastChunk&&(this.lastChunk=s.next),this.byEnd[s.end]=s,this.byStart[s.next.start]=s.next,this.byEnd[s.next.end]=s.next),e)return!0;s=s.next}while(s);return!1}trimStart(t){return this.trimStartAborted(t),this}hasChanged(){return this.original!==this.toString()}_replaceRegexp(t,i){function s(t,s){return"string"==typeof i?i.replace(/\$(\$|&|\d+)/g,((i,s)=>{if("$"===s)return"$";if("&"===s)return t[0];return+s<t.length?t[+s]:`$${s}`})):i(...t,t.index,s,t.groups)}if(t.global){(function(t,i){let s;const e=[];for(;s=t.exec(i);)e.push(s);return e})(t,this.original).forEach((t=>{if(null!=t.index){const i=s(t,this.original);i!==t[0]&&this.overwrite(t.index,t.index+t[0].length,i)}}))}else{const i=this.original.match(t);if(i&&null!=i.index){const t=s(i,this.original);t!==i[0]&&this.overwrite(i.index,i.index+i[0].length,t)}}return this}_replaceString(t,i){const{original:s}=this,e=s.indexOf(t);return-1!==e&&this.overwrite(e,e+t.length,i),this}replace(t,i){return"string"==typeof t?this._replaceString(t,i):this._replaceRegexp(t,i)}_replaceAllString(t,i){const{original:s}=this,e=t.length;for(let r=s.indexOf(t);-1!==r;r=s.indexOf(t,r+e)){s.slice(r,r+e)!==i&&this.overwrite(r,r+e,i)}return this}replaceAll(t,i){if("string"==typeof t)return this._replaceAllString(t,i);if(!t.global)throw new TypeError("MagicString.prototype.replaceAll called with a non-global RegExp argument");return this._replaceRegexp(t,i)}},R=Object.prototype.hasOwnProperty,L=class t{constructor(t={}){this.intro=t.intro||"",this.separator=void 0!==t.separator?t.separator:"\n",this.sources=[],this.uniqueSources=[],this.uniqueSourceIndexByFilename={}}addSource(t){if(t instanceof S)return this.addSource({content:t,filename:t.filename,separator:this.separator});if(!g(t)||!t.content)throw new Error("bundle.addSource() takes an object with a `content` property, which should be an instance of MagicString, and an optional `filename`");if(["filename","ignoreList","indentExclusionRanges","separator"].forEach((i=>{R.call(t,i)||(t[i]=t.content[i])})),void 0===t.separator&&(t.separator=this.separator),t.filename)if(R.call(this.uniqueSourceIndexByFilename,t.filename)){const i=this.uniqueSources[this.uniqueSourceIndexByFilename[t.filename]];if(t.content.original!==i.content)throw new Error(`Illegal source: same filename (${t.filename}), different contents`)}else this.uniqueSourceIndexByFilename[t.filename]=this.uniqueSources.length,this.uniqueSources.push({filename:t.filename,content:t.content.original});return this.sources.push(t),this}append(t,i){return this.addSource({content:new S(t),separator:i&&i.separator||""}),this}clone(){const i=new t({intro:this.intro,separator:this.separator});return this.sources.forEach((t=>{i.addSource({filename:t.filename,content:t.content.clone(),separator:t.separator})})),i}generateDecodedMap(t={}){const i=[];let s;this.sources.forEach((t=>{Object.keys(t.content.storedNames).forEach((t=>{~i.indexOf(t)||i.push(t)}))}));const e=new v(t.hires);return this.intro&&e.advance(this.intro),this.sources.forEach(((t,r)=>{r>0&&e.advance(this.separator);const n=t.filename?this.uniqueSourceIndexByFilename[t.filename]:-1,h=t.content,o=m(h.original);h.intro&&e.advance(h.intro),h.firstChunk.eachNext((s=>{const r=o(s.start);s.intro.length&&e.advance(s.intro),t.filename?s.edited?e.addEdit(n,s.content,r,s.storeName?i.indexOf(s.original):-1):e.addUneditedChunk(n,s,h.original,r,h.sourcemapLocations):e.advance(s.content),s.outro.length&&e.advance(s.outro)})),h.outro&&e.advance(h.outro),t.ignoreList&&-1!==n&&(void 0===s&&(s=[]),s.push(n))})),{file:t.file?t.file.split(/[/\\]/).pop():void 0,sources:this.uniqueSources.map((i=>t.file?p(t.file,i.filename):i.filename)),sourcesContent:this.uniqueSources.map((i=>t.includeContent?i.content:null)),names:i,mappings:e.raw,x_google_ignoreList:s}}generateMap(t){return new d(this.generateDecodedMap(t))}getIndentString(){const t={};return this.sources.forEach((i=>{const s=i.content._getRawIndentString();null!==s&&(t[s]||(t[s]=0),t[s]+=1)})),Object.keys(t).sort(((i,s)=>t[i]-t[s]))[0]||"\t"}indent(t){if(arguments.length||(t=this.getIndentString()),""===t)return this;let i=!this.intro||"\n"===this.intro.slice(-1);return this.sources.forEach(((s,e)=>{const r=void 0!==s.separator?s.separator:this.separator,n=i||e>0&&/\r?\n$/.test(r);s.content.indent(t,{exclude:s.indentExclusionRanges,indentStart:n}),i="\n"===s.content.lastChar()})),this.intro&&(this.intro=t+this.intro.replace(/^[^\n]/gm,((i,s)=>s>0?t+i:i))),this}prepend(t){return this.intro=t+this.intro,this}toString(){const t=this.sources.map(((t,i)=>{const s=void 0!==t.separator?t.separator:this.separator;return(i>0?s:"")+t.content.toString()})).join("");return this.intro+t}isEmpty(){return(!this.intro.length||!this.intro.trim())&&!this.sources.some((t=>!t.content.isEmpty()))}length(){return this.sources.reduce(((t,i)=>t+i.content.length()),this.intro.length)}trimLines(){return this.trim("[\\r\\n]")}trim(t){return this.trimStart(t).trimEnd(t)}trimStart(t){const i=new RegExp("^"+(t||"\\s")+"+");if(this.intro=this.intro.replace(i,""),!this.intro){let i,s=0;do{if(i=this.sources[s++],!i)break}while(!i.content.trimStartAborted(t))}return this}trimEnd(t){const i=new RegExp((t||"\\s")+"+$");let s,e=this.sources.length-1;do{if(s=this.sources[e--],!s){this.intro=this.intro.replace(i,"");break}}while(!s.content.trimEndAborted(t));return this}};export{L as Bundle,d as SourceMap,S as default};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Removes all leading empty lines or "#" comments line from the given string.
|
|
3
|
+
*
|
|
4
|
+
* This function trims any sequence of empty lines that appear at the beginning
|
|
5
|
+
* of the input string. It accounts for different newline characters including
|
|
6
|
+
* '\n', '\r\n', and also considers lines that contain only whitespace characters.
|
|
7
|
+
*
|
|
8
|
+
* @param text - The string from which to remove leading empty lines.
|
|
9
|
+
* @returns The string with leading empty lines removed.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* const sampleText = '# This is a comment\n\nHello, world!\n';
|
|
13
|
+
* const cleanedText = removeLeadingEmptyLines(sampleText);
|
|
14
|
+
* // cleanedText is now 'Hello, world!\n'
|
|
15
|
+
*/
|
|
16
|
+
declare function removeLeadingEmptyLines(text: string): string;
|
|
17
|
+
|
|
18
|
+
export { removeLeadingEmptyLines };
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Removes all leading empty lines or "#" comments line from the given string.
|
|
3
|
+
*
|
|
4
|
+
* This function trims any sequence of empty lines that appear at the beginning
|
|
5
|
+
* of the input string. It accounts for different newline characters including
|
|
6
|
+
* '\n', '\r\n', and also considers lines that contain only whitespace characters.
|
|
7
|
+
*
|
|
8
|
+
* @param text - The string from which to remove leading empty lines.
|
|
9
|
+
* @returns The string with leading empty lines removed.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* const sampleText = '# This is a comment\n\nHello, world!\n';
|
|
13
|
+
* const cleanedText = removeLeadingEmptyLines(sampleText);
|
|
14
|
+
* // cleanedText is now 'Hello, world!\n'
|
|
15
|
+
*/
|
|
16
|
+
declare function removeLeadingEmptyLines(text: string): string;
|
|
17
|
+
|
|
18
|
+
export { removeLeadingEmptyLines };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var e,t=Object.defineProperty,n=Object.getOwnPropertyDescriptor,r=Object.getOwnPropertyNames,o=Object.prototype.hasOwnProperty,u={};function c(e){const t=/^\s*(#[^\r\n]*)?[\r\n]+/;let n;for(;null!==(n=t.exec(e))&&((e=e.substring(n[0].length)).startsWith("\n")||e.startsWith("\r")||e.trimStart().startsWith("#")););return e}((e,n)=>{for(var r in n)t(e,r,{get:n[r],enumerable:!0})})(u,{removeLeadingEmptyLines:()=>c}),module.exports=(e=u,((e,u,c,f)=>{if(u&&"object"==typeof u||"function"==typeof u)for(let l of r(u))o.call(e,l)||l===c||t(e,l,{get:()=>u[l],enumerable:!(f=n(u,l))||f.enumerable});return e})(t({},"__esModule",{value:!0}),e));
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{removeLeadingEmptyLines as m}from"./chunk-D3BCI5SM.mjs";import"./chunk-UJZVJIGI.mjs";export{m as removeLeadingEmptyLines};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";function n(n){const e=/^\s*(#[^\r\n]*)?[\r\n]+/;let t;for(;null!==(t=e.exec(n))&&((n=n.substring(t[0].length)).startsWith("\n")||n.startsWith("\r")||n.trimStart().startsWith("#")););return n}describe("removeLeadingEmptyLines",(()=>{it("should remove leading empty lines",(()=>{expect(n("\n\n 这是一个示例文本,\n 它前面有若干空行。\n ")).toBe(" 这是一个示例文本,\n 它前面有若干空行。\n ")})),it("should handle strings with no leading empty lines",(()=>{expect(n("没有空行的文本")).toBe("没有空行的文本")})),it("should handle strings with only empty lines",(()=>{expect(n(" \n \n")).toBe("")})),it("should correctly handle different line endings",(()=>{expect(n("\r\n\r\n内容开始")).toBe("内容开始")})),it("should remove line comments too",(()=>{expect(n("# this is a comments one\n\r# this is a comments 2\n\n内容开始1\n\n内容开始")).toBe("内容开始1\n\n内容开始")})),it("should not remove line comments",(()=>{const e="---\n# this is a comments one\n\r# this is a comments 2\n\n内容开始1\n\n内容开始",t=e;expect(n(e)).toBe(t)}))}));
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{removeLeadingEmptyLines as n}from"./chunk-D3BCI5SM.mjs";import{init_esm_shims as e}from"./chunk-UJZVJIGI.mjs";e(),describe("removeLeadingEmptyLines",(()=>{it("should remove leading empty lines",(()=>{expect(n("\n\n 这是一个示例文本,\n 它前面有若干空行。\n ")).toBe(" 这是一个示例文本,\n 它前面有若干空行。\n ")})),it("should handle strings with no leading empty lines",(()=>{expect(n("没有空行的文本")).toBe("没有空行的文本")})),it("should handle strings with only empty lines",(()=>{expect(n(" \n \n")).toBe("")})),it("should correctly handle different line endings",(()=>{expect(n("\r\n\r\n内容开始")).toBe("内容开始")})),it("should remove line comments too",(()=>{expect(n("# this is a comments one\n\r# this is a comments 2\n\n内容开始1\n\n内容开始")).toBe("内容开始1\n\n内容开始")})),it("should not remove line comments",(()=>{const e="---\n# this is a comments one\n\r# this is a comments 2\n\n内容开始1\n\n内容开始",t=e;expect(n(e)).toBe(t)}))}));
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { Dirent } from 'fs';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* A handler function for asynchronous folder traversal.
|
|
5
|
+
* @param filePath - The full path of the file or directory.
|
|
6
|
+
* @param entry - The directory entry (file or folder).
|
|
7
|
+
* @returns Returns `true` to stop further traversal, or `false`/`void` to continue.
|
|
8
|
+
*/
|
|
9
|
+
type TraverseFolderHandler = (filePath: string, entry: Dirent) => boolean | void | Promise<boolean | void>;
|
|
10
|
+
/**
|
|
11
|
+
* A handler function for synchronous folder traversal.
|
|
12
|
+
* @param filePath - The full path of the file or directory.
|
|
13
|
+
* @param entry - The directory entry (file or folder).
|
|
14
|
+
* @returns Returns `true` to stop further traversal, or `false` to continue.
|
|
15
|
+
*/
|
|
16
|
+
type TraverseFolderSyncHandler = (filePath: string, entry: Dirent) => boolean | void;
|
|
17
|
+
/**
|
|
18
|
+
* Traverses a folder asynchronously and applies a handler to each file or directory.
|
|
19
|
+
*
|
|
20
|
+
* @param directoryPath - The root directory to start traversal.
|
|
21
|
+
* @param fileHandler - A handler function called for each file/directory.
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* ```typescript
|
|
25
|
+
* await traverseFolder('/path/to/folder', async (filePath, entry) => {
|
|
26
|
+
* console.log(`Found: ${filePath}`);
|
|
27
|
+
* if (entry.name === 'stopfile.txt') {
|
|
28
|
+
* console.log('Stopping traversal...');
|
|
29
|
+
* return true; // Stops further traversal
|
|
30
|
+
* }
|
|
31
|
+
* return false; // Continues traversal
|
|
32
|
+
* });
|
|
33
|
+
* ```
|
|
34
|
+
*/
|
|
35
|
+
declare function traverseFolder(directoryPath: string, fileHandler: TraverseFolderHandler): Promise<void>;
|
|
36
|
+
/**
|
|
37
|
+
* Traverses a folder synchronously and applies a handler to each file or directory.
|
|
38
|
+
*
|
|
39
|
+
* @param directoryPath - The root directory to start traversal.
|
|
40
|
+
* @param fileHandler - A handler function called for each file/directory.
|
|
41
|
+
*
|
|
42
|
+
* @example
|
|
43
|
+
* ```typescript
|
|
44
|
+
* traverseFolderSync('/path/to/folder', (filePath, entry) => {
|
|
45
|
+
* console.log(`Found: ${filePath}`);
|
|
46
|
+
* if (entry.name === 'stopfile.txt') {
|
|
47
|
+
* console.log('Stopping traversal...');
|
|
48
|
+
* return true; // Stops further traversal
|
|
49
|
+
* }
|
|
50
|
+
* return false; // Continues traversal
|
|
51
|
+
* });
|
|
52
|
+
* ```
|
|
53
|
+
*/
|
|
54
|
+
declare function traverseFolderSync(directoryPath: string, fileHandler: TraverseFolderSyncHandler): void;
|
|
55
|
+
|
|
56
|
+
export { type TraverseFolderHandler, type TraverseFolderSyncHandler, traverseFolder, traverseFolderSync };
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { Dirent } from 'fs';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* A handler function for asynchronous folder traversal.
|
|
5
|
+
* @param filePath - The full path of the file or directory.
|
|
6
|
+
* @param entry - The directory entry (file or folder).
|
|
7
|
+
* @returns Returns `true` to stop further traversal, or `false`/`void` to continue.
|
|
8
|
+
*/
|
|
9
|
+
type TraverseFolderHandler = (filePath: string, entry: Dirent) => boolean | void | Promise<boolean | void>;
|
|
10
|
+
/**
|
|
11
|
+
* A handler function for synchronous folder traversal.
|
|
12
|
+
* @param filePath - The full path of the file or directory.
|
|
13
|
+
* @param entry - The directory entry (file or folder).
|
|
14
|
+
* @returns Returns `true` to stop further traversal, or `false` to continue.
|
|
15
|
+
*/
|
|
16
|
+
type TraverseFolderSyncHandler = (filePath: string, entry: Dirent) => boolean | void;
|
|
17
|
+
/**
|
|
18
|
+
* Traverses a folder asynchronously and applies a handler to each file or directory.
|
|
19
|
+
*
|
|
20
|
+
* @param directoryPath - The root directory to start traversal.
|
|
21
|
+
* @param fileHandler - A handler function called for each file/directory.
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* ```typescript
|
|
25
|
+
* await traverseFolder('/path/to/folder', async (filePath, entry) => {
|
|
26
|
+
* console.log(`Found: ${filePath}`);
|
|
27
|
+
* if (entry.name === 'stopfile.txt') {
|
|
28
|
+
* console.log('Stopping traversal...');
|
|
29
|
+
* return true; // Stops further traversal
|
|
30
|
+
* }
|
|
31
|
+
* return false; // Continues traversal
|
|
32
|
+
* });
|
|
33
|
+
* ```
|
|
34
|
+
*/
|
|
35
|
+
declare function traverseFolder(directoryPath: string, fileHandler: TraverseFolderHandler): Promise<void>;
|
|
36
|
+
/**
|
|
37
|
+
* Traverses a folder synchronously and applies a handler to each file or directory.
|
|
38
|
+
*
|
|
39
|
+
* @param directoryPath - The root directory to start traversal.
|
|
40
|
+
* @param fileHandler - A handler function called for each file/directory.
|
|
41
|
+
*
|
|
42
|
+
* @example
|
|
43
|
+
* ```typescript
|
|
44
|
+
* traverseFolderSync('/path/to/folder', (filePath, entry) => {
|
|
45
|
+
* console.log(`Found: ${filePath}`);
|
|
46
|
+
* if (entry.name === 'stopfile.txt') {
|
|
47
|
+
* console.log('Stopping traversal...');
|
|
48
|
+
* return true; // Stops further traversal
|
|
49
|
+
* }
|
|
50
|
+
* return false; // Continues traversal
|
|
51
|
+
* });
|
|
52
|
+
* ```
|
|
53
|
+
*/
|
|
54
|
+
declare function traverseFolderSync(directoryPath: string, fileHandler: TraverseFolderSyncHandler): void;
|
|
55
|
+
|
|
56
|
+
export { type TraverseFolderHandler, type TraverseFolderSyncHandler, traverseFolder, traverseFolderSync };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var e,r=Object.create,t=Object.defineProperty,o=Object.getOwnPropertyDescriptor,c=Object.getOwnPropertyNames,i=Object.getPrototypeOf,a=Object.prototype.hasOwnProperty,n=(e,r,i,n)=>{if(r&&"object"==typeof r||"function"==typeof r)for(let s of c(r))a.call(e,s)||s===i||t(e,s,{get:()=>r[s],enumerable:!(n=o(r,s))||n.enumerable});return e},s={};((e,r)=>{for(var o in r)t(e,o,{get:r[o],enumerable:!0})})(s,{traverseFolder:()=>b,traverseFolderSync:()=>v}),module.exports=(e=s,n(t({},"__esModule",{value:!0}),e));var u=require("fs/promises"),f=require("fs"),l=((e,o,c)=>(c=null!=e?r(i(e)):{},n(!o&&e&&e.__esModule?c:t(c,"default",{value:e,enumerable:!0}),e)))(require("path"));async function b(e,r){const t=await(0,u.readdir)(e,{withFileTypes:!0,recursive:!0});for(const o of t){const t=l.default.join(e,o.name);if(!0===await r(t,o))break}}function v(e,r){const t=(0,f.readdirSync)(e,{withFileTypes:!0,recursive:!0});for(const o of t){if(!0===r(l.default.join(e,o.name),o))break}}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{traverseFolder as m,traverseFolderSync as o}from"./chunk-46TT3NZV.mjs";import"./chunk-UJZVJIGI.mjs";export{m as traverseFolder,o as traverseFolderSync};
|