@next-box/i18n 0.0.4 → 0.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 +1 -1
- package/dist/cjs/index.cjs +1 -1
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs/macros.cjs +1 -1
- package/dist/cjs/macros.cjs.map +1 -1
- package/dist/esm/index.mjs +1 -1
- package/dist/esm/index.mjs.map +1 -1
- package/dist/esm/macros.mjs +1 -1
- package/dist/esm/macros.mjs.map +1 -1
- package/dist/production.analysis.txt +6 -6
- package/dist/types/cjs/index.d.cts +0 -2
- package/dist/types/cjs/index.d.cts.map +1 -1
- package/dist/types/cjs/macros.d.cts.map +1 -1
- package/dist/types/esm/index.d.ts +0 -2
- package/dist/types/esm/index.d.ts.map +1 -1
- package/dist/types/esm/macros.d.ts.map +1 -1
- package/dist/types/tsconfig.build.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/src/index.ts +0 -2
- package/src/macros.test.ts +3 -3
- package/src/macros.ts +6 -3
package/README.md
CHANGED
|
@@ -150,7 +150,7 @@ import { md } from '@next-box/i18n/macros' with { type: 'macro' }; // This is im
|
|
|
150
150
|
|
|
151
151
|
const content = {
|
|
152
152
|
en: {
|
|
153
|
-
contactUs: md('./
|
|
153
|
+
contactUs: md('./markdown/contactUs.md'), // relative to the file's directory
|
|
154
154
|
},
|
|
155
155
|
} as const;
|
|
156
156
|
```
|
package/dist/cjs/index.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var r=require("zcb");exports.createI18n=e=>{const t=r.createConfigReader(e);return{t:(r,e)=>t.read(r,e),tt:(r,e)=>{const a=t.read(r,e);if(!a)throw new Error(`Path "${String(r)}" did not resolve to a value`);return a}}};
|
|
2
2
|
//# sourceMappingURL=index.cjs.map
|
package/dist/cjs/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","sources":["../i18n/src//
|
|
1
|
+
{"version":3,"file":"index.cjs","sources":["../i18n/src//main.ts"],"sourcesContent":["import { type AnyRecord, type Path, createConfigReader } from 'zcb';\nimport { type CreateI18nResult } from '#types.ts';\n\nexport const createI18n = <U extends object>(i18n: U): CreateI18nResult<U> => {\n const reader = createConfigReader<U>(i18n);\n\n return {\n // @ts-expect-error intentionally ignoring the type checking here as\n // function is supposed to be untyped.\n t: (key: string, variables?: AnyRecord): string | undefined => reader.read(key, variables),\n tt: <P extends Path<U>>(path: P, variables?: AnyRecord) => {\n const result = reader.read(path, variables);\n\n // This can resolve to a falsy value at runtime\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition\n if (!result) {\n throw new Error(`Path \"${String(path)}\" did not resolve to a value`);\n }\n\n return result;\n },\n };\n};\n"],"names":["i18n","reader","createConfigReader","t","key","variables","read","tt","path","result","Error","String"],"mappings":"qDAG6CA,IAC3C,MAAMC,EAASC,EAAsBF,mBAAAA,GAErC,MAAO,CAGLG,EAAG,CAACC,EAAaC,IAA8CJ,EAAOK,KAAKF,EAAKC,GAChFE,GAAI,CAAoBC,EAASH,KAC/B,MAAMI,EAASR,EAAOK,KAAKE,EAAMH,GAIjC,IAAKI,EACH,MAAM,IAAIC,MAAM,SAASC,OAAOH,kCAGlC,OAAOC"}
|
package/dist/cjs/macros.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var e=require("node:fs"),r=require("node:path");exports.md=
|
|
1
|
+
"use strict";var e=require("node:fs"),r=require("node:path"),n=require("node:url"),t="undefined"!=typeof document?document.currentScript:null;const o=r.dirname(n.fileURLToPath("undefined"==typeof document?require("url").pathToFileURL(__filename).href:t&&"SCRIPT"===t.tagName.toUpperCase()&&t.src||new URL("macros.cjs",document.baseURI).href));exports.md=n=>{if(!n)throw new Error("md expected a path, but received none");const t=r.resolve(o,n);return e.readFileSync(t,{encoding:"utf8"}).trim()};
|
|
2
2
|
//# sourceMappingURL=macros.cjs.map
|
package/dist/cjs/macros.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"macros.cjs","sources":["../i18n/src//macros.ts"],"sourcesContent":["import { readFileSync } from 'node:fs';\nimport { resolve } from 'node:path';\n\nexport const md = <P extends string>(path: P): P => {\n if (!path) {\n throw new Error('
|
|
1
|
+
{"version":3,"file":"macros.cjs","sources":["../i18n/src//macros.ts"],"sourcesContent":["import { readFileSync } from 'node:fs';\nimport { dirname, resolve } from 'node:path';\nimport { fileURLToPath } from 'node:url';\n\nconst dir = dirname(fileURLToPath(import.meta.url));\n\nexport const md = <P extends string>(path: P): P => {\n if (!path) {\n throw new Error('md expected a path, but received none');\n }\n\n const fullPath = resolve(dir, path);\n // @ts-expect-error `md` function runs and build time and its return value\n // replaces the `md` invocation. We are forcing the return type to be the\n // input type to aid type inference when using `createI18n` and its\n // `tt` content resolvers.\n return readFileSync(fullPath, { encoding: 'utf8' }).trim();\n};\n"],"names":["dir","dirname","fileURLToPath","document","require","pathToFileURL","__filename","href","_documentCurrentScript","tagName","toUpperCase","src","URL","baseURI","path","Error","fullPath","resolve","readFileSync","encoding","trim"],"mappings":"8IAIA,MAAMA,EAAMC,EAAAA,QAAQC,gBAAc,oBAAAC,SAAAC,QAAA,OAAAC,cAAAC,YAAAC,KAAAC,GAAA,WAAAA,EAAAC,QAAAC,eAAAF,EAAAG,KAAA,IAAAC,IAAA,aAAAT,SAAAU,SAAAN,kBAEGO,IACnC,IAAKA,EACH,MAAM,IAAIC,MAAM,yCAGlB,MAAMC,EAAWC,EAAAA,QAAQjB,EAAKc,GAK9B,OAAOI,EAAAA,aAAaF,EAAU,CAAEG,SAAU,SAAUC"}
|
package/dist/esm/index.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{createConfigReader as r}from"zcb";const t=t=>{const o=r(t);return{t:(r,t)=>o.read(r,t),tt:(r,t)=>{const e=o.read(r,t);if(!e)throw new Error(`Path "${String(r)}" did not resolve to a value`);return e}}};export{t as createI18n};
|
|
2
2
|
//# sourceMappingURL=index.mjs.map
|
package/dist/esm/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","sources":["../i18n/src//
|
|
1
|
+
{"version":3,"file":"index.mjs","sources":["../i18n/src//main.ts"],"sourcesContent":["import { type AnyRecord, type Path, createConfigReader } from 'zcb';\nimport { type CreateI18nResult } from '#types.ts';\n\nexport const createI18n = <U extends object>(i18n: U): CreateI18nResult<U> => {\n const reader = createConfigReader<U>(i18n);\n\n return {\n // @ts-expect-error intentionally ignoring the type checking here as\n // function is supposed to be untyped.\n t: (key: string, variables?: AnyRecord): string | undefined => reader.read(key, variables),\n tt: <P extends Path<U>>(path: P, variables?: AnyRecord) => {\n const result = reader.read(path, variables);\n\n // This can resolve to a falsy value at runtime\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition\n if (!result) {\n throw new Error(`Path \"${String(path)}\" did not resolve to a value`);\n }\n\n return result;\n },\n };\n};\n"],"names":["createI18n","i18n","reader","createConfigReader","t","key","variables","read","tt","path","result","Error","String"],"mappings":"yCAGO,MAAMA,EAAgCC,IAC3C,MAAMC,EAASC,EAAsBF,GAErC,MAAO,CAGLG,EAAG,CAACC,EAAaC,IAA8CJ,EAAOK,KAAKF,EAAKC,GAChFE,GAAI,CAAoBC,EAASH,KAC/B,MAAMI,EAASR,EAAOK,KAAKE,EAAMH,GAIjC,IAAKI,EACH,MAAM,IAAIC,MAAM,SAASC,OAAOH,kCAGlC,OAAOC"}
|
package/dist/esm/macros.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{readFileSync as
|
|
1
|
+
import{readFileSync as r}from"node:fs";import{dirname as o,resolve as t}from"node:path";import{fileURLToPath as e}from"node:url";const n=o(e(import.meta.url)),m=o=>{if(!o)throw new Error("md expected a path, but received none");const e=t(n,o);return r(e,{encoding:"utf8"}).trim()};export{m as md};
|
|
2
2
|
//# sourceMappingURL=macros.mjs.map
|
package/dist/esm/macros.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"macros.mjs","sources":["../i18n/src//macros.ts"],"sourcesContent":["import { readFileSync } from 'node:fs';\nimport { resolve } from 'node:path';\n\nexport const md = <P extends string>(path: P): P => {\n if (!path) {\n throw new Error('
|
|
1
|
+
{"version":3,"file":"macros.mjs","sources":["../i18n/src//macros.ts"],"sourcesContent":["import { readFileSync } from 'node:fs';\nimport { dirname, resolve } from 'node:path';\nimport { fileURLToPath } from 'node:url';\n\nconst dir = dirname(fileURLToPath(import.meta.url));\n\nexport const md = <P extends string>(path: P): P => {\n if (!path) {\n throw new Error('md expected a path, but received none');\n }\n\n const fullPath = resolve(dir, path);\n // @ts-expect-error `md` function runs and build time and its return value\n // replaces the `md` invocation. We are forcing the return type to be the\n // input type to aid type inference when using `createI18n` and its\n // `tt` content resolvers.\n return readFileSync(fullPath, { encoding: 'utf8' }).trim();\n};\n"],"names":["dir","dirname","fileURLToPath","url","md","path","Error","fullPath","resolve","readFileSync","encoding","trim"],"mappings":"iIAIA,MAAMA,EAAMC,EAAQC,cAA0BC,MAEjCC,EAAwBC,IACnC,IAAKA,EACH,MAAM,IAAIC,MAAM,yCAGlB,MAAMC,EAAWC,EAAQR,EAAKK,GAK9B,OAAOI,EAAaF,EAAU,CAAEG,SAAU,SAAUC"}
|
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
-----------------------------
|
|
2
2
|
Rollup File Analysis
|
|
3
3
|
-----------------------------
|
|
4
|
-
bundle size:
|
|
5
|
-
original size:
|
|
6
|
-
code reduction:
|
|
4
|
+
bundle size: 542 Bytes
|
|
5
|
+
original size: 675 Bytes
|
|
6
|
+
code reduction: 19.7 %
|
|
7
7
|
module count: 1
|
|
8
8
|
|
|
9
9
|
██████████████████████████████████████████████████
|
|
10
10
|
file: /src/macros.ts
|
|
11
11
|
bundle space: 100 %
|
|
12
|
-
rendered size:
|
|
13
|
-
original size:
|
|
14
|
-
code reduction:
|
|
12
|
+
rendered size: 542 Bytes
|
|
13
|
+
original size: 675 Bytes
|
|
14
|
+
code reduction: 19.7 %
|
|
15
15
|
dependents: 0
|
|
16
16
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.cts","sourceRoot":"","sources":["../../../src/index.cts"],"names":[],"mappings":"AAAA,cAAc
|
|
1
|
+
{"version":3,"file":"index.d.cts","sourceRoot":"","sources":["../../../src/index.cts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAC;AAC1B,cAAc,YAAY,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"macros.d.cts","sourceRoot":"","sources":["../../../src/macros.cts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"macros.d.cts","sourceRoot":"","sources":["../../../src/macros.cts"],"names":[],"mappings":"AAMA,eAAO,MAAM,EAAE,GAAI,CAAC,SAAS,MAAM,QAAQ,CAAC,KAAG,CAW9C,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAC;AAC1B,cAAc,YAAY,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"macros.d.ts","sourceRoot":"","sources":["../../../src/macros.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"macros.d.ts","sourceRoot":"","sources":["../../../src/macros.ts"],"names":[],"mappings":"AAMA,eAAO,MAAM,EAAE,GAAI,CAAC,SAAS,MAAM,QAAQ,CAAC,KAAG,CAW9C,CAAC"}
|