@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/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@next-box/i18n",
|
|
3
3
|
"description": "A type-safe content resolver with content path auto-complete and value preview.",
|
|
4
|
-
"version": "0.0.
|
|
4
|
+
"version": "0.0.6",
|
|
5
5
|
"author": "miami-man",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"homepage": "https://github.com/badbatch/next-box",
|
package/src/index.ts
CHANGED
package/src/macros.test.ts
CHANGED
|
@@ -3,7 +3,7 @@ import { md } from '#macros.ts';
|
|
|
3
3
|
describe('md', () => {
|
|
4
4
|
describe('when a valid path is provided', () => {
|
|
5
5
|
it('should return the markdown content in the file the path resolves to', () => {
|
|
6
|
-
const content = md('./
|
|
6
|
+
const content = md('./__testUtils__/content.md');
|
|
7
7
|
|
|
8
8
|
expect(content).toMatchInlineSnapshot(`
|
|
9
9
|
"# Page title
|
|
@@ -23,13 +23,13 @@ describe('md', () => {
|
|
|
23
23
|
|
|
24
24
|
describe('when no path is not provided', () => {
|
|
25
25
|
it('should throw the expected error', () => {
|
|
26
|
-
expect(() => md('')).toThrow('
|
|
26
|
+
expect(() => md('')).toThrow('md expected a path, but received none');
|
|
27
27
|
});
|
|
28
28
|
});
|
|
29
29
|
|
|
30
30
|
describe('when a valid path is not provided', () => {
|
|
31
31
|
it('should throw the expected error', () => {
|
|
32
|
-
expect(() => md('./
|
|
32
|
+
expect(() => md('./__testUtils__/no-content.md')).toThrow();
|
|
33
33
|
});
|
|
34
34
|
});
|
|
35
35
|
});
|
package/src/macros.ts
CHANGED
|
@@ -1,12 +1,15 @@
|
|
|
1
1
|
import { readFileSync } from 'node:fs';
|
|
2
|
-
import { resolve } from 'node:path';
|
|
2
|
+
import { dirname, resolve } from 'node:path';
|
|
3
|
+
import { fileURLToPath } from 'node:url';
|
|
4
|
+
|
|
5
|
+
const dir = dirname(fileURLToPath(import.meta.url));
|
|
3
6
|
|
|
4
7
|
export const md = <P extends string>(path: P): P => {
|
|
5
8
|
if (!path) {
|
|
6
|
-
throw new Error('
|
|
9
|
+
throw new Error('md expected a path, but received none');
|
|
7
10
|
}
|
|
8
11
|
|
|
9
|
-
const fullPath = resolve(
|
|
12
|
+
const fullPath = resolve(dir, path);
|
|
10
13
|
// @ts-expect-error `md` function runs and build time and its return value
|
|
11
14
|
// replaces the `md` invocation. We are forcing the return type to be the
|
|
12
15
|
// input type to aid type inference when using `createI18n` and its
|