Comparing version 3.0.0-0 to 3.0.0-2
@@ -8,2 +8,8 @@ # Changelog | ||
## [3.0.0-0] 2020-05-20 | ||
### Changed | ||
- Switched to TypeScript | ||
## [2.0.0] - 2020-04-19 | ||
@@ -16,2 +22,3 @@ | ||
[2.0.0]: https://github.com/YouTwitFace/new-i18n/tree/v2.0.0 | ||
[2.0.0]: https://github.com/AndrewLaneX/new-i18n/tree/v2.0.0 | ||
[3.0.0-0]: https://github.com/AndrewLaneX/new-i18n/tree/v3.0.0-0 |
@@ -9,2 +9,5 @@ "use strict"; | ||
} | ||
else if (fallback && !languages.includes(fallback)) { | ||
throw new Error(`The fallback language wasn't listed as a language.`); | ||
} | ||
this.fallback = fallback; | ||
@@ -38,6 +41,6 @@ this._languages = new Map(languages.map(language => [language, require(`${folder}/${language}.json`)])); | ||
} | ||
return value.replace(/\{{2}(.+?)\}{2}/g, (_, variable) => variables[variable] || variable); | ||
return value.replace(/\{{2}(.+?)\}{2}/g, (_, variable) => (variables[variable] || variable).toString()); | ||
} | ||
_update(oldValues, newValues) { | ||
const result = Object.assign({}, oldValues); | ||
const result = { ...oldValues }; | ||
for (const key in newValues) { | ||
@@ -44,0 +47,0 @@ if (typeof newValues[key] === `object`) { |
export interface Language { | ||
[key: string]: string | Language; | ||
} | ||
export declare type Variable = string | number; | ||
export interface Variables { | ||
[key: string]: any; | ||
[key: string]: Variable; | ||
} | ||
export declare type Translation = string | null; |
{ | ||
"name": "new-i18n", | ||
"version": "3.0.0-0", | ||
"version": "3.0.0-2", | ||
"description": "new-i18n is a simple and easy to use internationalization library.", | ||
@@ -8,4 +8,5 @@ "main": "lib/index.js", | ||
"scripts": { | ||
"test": "mocha -r ts-node/register test/**/*.ts", | ||
"lint": "eslint src/", | ||
"test": "npm run prepare && mocha -r ts-node/register test/**/*.ts", | ||
"coverage": "nyc npm run test", | ||
"lint": "eslint .", | ||
"prepare": "rm -rf lib/ && tsc", | ||
@@ -20,2 +21,3 @@ "preversion": "npm run test" | ||
"devDependencies": { | ||
"@istanbuljs/nyc-config-typescript": "^1.0.1", | ||
"@types/mocha": "^7.0.2", | ||
@@ -27,2 +29,3 @@ "@types/node": "^14.0.1", | ||
"mocha": "^7.1.2", | ||
"nyc": "^15.1.0", | ||
"ts-node": "^8.10.1", | ||
@@ -29,0 +32,0 @@ "typescript": "^3.9.2" |
{ | ||
"include": ["./src/**/*"], | ||
"include": ["src/"], | ||
"compilerOptions": { | ||
"target": "es6", | ||
"target": "ES2019", | ||
"module": "commonjs", | ||
"declaration": true, | ||
"outDir": "./lib/", | ||
"outDir": "lib/", | ||
"strict": true, | ||
@@ -9,0 +9,0 @@ "noUnusedLocals": true, |
8230
11
117
10