@aurium/i18n
Advanced tools
Comparing version 0.1.0 to 0.1.2
@@ -33,3 +33,3 @@ How to Contribute | ||
All submissions, including submissions by project members, require review. We use GitHub pull requests for this purpose. | ||
All submissions, including submissions by project members, require review. We use GitLab merge requests for this purpose. | ||
Your comments are welcome in merge requests as well as in issues. | ||
@@ -46,2 +46,3 @@ | ||
``` | ||
This command will test in node and headless browsers. | ||
@@ -62,3 +63,22 @@ However you may be in a context where you can't run on your SO. Then you can use a Docker based solution: | ||
### Watch | ||
To watch for file changes and auto-run the tests: | ||
```bash | ||
$ npm run test:watch | ||
``` | ||
### Separated Environments | ||
For node env, run the `test:node` script: | ||
```bash | ||
$ npm run test:node | ||
``` | ||
For headless browser env, run the `test:browser` script: | ||
```bash | ||
$ npm run test:browser | ||
``` | ||
If you want to see the tests running in a browser, you can just open `./test/test.html` in a tab. | ||
@@ -19,2 +19,3 @@ export type L10nObj = L10nString | L10nArray; | ||
build: (...args: [{[k: string]: string}] | string[]) => L10nString; | ||
get str: string; | ||
} | ||
@@ -26,2 +27,3 @@ | ||
build: (...args: [{[k: string]: string}] | string[]) => L10nArray; | ||
get str: string; | ||
} |
30
i18n.js
@@ -13,3 +13,3 @@ "use strict"; | ||
for (let i=0; i<args.length; i++) | ||
str = str.replace(new RegExp(`\\{${i+1}\\}`,'g'), args[i]) | ||
str = str.replace(new RegExp(`\\{${i}\\}`,'g'), args[i]) | ||
} | ||
@@ -19,8 +19,16 @@ return mkL10nString(str) | ||
function arrIncludesAll(arr, strs) { | ||
return !strs.map((str)=> arr.includes(str) ).includes(false) | ||
} | ||
class L10nArray extends Array { | ||
toString() { | ||
return '' + this[0] | ||
return '' + this[0].split('\0')[0] | ||
} | ||
get str() { | ||
this.toString() | ||
} | ||
plural(num) { | ||
@@ -35,5 +43,5 @@ let str = num===1 ? this[0] : this[1] | ||
category(c) { | ||
category(...categories) { | ||
let arr = this.filter((str)=> | ||
str.split('\0').slice(1).includes(c) | ||
arrIncludesAll(str.split('\0').slice(1), categories) | ||
) | ||
@@ -44,3 +52,3 @@ return arr.length == 0 | ||
? mkL10nString(arr[0]) | ||
: arr.map(mkL10nString) | ||
: mkL10nArray(arr) | ||
} | ||
@@ -52,6 +60,10 @@ | ||
get raw() { | ||
return toStr(this) | ||
toString() { | ||
return toStr(this).split('\0')[0] | ||
} | ||
get str() { | ||
this.toString() | ||
} | ||
plural(num) { | ||
@@ -129,2 +141,4 @@ let str = '' + this | ||
i18nBuilder.__mkLangList = mkLangList | ||
module.exports = i18nBuilder | ||
if (typeof module != 'undefined' && module.exports) module.exports = i18nBuilder | ||
else if (typeof window != 'undefined') window.i18nBuilder = i18nBuilder | ||
else throw Error("Can't export i18nBuilder.") |
{ | ||
"name": "@aurium/i18n", | ||
"version": "0.1.0", | ||
"version": "0.1.2", | ||
"description": "Internationalization made simple", | ||
@@ -10,3 +10,6 @@ "main": "i18n.js", | ||
"scripts": { | ||
"test": "node test/test.js", | ||
"test": "npm -s run test:node && npm -s run test:browser", | ||
"test:watch": "while inotifywait -r -e create -e modify -e move -e delete --exclude dist .; do npm -s test; done", | ||
"test:node": "mocha -r ./test/chai.js -r ./register.js --growl test/i18n.spec.js", | ||
"test:browser": "node test/browser-test.js", | ||
"test:docker:build": "docker image build --network=host -f test/Dockerfile -t i18n-test:$npm_package_version .", | ||
@@ -31,4 +34,4 @@ "test:docker:run": "docker run --rm --volume $(pwd):/opt/src --network=host --name i18n-test i18n-test:$npm_package_version sh -c 'cp /opt/src/package.json . && echo Update source... && cp -vr $(ls -1 /opt/src | grep -v node_modules | sed 's#^#/opt/src/#') ./ && echo Run tests... && npm -s test'" | ||
"devDependencies": { | ||
"puppeteer": "^2.0.0", | ||
"puppeteer-firefox": "^0.5.0" | ||
"mocha": "^7.1.1", | ||
"puppeteer": "^3.0.0" | ||
}, | ||
@@ -35,0 +38,0 @@ "dependencies": { |
@@ -91,3 +91,3 @@ Internationalization made Simple | ||
⚠ The localization file format may not fit to your code pattern. If you wont format this files, you can tell eslint to ignore they. `.eslintrc.js`: | ||
⚠ The localization file format may not fit to your code pattern. If you wont to format this files, you can tell eslint to ignore they. `.eslintrc.js`: | ||
```js | ||
@@ -99,2 +99,3 @@ module.exports = { | ||
... | ||
} | ||
``` | ||
@@ -108,3 +109,3 @@ | ||
`extract-i18n-keys` can write js file modules with ocurrences information, or clean json files. You can also change your proxy var name from `i18n` to any other and use the `-p|--i18n-proxy-name` parameter to inform that. | ||
`extract-i18n-keys` can write js file modules with occurrences information, or clean json files. You can also change your proxy var name from `i18n` to any other and use the `-p|--i18n-proxy-name` parameter to inform that. | ||
@@ -111,0 +112,0 @@ For more details, read `extract-i18n-keys --help`. |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
375600
13
10303
116
2
1