@nexim/localizer 1.1.2 → 1.1.3
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/CHANGELOG.md +4 -0
- package/dist/main.cjs +18 -17
- package/dist/main.cjs.map +1 -1
- package/dist/main.mjs +18 -17
- package/dist/main.mjs.map +1 -1
- package/package.json +8 -8
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,10 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
## [1.1.3](https://github.com/the-nexim/nanolib/compare/@nexim/localizer@1.1.2...@nexim/localizer@1.1.3) (2025-08-30)
|
|
7
|
+
|
|
8
|
+
**Note:** Version bump only for package @nexim/localizer
|
|
9
|
+
|
|
6
10
|
## [1.1.2](https://github.com/the-nexim/nanolib/compare/@nexim/localizer@1.1.1...@nexim/localizer@1.1.2) (2025-08-19)
|
|
7
11
|
|
|
8
12
|
**Note:** Version bump only for package @nexim/localizer
|
package/dist/main.cjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/* @nexim/localizer v1.1.
|
|
1
|
+
/* @nexim/localizer v1.1.3 */
|
|
2
2
|
"use strict";
|
|
3
3
|
var __defProp = Object.defineProperty;
|
|
4
4
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
@@ -27,8 +27,8 @@ module.exports = __toCommonJS(main_exports);
|
|
|
27
27
|
var import_logger = require("@alwatr/logger");
|
|
28
28
|
var import_package_tracer = require("@alwatr/package-tracer");
|
|
29
29
|
var import_unicode_digits = require("@alwatr/unicode-digits");
|
|
30
|
-
__dev_mode__: import_package_tracer.packageTracer.add("@nexim/localizer", "1.1.
|
|
31
|
-
var
|
|
30
|
+
__dev_mode__: import_package_tracer.packageTracer.add("@nexim/localizer", "1.1.3");
|
|
31
|
+
var Localizer = class _Localizer {
|
|
32
32
|
/**
|
|
33
33
|
* Creates a new instance of the Localizer class.
|
|
34
34
|
*
|
|
@@ -40,6 +40,21 @@ var _Localizer = class _Localizer {
|
|
|
40
40
|
this.numberFormatter_ = new Intl.NumberFormat(this.options__.locale.code);
|
|
41
41
|
this.unicodeDigits_ = new import_unicode_digits.UnicodeDigits(this.options__.locale.language);
|
|
42
42
|
}
|
|
43
|
+
static {
|
|
44
|
+
/**
|
|
45
|
+
* Time units used for relative time calculations.
|
|
46
|
+
* @internal
|
|
47
|
+
*/
|
|
48
|
+
this.timeUnits_ = [
|
|
49
|
+
{ label: "year", seconds: 31536e3 },
|
|
50
|
+
{ label: "month", seconds: 2592e3 },
|
|
51
|
+
{ label: "week", seconds: 604800 },
|
|
52
|
+
{ label: "day", seconds: 86400 },
|
|
53
|
+
{ label: "hour", seconds: 3600 },
|
|
54
|
+
{ label: "minute", seconds: 60 },
|
|
55
|
+
{ label: "second", seconds: 1 }
|
|
56
|
+
];
|
|
57
|
+
}
|
|
43
58
|
/**
|
|
44
59
|
* Retrieves a localized message by key from the resource dictionary.
|
|
45
60
|
*
|
|
@@ -150,18 +165,4 @@ var _Localizer = class _Localizer {
|
|
|
150
165
|
return rtf.format(0, "second");
|
|
151
166
|
}
|
|
152
167
|
};
|
|
153
|
-
/**
|
|
154
|
-
* Time units used for relative time calculations.
|
|
155
|
-
* @internal
|
|
156
|
-
*/
|
|
157
|
-
_Localizer.timeUnits_ = [
|
|
158
|
-
{ label: "year", seconds: 31536e3 },
|
|
159
|
-
{ label: "month", seconds: 2592e3 },
|
|
160
|
-
{ label: "week", seconds: 604800 },
|
|
161
|
-
{ label: "day", seconds: 86400 },
|
|
162
|
-
{ label: "hour", seconds: 3600 },
|
|
163
|
-
{ label: "minute", seconds: 60 },
|
|
164
|
-
{ label: "second", seconds: 1 }
|
|
165
|
-
];
|
|
166
|
-
var Localizer = _Localizer;
|
|
167
168
|
//# sourceMappingURL=main.cjs.map
|
package/dist/main.cjs.map
CHANGED
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/main.ts"],
|
|
4
4
|
"sourcesContent": ["import { createLogger } from '@alwatr/logger';\nimport { packageTracer } from '@alwatr/package-tracer';\nimport { UnicodeDigits, type UnicodeLangKeys } from '@alwatr/unicode-digits';\n\n__dev_mode__: packageTracer.add(__package_name__, __package_version__);\n\n/**\n * Represents a locale code in the format \"language-COUNTRY\".\n * The language part must be in lowercase, and the country part must be in uppercase.\n *\n * @example \"en-US\"\n * @example \"fr-FR\"\n * @example \"de-DE\"\n */\nexport type LocaleCode = `${Lowercase<string>}-${Uppercase<string>}`;\n\n/**\n * Represents a locale configuration with language code and language identifier.\n */\nexport interface Locale {\n /**\n * fa-IR, en-US, ...\n */\n code: LocaleCode;\n\n /**\n * The ISO 639-1 language code (e.g., 'fa', 'en')\n */\n language: UnicodeLangKeys;\n}\n\n/**\n * Provides localization and internationalization functionality.\n *\n * @remarks\n * This class handles number formatting, text translation, date formatting,\n * and relative time calculations based on the specified locale.\n */\nexport class Localizer {\n /**\n * Number formatter instance for formatting numbers according to the locale.\n *\n * @internal\n */\n protected numberFormatter_;\n\n /**\n * UnicodeDigits instance for converting numbers to locale-specific digits.\n *\n * @internal\n */\n protected unicodeDigits_;\n\n protected logger_ = createLogger(__package_name__);\n\n /**\n * Time units used for relative time calculations.\n * @internal\n */\n static timeUnits_ = [\n { label: 'year', seconds: 31536000 },\n { label: 'month', seconds: 2592000 },\n { label: 'week', seconds: 604800 },\n { label: 'day', seconds: 86400 },\n { label: 'hour', seconds: 3600 },\n { label: 'minute', seconds: 60 },\n { label: 'second', seconds: 1 },\n ] as const;\n\n /**\n * Creates a new instance of the Localizer class.\n *\n * @param options__ - Configuration options for localization\n */\n constructor(private options__: { locale: Locale; resource: DictionaryReq | null }) {\n this.numberFormatter_ = new Intl.NumberFormat(this.options__.locale.code);\n this.unicodeDigits_ = new UnicodeDigits(this.options__.locale.language);\n }\n\n /**\n * Retrieves a localized message by key from the resource dictionary.\n *\n * @param key - The key to lookup in the resource dictionary\n * @returns The localized message string\n *\n * @remarks\n * - Returns \"\\{key\\}\" if the key is not found in the dictionary\n * - Returns an empty string if the key is null or undefined\n *\n * @example\n * ```typescript\n * const localizer = new Localizer({...});\n * console.log(localizer.message('hello_world')); // \"Hello world!\"\n * console.log(localizer.message('missing_key')); // \"{missing_key}\"\n * ```\n */\n message(key: keyof NonNullable<typeof this.options__.resource>): string {\n // this.logger_.logMethodArgs?.('message', key);\n if (!key) return '';\n\n const msg = this.options__.resource?.[key];\n if (msg === undefined) {\n this.logger_.accident('message', 'l10n_key_not_found', 'Key not defined in the localization resource', {\n key,\n locale: this.options__.locale,\n });\n return `{${key}}`;\n }\n // else\n return msg;\n }\n\n /**\n * Formats a number according to the current locale settings.\n *\n * @param number - The number to format\n * @param decimal - Number of decimal places (default: 2)\n * @returns Formatted number string using locale-specific formatting\n *\n * @example\n * ```typescript\n * const localizer = new Localizer({...});\n * console.log(localizer.number(1234.567)); // \"1,234.57\"\n * console.log(localizer.number(1234.567, 1)); // \"1,234.6\"\n * ```\n */\n number(number?: number | null, decimal = 2): string {\n if (number == null) return '';\n decimal = Math.pow(10, decimal);\n number = Math.round(number * decimal) / decimal;\n return this.numberFormatter_.format(number);\n }\n\n /**\n * Replaces all numeric digits in a string with their locale-specific Unicode equivalents.\n *\n * @param str - The input string containing numbers to replace\n * @returns String with numbers converted to locale-specific digits\n *\n * @example\n * ```typescript\n * const localizer = new Localizer({locale: {code: 'fa-IR', language: 'fa'}, ...});\n * console.log(localizer.replaceNumber('123')); // '۱۲۳'\n * ```\n */\n replaceNumber(str: string): string {\n // this.logger_.logMethodArgs?.('replaceNumber', str);\n return this.unicodeDigits_.translate(str);\n }\n\n /**\n * Formats a date according to the current locale settings.\n *\n * @param date - Date to format (as Date object or timestamp)\n * @param options - Intl.DateTimeFormatOptions for customizing the output\n * @returns Localized date string\n *\n * @example\n * ```typescript\n * const localizer = new Localizer({...});\n * console.log(localizer.time(new Date())); // \"4/21/2025\"\n * ```\n */\n time(date: number | Date, options?: Intl.DateTimeFormatOptions): string {\n // this.logger_.logMethodArgs?.('time', { date, options });\n if (typeof date === 'number') date = new Date(date);\n return date.toLocaleDateString(this.options__.locale.code, options);\n }\n\n /**\n * Creates a relative time string comparing two dates.\n *\n * @param date - The date to compare (as Date object or timestamp)\n * @param from - Reference date for comparison (defaults to current time)\n * @param options - Formatting options for relative time\n * @returns Localized relative time string\n *\n * @example\n * ```typescript\n * const localizer = new Localizer({...});\n * const date = new Date(Date.now() - 3600000); // 1 hour ago\n * console.log(localizer.relativeTime(date)); // \"1 hour ago\"\n * ```\n */\n relativeTime(\n date: number | Date,\n from: number | Date = Date.now(),\n options: Intl.RelativeTimeFormatOptions = { numeric: 'auto', style: 'narrow' },\n ): string {\n // this.logger_.logMethodArgs?.('relativeTime', { date, from, options });\n\n const rtf = new Intl.RelativeTimeFormat(this.options__.locale.code, options);\n\n if (typeof date !== 'number') date = date.getTime();\n if (typeof from !== 'number') from = from.getTime();\n const diffSec = (from - date) / 1000;\n\n // Find the appropriate unit for the time difference\n for (const unit of Localizer.timeUnits_) {\n const interval = Math.floor(Math.abs(diffSec / unit.seconds));\n if (interval >= 1) {\n return rtf.format(diffSec > 0 ? interval : -interval, unit.label);\n }\n }\n\n return rtf.format(0, 'second');\n }\n}\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBAA6B;AAC7B,4BAA8B;AAC9B,4BAAoD;AAEpD,aAAc,qCAAc,IAAI,oBAAkB,OAAmB;AAkC9D,IAAM,
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBAA6B;AAC7B,4BAA8B;AAC9B,4BAAoD;AAEpD,aAAc,qCAAc,IAAI,oBAAkB,OAAmB;AAkC9D,IAAM,YAAN,MAAM,WAAU;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,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
// src/main.ts
|
|
4
4
|
import { createLogger } from "@alwatr/logger";
|
|
5
5
|
import { packageTracer } from "@alwatr/package-tracer";
|
|
6
6
|
import { UnicodeDigits } from "@alwatr/unicode-digits";
|
|
7
|
-
__dev_mode__: packageTracer.add("@nexim/localizer", "1.1.
|
|
8
|
-
var
|
|
7
|
+
__dev_mode__: packageTracer.add("@nexim/localizer", "1.1.3");
|
|
8
|
+
var Localizer = class _Localizer {
|
|
9
9
|
/**
|
|
10
10
|
* Creates a new instance of the Localizer class.
|
|
11
11
|
*
|
|
@@ -17,6 +17,21 @@ var _Localizer = class _Localizer {
|
|
|
17
17
|
this.numberFormatter_ = new Intl.NumberFormat(this.options__.locale.code);
|
|
18
18
|
this.unicodeDigits_ = new UnicodeDigits(this.options__.locale.language);
|
|
19
19
|
}
|
|
20
|
+
static {
|
|
21
|
+
/**
|
|
22
|
+
* Time units used for relative time calculations.
|
|
23
|
+
* @internal
|
|
24
|
+
*/
|
|
25
|
+
this.timeUnits_ = [
|
|
26
|
+
{ label: "year", seconds: 31536e3 },
|
|
27
|
+
{ label: "month", seconds: 2592e3 },
|
|
28
|
+
{ label: "week", seconds: 604800 },
|
|
29
|
+
{ label: "day", seconds: 86400 },
|
|
30
|
+
{ label: "hour", seconds: 3600 },
|
|
31
|
+
{ label: "minute", seconds: 60 },
|
|
32
|
+
{ label: "second", seconds: 1 }
|
|
33
|
+
];
|
|
34
|
+
}
|
|
20
35
|
/**
|
|
21
36
|
* Retrieves a localized message by key from the resource dictionary.
|
|
22
37
|
*
|
|
@@ -127,20 +142,6 @@ var _Localizer = class _Localizer {
|
|
|
127
142
|
return rtf.format(0, "second");
|
|
128
143
|
}
|
|
129
144
|
};
|
|
130
|
-
/**
|
|
131
|
-
* Time units used for relative time calculations.
|
|
132
|
-
* @internal
|
|
133
|
-
*/
|
|
134
|
-
_Localizer.timeUnits_ = [
|
|
135
|
-
{ label: "year", seconds: 31536e3 },
|
|
136
|
-
{ label: "month", seconds: 2592e3 },
|
|
137
|
-
{ label: "week", seconds: 604800 },
|
|
138
|
-
{ label: "day", seconds: 86400 },
|
|
139
|
-
{ label: "hour", seconds: 3600 },
|
|
140
|
-
{ label: "minute", seconds: 60 },
|
|
141
|
-
{ label: "second", seconds: 1 }
|
|
142
|
-
];
|
|
143
|
-
var Localizer = _Localizer;
|
|
144
145
|
export {
|
|
145
146
|
Localizer
|
|
146
147
|
};
|
package/dist/main.mjs.map
CHANGED
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/main.ts"],
|
|
4
4
|
"sourcesContent": ["import { createLogger } from '@alwatr/logger';\nimport { packageTracer } from '@alwatr/package-tracer';\nimport { UnicodeDigits, type UnicodeLangKeys } from '@alwatr/unicode-digits';\n\n__dev_mode__: packageTracer.add(__package_name__, __package_version__);\n\n/**\n * Represents a locale code in the format \"language-COUNTRY\".\n * The language part must be in lowercase, and the country part must be in uppercase.\n *\n * @example \"en-US\"\n * @example \"fr-FR\"\n * @example \"de-DE\"\n */\nexport type LocaleCode = `${Lowercase<string>}-${Uppercase<string>}`;\n\n/**\n * Represents a locale configuration with language code and language identifier.\n */\nexport interface Locale {\n /**\n * fa-IR, en-US, ...\n */\n code: LocaleCode;\n\n /**\n * The ISO 639-1 language code (e.g., 'fa', 'en')\n */\n language: UnicodeLangKeys;\n}\n\n/**\n * Provides localization and internationalization functionality.\n *\n * @remarks\n * This class handles number formatting, text translation, date formatting,\n * and relative time calculations based on the specified locale.\n */\nexport class Localizer {\n /**\n * Number formatter instance for formatting numbers according to the locale.\n *\n * @internal\n */\n protected numberFormatter_;\n\n /**\n * UnicodeDigits instance for converting numbers to locale-specific digits.\n *\n * @internal\n */\n protected unicodeDigits_;\n\n protected logger_ = createLogger(__package_name__);\n\n /**\n * Time units used for relative time calculations.\n * @internal\n */\n static timeUnits_ = [\n { label: 'year', seconds: 31536000 },\n { label: 'month', seconds: 2592000 },\n { label: 'week', seconds: 604800 },\n { label: 'day', seconds: 86400 },\n { label: 'hour', seconds: 3600 },\n { label: 'minute', seconds: 60 },\n { label: 'second', seconds: 1 },\n ] as const;\n\n /**\n * Creates a new instance of the Localizer class.\n *\n * @param options__ - Configuration options for localization\n */\n constructor(private options__: { locale: Locale; resource: DictionaryReq | null }) {\n this.numberFormatter_ = new Intl.NumberFormat(this.options__.locale.code);\n this.unicodeDigits_ = new UnicodeDigits(this.options__.locale.language);\n }\n\n /**\n * Retrieves a localized message by key from the resource dictionary.\n *\n * @param key - The key to lookup in the resource dictionary\n * @returns The localized message string\n *\n * @remarks\n * - Returns \"\\{key\\}\" if the key is not found in the dictionary\n * - Returns an empty string if the key is null or undefined\n *\n * @example\n * ```typescript\n * const localizer = new Localizer({...});\n * console.log(localizer.message('hello_world')); // \"Hello world!\"\n * console.log(localizer.message('missing_key')); // \"{missing_key}\"\n * ```\n */\n message(key: keyof NonNullable<typeof this.options__.resource>): string {\n // this.logger_.logMethodArgs?.('message', key);\n if (!key) return '';\n\n const msg = this.options__.resource?.[key];\n if (msg === undefined) {\n this.logger_.accident('message', 'l10n_key_not_found', 'Key not defined in the localization resource', {\n key,\n locale: this.options__.locale,\n });\n return `{${key}}`;\n }\n // else\n return msg;\n }\n\n /**\n * Formats a number according to the current locale settings.\n *\n * @param number - The number to format\n * @param decimal - Number of decimal places (default: 2)\n * @returns Formatted number string using locale-specific formatting\n *\n * @example\n * ```typescript\n * const localizer = new Localizer({...});\n * console.log(localizer.number(1234.567)); // \"1,234.57\"\n * console.log(localizer.number(1234.567, 1)); // \"1,234.6\"\n * ```\n */\n number(number?: number | null, decimal = 2): string {\n if (number == null) return '';\n decimal = Math.pow(10, decimal);\n number = Math.round(number * decimal) / decimal;\n return this.numberFormatter_.format(number);\n }\n\n /**\n * Replaces all numeric digits in a string with their locale-specific Unicode equivalents.\n *\n * @param str - The input string containing numbers to replace\n * @returns String with numbers converted to locale-specific digits\n *\n * @example\n * ```typescript\n * const localizer = new Localizer({locale: {code: 'fa-IR', language: 'fa'}, ...});\n * console.log(localizer.replaceNumber('123')); // '۱۲۳'\n * ```\n */\n replaceNumber(str: string): string {\n // this.logger_.logMethodArgs?.('replaceNumber', str);\n return this.unicodeDigits_.translate(str);\n }\n\n /**\n * Formats a date according to the current locale settings.\n *\n * @param date - Date to format (as Date object or timestamp)\n * @param options - Intl.DateTimeFormatOptions for customizing the output\n * @returns Localized date string\n *\n * @example\n * ```typescript\n * const localizer = new Localizer({...});\n * console.log(localizer.time(new Date())); // \"4/21/2025\"\n * ```\n */\n time(date: number | Date, options?: Intl.DateTimeFormatOptions): string {\n // this.logger_.logMethodArgs?.('time', { date, options });\n if (typeof date === 'number') date = new Date(date);\n return date.toLocaleDateString(this.options__.locale.code, options);\n }\n\n /**\n * Creates a relative time string comparing two dates.\n *\n * @param date - The date to compare (as Date object or timestamp)\n * @param from - Reference date for comparison (defaults to current time)\n * @param options - Formatting options for relative time\n * @returns Localized relative time string\n *\n * @example\n * ```typescript\n * const localizer = new Localizer({...});\n * const date = new Date(Date.now() - 3600000); // 1 hour ago\n * console.log(localizer.relativeTime(date)); // \"1 hour ago\"\n * ```\n */\n relativeTime(\n date: number | Date,\n from: number | Date = Date.now(),\n options: Intl.RelativeTimeFormatOptions = { numeric: 'auto', style: 'narrow' },\n ): string {\n // this.logger_.logMethodArgs?.('relativeTime', { date, from, options });\n\n const rtf = new Intl.RelativeTimeFormat(this.options__.locale.code, options);\n\n if (typeof date !== 'number') date = date.getTime();\n if (typeof from !== 'number') from = from.getTime();\n const diffSec = (from - date) / 1000;\n\n // Find the appropriate unit for the time difference\n for (const unit of Localizer.timeUnits_) {\n const interval = Math.floor(Math.abs(diffSec / unit.seconds));\n if (interval >= 1) {\n return rtf.format(diffSec > 0 ? interval : -interval, unit.label);\n }\n }\n\n return rtf.format(0, 'second');\n }\n}\n"],
|
|
5
|
-
"mappings": ";;;AAAA,SAAS,oBAAoB;AAC7B,SAAS,qBAAqB;AAC9B,SAAS,qBAA2C;AAEpD,aAAc,eAAc,IAAI,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AEA,WAAO,IAAI,OAAO,GAAG,QAAQ;AAAA,EAC/B;AACF;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nexim/localizer",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.3",
|
|
4
4
|
"description": "Lightweight i18n utilities to handle translations, number formatting, date/time localization using native browser APIs.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"localization",
|
|
@@ -48,16 +48,16 @@
|
|
|
48
48
|
"watch": "wireit"
|
|
49
49
|
},
|
|
50
50
|
"dependencies": {
|
|
51
|
-
"@alwatr/logger": "^5.5.
|
|
52
|
-
"@alwatr/package-tracer": "^5.5.
|
|
53
|
-
"@alwatr/unicode-digits": "^5.5.
|
|
51
|
+
"@alwatr/logger": "^5.5.6",
|
|
52
|
+
"@alwatr/package-tracer": "^5.5.6",
|
|
53
|
+
"@alwatr/unicode-digits": "^5.5.6"
|
|
54
54
|
},
|
|
55
55
|
"devDependencies": {
|
|
56
|
-
"@alwatr/nano-build": "^
|
|
57
|
-
"@alwatr/type-helper": "^5.4.
|
|
56
|
+
"@alwatr/nano-build": "^6.0.1",
|
|
57
|
+
"@alwatr/type-helper": "^5.4.4",
|
|
58
58
|
"@nexim/typescript-config": "^2.0.1",
|
|
59
59
|
"ava": "^6.4.1",
|
|
60
|
-
"typedoc": "^0.28.
|
|
60
|
+
"typedoc": "^0.28.11",
|
|
61
61
|
"typedoc-plugin-markdown": "^4.8.1",
|
|
62
62
|
"typedoc-plugin-no-inherit": "^1.6.1",
|
|
63
63
|
"typescript": "^5.9.2",
|
|
@@ -113,5 +113,5 @@
|
|
|
113
113
|
"command": "typedoc"
|
|
114
114
|
}
|
|
115
115
|
},
|
|
116
|
-
"gitHead": "
|
|
116
|
+
"gitHead": "e9784c58e523a33fc5dc6959559ba60cbdd55ab1"
|
|
117
117
|
}
|