@unraven/env 1.0.1 → 1.0.2
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 +5 -4
- package/dist/index.js +2 -2
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -6,7 +6,7 @@ interface EnvFlags {
|
|
|
6
6
|
}
|
|
7
7
|
//#endregion
|
|
8
8
|
//#region src/formatters/types.d.ts
|
|
9
|
-
interface Groupable {
|
|
9
|
+
interface Groupable$1 {
|
|
10
10
|
name: string;
|
|
11
11
|
}
|
|
12
12
|
interface Formattable {
|
|
@@ -23,8 +23,8 @@ interface FormatterContract {
|
|
|
23
23
|
declare abstract class BaseFormatter {
|
|
24
24
|
protected type: string;
|
|
25
25
|
constructor(type: string);
|
|
26
|
-
static sort<T extends Groupable>(items: T[]): T[];
|
|
27
|
-
|
|
26
|
+
static sort<T extends Groupable$1>(items: T[]): T[];
|
|
27
|
+
toSorted<T extends Groupable$1>(items: T[]): T[];
|
|
28
28
|
}
|
|
29
29
|
//#endregion
|
|
30
30
|
//#region src/formatters/dotenv.formatter.d.ts
|
|
@@ -33,8 +33,8 @@ interface EnvFormatterOptions {
|
|
|
33
33
|
eol?: string;
|
|
34
34
|
}
|
|
35
35
|
declare class DotenvFormatter extends BaseFormatter implements FormatterContract {
|
|
36
|
-
group<T extends Groupable>(items: T[]): T[][];
|
|
37
36
|
format(items: Formattable[], options?: EnvFormatterOptions): string;
|
|
37
|
+
private group;
|
|
38
38
|
private resolvePrefix;
|
|
39
39
|
private escapeValue;
|
|
40
40
|
}
|
|
@@ -59,6 +59,7 @@ declare class Formatter<T extends Record<string, new (type: string) => Formatter
|
|
|
59
59
|
use<Type extends Format>(type: Type): InstanceType<T[Type]>;
|
|
60
60
|
detect(file: string): "json" | "yaml" | "dotenv";
|
|
61
61
|
format<Type extends Format>(type: Type, items: Formattable[], options?: Parameters<InstanceType<T[Type]>['format']>[1]): string;
|
|
62
|
+
sort<T extends Groupable>(items: T[]): T[];
|
|
62
63
|
}
|
|
63
64
|
//#endregion
|
|
64
65
|
//#region src/index.d.ts
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
var e=class{constructor(e){this.formatters=e}use(e){if(!this.formatters[e])throw Error(`Invalid format "${e}".`);return new this.formatters[e](e)}detect(e){switch(e.split(`.`).slice(1).pop()?.toLowerCase()??``){case`json`:return`json`;case`yml`:case`yaml`:return`yaml`;default:return`dotenv`}}format(e,t,n={}){return this.use(e).format(t,n)}
|
|
2
|
-
`,i=t.headers??[];i.length>0&&n.push(...i,``);let a=this.group(e);for(let e of a){for(let t of e){n.push(...t.comments??[]);let e=Object.entries(t.flags??{}).filter(([e,t])=>t&&e!==`commented`);if(e.length>0){let t=e.map(([e])=>`@${e}`).join(` `);n.push(`# ${t}`)}let r=`${t.name}=${this.escapeValue(t.value??``)}`;t.flags?.commented&&(r=`# ${r}`),n.push(r)}n.push(``)}return n.join(r)}resolvePrefix(e){let t=e.split(`_`),r=[];do r.push(t.shift());while(t.length>0&&n.includes(r.join(`_`)));return{prefix:r.join(`_`),common:r.slice(0,r.length-1).join(`_`),name:r.slice(r.length-1).join(`_`)}}escapeValue(e){return/[ \n\r\t"'\\]/.test(e)?`"${e.replace(/\\/g,`\\\\`).replace(/"/g,`\\"`).replace(/\n/g,`\\n`).replace(/\r/g,`\\r`).replace(/\t/g,`\\t`)}"`:e}},i=class extends
|
|
1
|
+
var e=class e{constructor(e){this.type=e}static sort(e){return e.toSorted((e,t)=>e.name.localeCompare(t.name))}toSorted(t){return e.sort(t)}},t=class{constructor(e){this.formatters=e}use(e){if(!this.formatters[e])throw Error(`Invalid format "${e}".`);return new this.formatters[e](e)}detect(e){switch(e.split(`.`).slice(1).pop()?.toLowerCase()??``){case`json`:return`json`;case`yml`:case`yaml`:return`yaml`;default:return`dotenv`}}format(e,t,n={}){return this.use(e).format(t,n)}sort(t){return e.sort(t)}};const n=[`NUXT`,`NUXT_PUBLIC`,`NEXT`,`NEXT_PUBLIC`,`VITE`];var r=class extends e{format(e,t={}){let n=[],r=t.eol??`
|
|
2
|
+
`,i=t.headers??[];i.length>0&&n.push(...i,``);let a=this.group(e);for(let e of a){for(let t of e){n.push(...t.comments??[]);let e=Object.entries(t.flags??{}).filter(([e,t])=>t&&e!==`commented`);if(e.length>0){let t=e.map(([e])=>`@${e}`).join(` `);n.push(`# ${t}`)}let r=`${t.name}=${this.escapeValue(t.value??``)}`;t.flags?.commented&&(r=`# ${r}`),n.push(r)}n.push(``)}return n.join(r)}group(e){let t={},n=this.toSorted(e);for(let e of n){let{common:n,prefix:r}=this.resolvePrefix(e.name),i=t[r];i||(i={items:[],common:n,name:r},t[r]=i),i.items.push(e)}return Object.values(t).sort((e,t)=>e.common.localeCompare(t.common)).map(e=>e.items)}resolvePrefix(e){let t=e.split(`_`),r=[];do r.push(t.shift());while(t.length>0&&n.includes(r.join(`_`)));return{prefix:r.join(`_`),common:r.slice(0,r.length-1).join(`_`),name:r.slice(r.length-1).join(`_`)}}escapeValue(e){return/[ \n\r\t"'\\]/.test(e)?`"${e.replace(/\\/g,`\\\\`).replace(/"/g,`\\"`).replace(/\n/g,`\\n`).replace(/\r/g,`\\r`).replace(/\t/g,`\\t`)}"`:e}},i=class extends e{format(e){let t=this.toSorted(e),n;switch(this.type){case`json_array`:n=this.asArray(t);break;default:n=this.asObject(t);break}return JSON.stringify(n,null,2)}asObject(e){return e.reduce((e,t)=>(e[t.name]=t.value,e),{})}asArray(e){return e.map(e=>({name:e.name,value:e.value}))}};const a=new t({dotenv:r,json:i,json_array:i,yaml:class extends e{format(e){return this.toSorted(e).map(e=>`${e.name}: ${this.escapeValue(e.value??``)}`).join(`
|
|
3
3
|
`)}escapeValue(e){return e.includes(`
|
|
4
4
|
`)?`|\n${e.split(`
|
|
5
5
|
`).map(e=>` ${e}`).join(`
|