Skip to content

Commit f0c7f6e

Browse files
authored
fix(cli): handling numbers in unlocalizable loader (#507)
1 parent 6cf9f0d commit f0c7f6e

File tree

3 files changed

+19
-6
lines changed

3 files changed

+19
-6
lines changed

.changeset/long-cameras-cough.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"lingo.dev": patch
3+
---
4+
5+
fix handling numbers in unlocalizable loader

packages/cli/src/cli/loaders/unlocalizable.spec.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,12 @@ describe("unlocalizable loader", () => {
55
const data = {
66
foo: "bar",
77
num: 1,
8+
numStr: "1.0",
89
empty: "",
910
bool: true,
11+
boolStr: "false",
1012
isoDate: "2025-02-21",
13+
isoDateTime: "2025-02-21T00:00:00.000Z",
1114
bar: "foo",
1215
url: "https://example.com",
1316
systemId: "Ab1cdefghijklmnopqrst2",
@@ -19,7 +22,12 @@ describe("unlocalizable loader", () => {
1922
loader.setDefaultLocale("en");
2023
const result = await loader.pull("en", data);
2124

22-
expect(result).toEqual({ foo: "bar", bar: "foo" });
25+
expect(result).toEqual({
26+
foo: "bar",
27+
numStr: "1.0",
28+
boolStr: "false",
29+
bar: "foo",
30+
});
2331
});
2432

2533
it("should handle unlocalizable keys on push", async () => {

packages/cli/src/cli/loaders/unlocalizable.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@ export default function createUnlocalizableLoader(
1010
): ILoader<Record<string, any>, Record<string, any>> {
1111
const rules = {
1212
isEmpty: (v: any) => _.isEmpty(v),
13-
isNumber: (v: string) => !_.isNaN(_.toNumber(v)),
14-
isBoolean: (v: string) => _.isBoolean(v),
15-
isIsoDate: (v: string) => _.isString(v) && _isIsoDate(v),
16-
isSystemId: (v: string) => _.isString(v) && _isSystemId(v),
17-
isUrl: (v: string) => _.isString(v) && _isUrl(v),
13+
isNumber: (v: any) => typeof v === "number" || /^[0-9]+$/.test(v),
14+
isBoolean: (v: any) => _.isBoolean(v),
15+
isIsoDate: (v: any) => _.isString(v) && _isIsoDate(v),
16+
isSystemId: (v: any) => _.isString(v) && _isSystemId(v),
17+
isUrl: (v: any) => _.isString(v) && _isUrl(v),
1818
};
1919
return createLoader({
2020
async pull(locale, input) {

0 commit comments

Comments
 (0)