@marktrue/dsh-mobile-remote 3.2.2-alpha.1-app → 3.2.2-alpha.1
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 +1223 -0
- package/CONTRIBUTING.md +59 -0
- package/FAQ.md +111 -0
- package/README.md +253 -6
- package/cordis.patch.yml +14 -0
- package/docs/00-/345/274/200/345/217/221/346/200/273/347/272/262.md +125 -0
- package/docs/01-PRD.md +148 -0
- package/docs/02-architecture.md +249 -0
- package/docs/03-api.md +930 -0
- package/docs/04-security.md +100 -0
- package/docs/05-test-cases.md +366 -0
- package/docs/06-install-run.md +372 -0
- package/docs/07-user-manual.md +66 -0
- package/docs/08-/346/211/251/345/261/225/345/274/200/345/217/221/346/214/207/345/215/227.md +86 -0
- package/docs/09-compatibility.md +223 -0
- package/docs/10-release.md +929 -0
- package/docs/screenshots/01-home.png +0 -0
- package/docs/screenshots/02-notifications.png +0 -0
- package/docs/screenshots/03-sessions.png +0 -0
- package/docs/screenshots/04-chat.png +0 -0
- package/docs/screenshots/05-settings.png +0 -0
- package/docs/screenshots/06-new-session.png +0 -0
- package/docs/screenshots/pgy-appstore.jpg +0 -0
- package/docs/screenshots/pgy-mobile-app.jpg +0 -0
- package/docs/screenshots/pgy-pc-client.jpg +0 -0
- package/docs/spec-app-auto-update.md +143 -0
- package/lib/account-usage.js +145 -0
- package/lib/app-alignment.js +112 -0
- package/lib/app-carrier-store.js +1972 -0
- package/lib/app-carrier.js +609 -0
- package/lib/client.js +1174 -0
- package/lib/desktop-form.js +738 -0
- package/lib/endpoint-registry.js +165 -0
- package/lib/git-read-bundled-provider.js +255 -0
- package/lib/git-read-service.js +322 -0
- package/lib/index.js +9467 -0
- package/lib/npm-update-source.js +226 -0
- package/lib/plugin-content-digest.js +80 -0
- package/lib/plugin-self-update.js +997 -0
- package/lib/plugin-update-controller.js +274 -0
- package/lib/plugin-update-log.js +164 -0
- package/lib/plugin-update-transaction.js +322 -0
- package/lib/plugin-update.js +309 -0
- package/lib/runtime-dependency-snapshot.js +345 -0
- package/lib/session-title-cache.js +123 -0
- package/lib/session-title-refresh.js +261 -0
- package/lib/tool-process.js +20 -0
- package/lib/update-fetch.js +24 -0
- package/lib/update-lock-arbiter.js +170 -0
- package/lib/update-supervisor.js +346 -0
- package/node_modules/ansi-regex/index.d.ts +37 -0
- package/node_modules/ansi-regex/index.js +10 -0
- package/node_modules/ansi-regex/license +9 -0
- package/node_modules/ansi-regex/package.json +55 -0
- package/node_modules/ansi-regex/readme.md +78 -0
- package/node_modules/ansi-styles/index.d.ts +345 -0
- package/node_modules/ansi-styles/index.js +163 -0
- package/node_modules/ansi-styles/license +9 -0
- package/node_modules/ansi-styles/package.json +56 -0
- package/node_modules/ansi-styles/readme.md +152 -0
- package/node_modules/camelcase/index.d.ts +63 -0
- package/node_modules/camelcase/index.js +76 -0
- package/node_modules/camelcase/license +9 -0
- package/node_modules/camelcase/package.json +43 -0
- package/node_modules/camelcase/readme.md +99 -0
- package/node_modules/cliui/CHANGELOG.md +76 -0
- package/node_modules/cliui/LICENSE.txt +14 -0
- package/node_modules/cliui/README.md +115 -0
- package/node_modules/cliui/index.js +354 -0
- package/node_modules/cliui/package.json +65 -0
- package/node_modules/color-convert/CHANGELOG.md +54 -0
- package/node_modules/color-convert/LICENSE +21 -0
- package/node_modules/color-convert/README.md +68 -0
- package/node_modules/color-convert/conversions.js +839 -0
- package/node_modules/color-convert/index.js +81 -0
- package/node_modules/color-convert/package.json +48 -0
- package/node_modules/color-convert/route.js +97 -0
- package/node_modules/color-name/LICENSE +8 -0
- package/node_modules/color-name/README.md +11 -0
- package/node_modules/color-name/index.js +152 -0
- package/node_modules/color-name/package.json +28 -0
- package/node_modules/decamelize/index.js +13 -0
- package/node_modules/decamelize/license +21 -0
- package/node_modules/decamelize/package.json +38 -0
- package/node_modules/decamelize/readme.md +48 -0
- package/node_modules/dijkstrajs/.travis.yml +4 -0
- package/node_modules/dijkstrajs/CONTRIBUTING.md +8 -0
- package/node_modules/dijkstrajs/LICENSE.md +19 -0
- package/node_modules/dijkstrajs/README.md +18 -0
- package/node_modules/dijkstrajs/dijkstra.js +165 -0
- package/node_modules/dijkstrajs/package.json +60 -0
- package/node_modules/dijkstrajs/test/dijkstra.test.js +96 -0
- package/node_modules/emoji-regex/LICENSE-MIT.txt +20 -0
- package/node_modules/emoji-regex/README.md +73 -0
- package/node_modules/emoji-regex/es2015/index.js +6 -0
- package/node_modules/emoji-regex/es2015/text.js +6 -0
- package/node_modules/emoji-regex/index.d.ts +23 -0
- package/node_modules/emoji-regex/index.js +6 -0
- package/node_modules/emoji-regex/package.json +50 -0
- package/node_modules/emoji-regex/text.js +6 -0
- package/node_modules/find-up/index.d.ts +137 -0
- package/node_modules/find-up/index.js +89 -0
- package/node_modules/find-up/license +9 -0
- package/node_modules/find-up/package.json +53 -0
- package/node_modules/find-up/readme.md +156 -0
- package/node_modules/get-caller-file/LICENSE.md +6 -0
- package/node_modules/get-caller-file/README.md +41 -0
- package/node_modules/get-caller-file/index.d.ts +2 -0
- package/node_modules/get-caller-file/index.js +22 -0
- package/node_modules/get-caller-file/index.js.map +1 -0
- package/node_modules/get-caller-file/package.json +42 -0
- package/node_modules/is-fullwidth-code-point/index.d.ts +17 -0
- package/node_modules/is-fullwidth-code-point/index.js +50 -0
- package/node_modules/is-fullwidth-code-point/license +9 -0
- package/node_modules/is-fullwidth-code-point/package.json +42 -0
- package/node_modules/is-fullwidth-code-point/readme.md +39 -0
- package/node_modules/locate-path/index.d.ts +83 -0
- package/node_modules/locate-path/index.js +65 -0
- package/node_modules/locate-path/license +9 -0
- package/node_modules/locate-path/package.json +45 -0
- package/node_modules/locate-path/readme.md +122 -0
- package/node_modules/p-limit/index.d.ts +38 -0
- package/node_modules/p-limit/index.js +57 -0
- package/node_modules/p-limit/license +9 -0
- package/node_modules/p-limit/package.json +52 -0
- package/node_modules/p-limit/readme.md +101 -0
- package/node_modules/p-locate/index.d.ts +64 -0
- package/node_modules/p-locate/index.js +52 -0
- package/node_modules/p-locate/license +9 -0
- package/node_modules/p-locate/package.json +53 -0
- package/node_modules/p-locate/readme.md +90 -0
- package/node_modules/p-try/index.d.ts +39 -0
- package/node_modules/p-try/index.js +9 -0
- package/node_modules/p-try/license +9 -0
- package/node_modules/p-try/package.json +42 -0
- package/node_modules/p-try/readme.md +58 -0
- package/node_modules/path-exists/index.d.ts +28 -0
- package/node_modules/path-exists/index.js +23 -0
- package/node_modules/path-exists/license +9 -0
- package/node_modules/path-exists/package.json +39 -0
- package/node_modules/path-exists/readme.md +52 -0
- package/node_modules/pngjs/.eslintignore +2 -0
- package/node_modules/pngjs/.eslintrc.json +19 -0
- package/node_modules/pngjs/.prettierignore +3 -0
- package/node_modules/pngjs/LICENSE +20 -0
- package/node_modules/pngjs/README.md +429 -0
- package/node_modules/pngjs/browser.js +16096 -0
- package/node_modules/pngjs/coverage/lcov-report/base.css +354 -0
- package/node_modules/pngjs/coverage/lcov-report/bitmapper.js.html +881 -0
- package/node_modules/pngjs/coverage/lcov-report/bitpacker.js.html +554 -0
- package/node_modules/pngjs/coverage/lcov-report/block-navigation.js +77 -0
- package/node_modules/pngjs/coverage/lcov-report/chunkstream.js.html +647 -0
- package/node_modules/pngjs/coverage/lcov-report/constants.js.html +176 -0
- package/node_modules/pngjs/coverage/lcov-report/crc.js.html +200 -0
- package/node_modules/pngjs/coverage/lcov-report/favicon.png +0 -0
- package/node_modules/pngjs/coverage/lcov-report/filter-pack.js.html +593 -0
- package/node_modules/pngjs/coverage/lcov-report/filter-parse-async.js.html +152 -0
- package/node_modules/pngjs/coverage/lcov-report/filter-parse-sync.js.html +143 -0
- package/node_modules/pngjs/coverage/lcov-report/filter-parse.js.html +611 -0
- package/node_modules/pngjs/coverage/lcov-report/format-normaliser.js.html +359 -0
- package/node_modules/pngjs/coverage/lcov-report/index.html +426 -0
- package/node_modules/pngjs/coverage/lcov-report/interlace.js.html +365 -0
- package/node_modules/pngjs/coverage/lcov-report/packer-async.js.html +230 -0
- package/node_modules/pngjs/coverage/lcov-report/packer-sync.js.html +248 -0
- package/node_modules/pngjs/coverage/lcov-report/packer.js.html +467 -0
- package/node_modules/pngjs/coverage/lcov-report/paeth-predictor.js.html +128 -0
- package/node_modules/pngjs/coverage/lcov-report/parser-async.js.html +575 -0
- package/node_modules/pngjs/coverage/lcov-report/parser-sync.js.html +404 -0
- package/node_modules/pngjs/coverage/lcov-report/parser.js.html +950 -0
- package/node_modules/pngjs/coverage/lcov-report/png-sync.js.html +116 -0
- package/node_modules/pngjs/coverage/lcov-report/png.js.html +662 -0
- package/node_modules/pngjs/coverage/lcov-report/prettify.css +101 -0
- package/node_modules/pngjs/coverage/lcov-report/prettify.js +1007 -0
- package/node_modules/pngjs/coverage/lcov-report/sort-arrow-sprite.png +0 -0
- package/node_modules/pngjs/coverage/lcov-report/sorter.js +169 -0
- package/node_modules/pngjs/coverage/lcov-report/sync-inflate.js.html +584 -0
- package/node_modules/pngjs/coverage/lcov-report/sync-reader.js.html +215 -0
- package/node_modules/pngjs/coverage/lcov.info +2177 -0
- package/node_modules/pngjs/lib/bitmapper.js +267 -0
- package/node_modules/pngjs/lib/bitpacker.js +158 -0
- package/node_modules/pngjs/lib/chunkstream.js +189 -0
- package/node_modules/pngjs/lib/constants.js +32 -0
- package/node_modules/pngjs/lib/crc.js +40 -0
- package/node_modules/pngjs/lib/filter-pack.js +171 -0
- package/node_modules/pngjs/lib/filter-parse-async.js +24 -0
- package/node_modules/pngjs/lib/filter-parse-sync.js +21 -0
- package/node_modules/pngjs/lib/filter-parse.js +177 -0
- package/node_modules/pngjs/lib/format-normaliser.js +93 -0
- package/node_modules/pngjs/lib/interlace.js +95 -0
- package/node_modules/pngjs/lib/packer-async.js +50 -0
- package/node_modules/pngjs/lib/packer-sync.js +56 -0
- package/node_modules/pngjs/lib/packer.js +129 -0
- package/node_modules/pngjs/lib/paeth-predictor.js +16 -0
- package/node_modules/pngjs/lib/parser-async.js +165 -0
- package/node_modules/pngjs/lib/parser-sync.js +108 -0
- package/node_modules/pngjs/lib/parser.js +290 -0
- package/node_modules/pngjs/lib/png-sync.js +12 -0
- package/node_modules/pngjs/lib/png.js +194 -0
- package/node_modules/pngjs/lib/sync-inflate.js +168 -0
- package/node_modules/pngjs/lib/sync-reader.js +45 -0
- package/node_modules/pngjs/package.json +73 -0
- package/node_modules/qrcode/README.md +770 -0
- package/node_modules/qrcode/bin/qrcode +159 -0
- package/node_modules/qrcode/helper/to-sjis-browser.js +2 -0
- package/node_modules/qrcode/helper/to-sjis.js +105 -0
- package/node_modules/qrcode/lib/browser.js +76 -0
- package/node_modules/qrcode/lib/can-promise.js +7 -0
- package/node_modules/qrcode/lib/core/alignment-pattern.js +83 -0
- package/node_modules/qrcode/lib/core/alphanumeric-data.js +59 -0
- package/node_modules/qrcode/lib/core/bit-buffer.js +37 -0
- package/node_modules/qrcode/lib/core/bit-matrix.js +65 -0
- package/node_modules/qrcode/lib/core/byte-data.js +30 -0
- package/node_modules/qrcode/lib/core/error-correction-code.js +135 -0
- package/node_modules/qrcode/lib/core/error-correction-level.js +50 -0
- package/node_modules/qrcode/lib/core/finder-pattern.js +22 -0
- package/node_modules/qrcode/lib/core/format-info.js +29 -0
- package/node_modules/qrcode/lib/core/galois-field.js +69 -0
- package/node_modules/qrcode/lib/core/kanji-data.js +54 -0
- package/node_modules/qrcode/lib/core/mask-pattern.js +234 -0
- package/node_modules/qrcode/lib/core/mode.js +167 -0
- package/node_modules/qrcode/lib/core/numeric-data.js +43 -0
- package/node_modules/qrcode/lib/core/polynomial.js +62 -0
- package/node_modules/qrcode/lib/core/qrcode.js +495 -0
- package/node_modules/qrcode/lib/core/reed-solomon-encoder.js +56 -0
- package/node_modules/qrcode/lib/core/regex.js +31 -0
- package/node_modules/qrcode/lib/core/segments.js +330 -0
- package/node_modules/qrcode/lib/core/utils.js +63 -0
- package/node_modules/qrcode/lib/core/version-check.js +9 -0
- package/node_modules/qrcode/lib/core/version.js +163 -0
- package/node_modules/qrcode/lib/index.js +12 -0
- package/node_modules/qrcode/lib/renderer/canvas.js +63 -0
- package/node_modules/qrcode/lib/renderer/png.js +78 -0
- package/node_modules/qrcode/lib/renderer/svg-tag.js +81 -0
- package/node_modules/qrcode/lib/renderer/svg.js +19 -0
- package/node_modules/qrcode/lib/renderer/terminal/terminal-small.js +85 -0
- package/node_modules/qrcode/lib/renderer/terminal/terminal.js +49 -0
- package/node_modules/qrcode/lib/renderer/terminal.js +9 -0
- package/node_modules/qrcode/lib/renderer/utf8.js +71 -0
- package/node_modules/qrcode/lib/renderer/utils.js +99 -0
- package/node_modules/qrcode/lib/server.js +138 -0
- package/node_modules/qrcode/license +10 -0
- package/node_modules/qrcode/package.json +77 -0
- package/node_modules/require-directory/.jshintrc +67 -0
- package/node_modules/require-directory/.npmignore +1 -0
- package/node_modules/require-directory/.travis.yml +3 -0
- package/node_modules/require-directory/LICENSE +22 -0
- package/node_modules/require-directory/README.markdown +184 -0
- package/node_modules/require-directory/index.js +86 -0
- package/node_modules/require-directory/package.json +40 -0
- package/node_modules/require-main-filename/CHANGELOG.md +26 -0
- package/node_modules/require-main-filename/LICENSE.txt +14 -0
- package/node_modules/require-main-filename/README.md +26 -0
- package/node_modules/require-main-filename/index.js +18 -0
- package/node_modules/require-main-filename/package.json +35 -0
- package/node_modules/set-blocking/CHANGELOG.md +26 -0
- package/node_modules/set-blocking/LICENSE.txt +14 -0
- package/node_modules/set-blocking/README.md +31 -0
- package/node_modules/set-blocking/index.js +7 -0
- package/node_modules/set-blocking/package.json +42 -0
- package/node_modules/string-width/index.d.ts +29 -0
- package/node_modules/string-width/index.js +47 -0
- package/node_modules/string-width/license +9 -0
- package/node_modules/string-width/package.json +56 -0
- package/node_modules/string-width/readme.md +50 -0
- package/node_modules/strip-ansi/index.d.ts +17 -0
- package/node_modules/strip-ansi/index.js +4 -0
- package/node_modules/strip-ansi/license +9 -0
- package/node_modules/strip-ansi/package.json +54 -0
- package/node_modules/strip-ansi/readme.md +46 -0
- package/node_modules/which-module/LICENSE +13 -0
- package/node_modules/which-module/README.md +58 -0
- package/node_modules/which-module/index.js +9 -0
- package/node_modules/which-module/package.json +41 -0
- package/node_modules/wrap-ansi/index.js +186 -0
- package/node_modules/wrap-ansi/license +9 -0
- package/node_modules/wrap-ansi/package.json +61 -0
- package/node_modules/wrap-ansi/readme.md +97 -0
- package/node_modules/y18n/CHANGELOG.md +35 -0
- package/node_modules/y18n/LICENSE +13 -0
- package/node_modules/y18n/README.md +109 -0
- package/node_modules/y18n/index.js +188 -0
- package/node_modules/y18n/package.json +39 -0
- package/node_modules/yargs/CHANGELOG.md +420 -0
- package/node_modules/yargs/LICENSE +21 -0
- package/node_modules/yargs/README.md +140 -0
- package/node_modules/yargs/build/lib/apply-extends.d.ts +2 -0
- package/node_modules/yargs/build/lib/apply-extends.js +65 -0
- package/node_modules/yargs/build/lib/argsert.d.ts +2 -0
- package/node_modules/yargs/build/lib/argsert.js +65 -0
- package/node_modules/yargs/build/lib/command.d.ts +64 -0
- package/node_modules/yargs/build/lib/command.js +416 -0
- package/node_modules/yargs/build/lib/common-types.d.ts +36 -0
- package/node_modules/yargs/build/lib/common-types.js +25 -0
- package/node_modules/yargs/build/lib/completion-templates.d.ts +2 -0
- package/node_modules/yargs/build/lib/completion-templates.js +50 -0
- package/node_modules/yargs/build/lib/completion.d.ts +21 -0
- package/node_modules/yargs/build/lib/completion.js +135 -0
- package/node_modules/yargs/build/lib/is-promise.d.ts +1 -0
- package/node_modules/yargs/build/lib/is-promise.js +9 -0
- package/node_modules/yargs/build/lib/levenshtein.d.ts +1 -0
- package/node_modules/yargs/build/lib/levenshtein.js +58 -0
- package/node_modules/yargs/build/lib/middleware.d.ts +10 -0
- package/node_modules/yargs/build/lib/middleware.js +57 -0
- package/node_modules/yargs/build/lib/obj-filter.d.ts +1 -0
- package/node_modules/yargs/build/lib/obj-filter.js +14 -0
- package/node_modules/yargs/build/lib/parse-command.d.ts +11 -0
- package/node_modules/yargs/build/lib/parse-command.js +36 -0
- package/node_modules/yargs/build/lib/process-argv.d.ts +2 -0
- package/node_modules/yargs/build/lib/process-argv.js +31 -0
- package/node_modules/yargs/build/lib/usage.d.ts +49 -0
- package/node_modules/yargs/build/lib/usage.js +540 -0
- package/node_modules/yargs/build/lib/validation.d.ts +34 -0
- package/node_modules/yargs/build/lib/validation.js +330 -0
- package/node_modules/yargs/build/lib/yargs.d.ts +274 -0
- package/node_modules/yargs/build/lib/yargs.js +1190 -0
- package/node_modules/yargs/build/lib/yerror.d.ts +4 -0
- package/node_modules/yargs/build/lib/yerror.js +11 -0
- package/node_modules/yargs/index.js +40 -0
- package/node_modules/yargs/locales/be.json +46 -0
- package/node_modules/yargs/locales/de.json +46 -0
- package/node_modules/yargs/locales/en.json +51 -0
- package/node_modules/yargs/locales/es.json +46 -0
- package/node_modules/yargs/locales/fi.json +49 -0
- package/node_modules/yargs/locales/fr.json +53 -0
- package/node_modules/yargs/locales/hi.json +49 -0
- package/node_modules/yargs/locales/hu.json +46 -0
- package/node_modules/yargs/locales/id.json +50 -0
- package/node_modules/yargs/locales/it.json +46 -0
- package/node_modules/yargs/locales/ja.json +51 -0
- package/node_modules/yargs/locales/ko.json +49 -0
- package/node_modules/yargs/locales/nb.json +44 -0
- package/node_modules/yargs/locales/nl.json +49 -0
- package/node_modules/yargs/locales/nn.json +44 -0
- package/node_modules/yargs/locales/pirate.json +13 -0
- package/node_modules/yargs/locales/pl.json +49 -0
- package/node_modules/yargs/locales/pt.json +45 -0
- package/node_modules/yargs/locales/pt_BR.json +48 -0
- package/node_modules/yargs/locales/ru.json +46 -0
- package/node_modules/yargs/locales/th.json +46 -0
- package/node_modules/yargs/locales/tr.json +48 -0
- package/node_modules/yargs/locales/zh_CN.json +48 -0
- package/node_modules/yargs/locales/zh_TW.json +47 -0
- package/node_modules/yargs/package.json +92 -0
- package/node_modules/yargs/yargs.js +14 -0
- package/node_modules/yargs-parser/CHANGELOG.md +601 -0
- package/node_modules/yargs-parser/LICENSE.txt +14 -0
- package/node_modules/yargs-parser/README.md +449 -0
- package/node_modules/yargs-parser/index.js +1032 -0
- package/node_modules/yargs-parser/lib/tokenize-arg-string.js +40 -0
- package/node_modules/yargs-parser/package.json +46 -0
- package/package.json +65 -12
- package/DSH-Remote-v3.2.2.apk +0 -4
- package/manifest.json +0 -21
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
const stringWidth = require('string-width');
|
|
3
|
+
const stripAnsi = require('strip-ansi');
|
|
4
|
+
const ansiStyles = require('ansi-styles');
|
|
5
|
+
|
|
6
|
+
const ESCAPES = new Set([
|
|
7
|
+
'\u001B',
|
|
8
|
+
'\u009B'
|
|
9
|
+
]);
|
|
10
|
+
|
|
11
|
+
const END_CODE = 39;
|
|
12
|
+
|
|
13
|
+
const wrapAnsi = code => `${ESCAPES.values().next().value}[${code}m`;
|
|
14
|
+
|
|
15
|
+
// Calculate the length of words split on ' ', ignoring
|
|
16
|
+
// the extra characters added by ansi escape codes
|
|
17
|
+
const wordLengths = string => string.split(' ').map(character => stringWidth(character));
|
|
18
|
+
|
|
19
|
+
// Wrap a long word across multiple rows
|
|
20
|
+
// Ansi escape codes do not count towards length
|
|
21
|
+
const wrapWord = (rows, word, columns) => {
|
|
22
|
+
const characters = [...word];
|
|
23
|
+
|
|
24
|
+
let isInsideEscape = false;
|
|
25
|
+
let visible = stringWidth(stripAnsi(rows[rows.length - 1]));
|
|
26
|
+
|
|
27
|
+
for (const [index, character] of characters.entries()) {
|
|
28
|
+
const characterLength = stringWidth(character);
|
|
29
|
+
|
|
30
|
+
if (visible + characterLength <= columns) {
|
|
31
|
+
rows[rows.length - 1] += character;
|
|
32
|
+
} else {
|
|
33
|
+
rows.push(character);
|
|
34
|
+
visible = 0;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
if (ESCAPES.has(character)) {
|
|
38
|
+
isInsideEscape = true;
|
|
39
|
+
} else if (isInsideEscape && character === 'm') {
|
|
40
|
+
isInsideEscape = false;
|
|
41
|
+
continue;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
if (isInsideEscape) {
|
|
45
|
+
continue;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
visible += characterLength;
|
|
49
|
+
|
|
50
|
+
if (visible === columns && index < characters.length - 1) {
|
|
51
|
+
rows.push('');
|
|
52
|
+
visible = 0;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// It's possible that the last row we copy over is only
|
|
57
|
+
// ansi escape characters, handle this edge-case
|
|
58
|
+
if (!visible && rows[rows.length - 1].length > 0 && rows.length > 1) {
|
|
59
|
+
rows[rows.length - 2] += rows.pop();
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
// Trims spaces from a string ignoring invisible sequences
|
|
64
|
+
const stringVisibleTrimSpacesRight = str => {
|
|
65
|
+
const words = str.split(' ');
|
|
66
|
+
let last = words.length;
|
|
67
|
+
|
|
68
|
+
while (last > 0) {
|
|
69
|
+
if (stringWidth(words[last - 1]) > 0) {
|
|
70
|
+
break;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
last--;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
if (last === words.length) {
|
|
77
|
+
return str;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
return words.slice(0, last).join(' ') + words.slice(last).join('');
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
// The wrap-ansi module can be invoked in either 'hard' or 'soft' wrap mode
|
|
84
|
+
//
|
|
85
|
+
// 'hard' will never allow a string to take up more than columns characters
|
|
86
|
+
//
|
|
87
|
+
// 'soft' allows long words to expand past the column length
|
|
88
|
+
const exec = (string, columns, options = {}) => {
|
|
89
|
+
if (options.trim !== false && string.trim() === '') {
|
|
90
|
+
return '';
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
let pre = '';
|
|
94
|
+
let ret = '';
|
|
95
|
+
let escapeCode;
|
|
96
|
+
|
|
97
|
+
const lengths = wordLengths(string);
|
|
98
|
+
let rows = [''];
|
|
99
|
+
|
|
100
|
+
for (const [index, word] of string.split(' ').entries()) {
|
|
101
|
+
if (options.trim !== false) {
|
|
102
|
+
rows[rows.length - 1] = rows[rows.length - 1].trimLeft();
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
let rowLength = stringWidth(rows[rows.length - 1]);
|
|
106
|
+
|
|
107
|
+
if (index !== 0) {
|
|
108
|
+
if (rowLength >= columns && (options.wordWrap === false || options.trim === false)) {
|
|
109
|
+
// If we start with a new word but the current row length equals the length of the columns, add a new row
|
|
110
|
+
rows.push('');
|
|
111
|
+
rowLength = 0;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
if (rowLength > 0 || options.trim === false) {
|
|
115
|
+
rows[rows.length - 1] += ' ';
|
|
116
|
+
rowLength++;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
// In 'hard' wrap mode, the length of a line is never allowed to extend past 'columns'
|
|
121
|
+
if (options.hard && lengths[index] > columns) {
|
|
122
|
+
const remainingColumns = (columns - rowLength);
|
|
123
|
+
const breaksStartingThisLine = 1 + Math.floor((lengths[index] - remainingColumns - 1) / columns);
|
|
124
|
+
const breaksStartingNextLine = Math.floor((lengths[index] - 1) / columns);
|
|
125
|
+
if (breaksStartingNextLine < breaksStartingThisLine) {
|
|
126
|
+
rows.push('');
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
wrapWord(rows, word, columns);
|
|
130
|
+
continue;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
if (rowLength + lengths[index] > columns && rowLength > 0 && lengths[index] > 0) {
|
|
134
|
+
if (options.wordWrap === false && rowLength < columns) {
|
|
135
|
+
wrapWord(rows, word, columns);
|
|
136
|
+
continue;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
rows.push('');
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
if (rowLength + lengths[index] > columns && options.wordWrap === false) {
|
|
143
|
+
wrapWord(rows, word, columns);
|
|
144
|
+
continue;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
rows[rows.length - 1] += word;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
if (options.trim !== false) {
|
|
151
|
+
rows = rows.map(stringVisibleTrimSpacesRight);
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
pre = rows.join('\n');
|
|
155
|
+
|
|
156
|
+
for (const [index, character] of [...pre].entries()) {
|
|
157
|
+
ret += character;
|
|
158
|
+
|
|
159
|
+
if (ESCAPES.has(character)) {
|
|
160
|
+
const code = parseFloat(/\d[^m]*/.exec(pre.slice(index, index + 4)));
|
|
161
|
+
escapeCode = code === END_CODE ? null : code;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
const code = ansiStyles.codes.get(Number(escapeCode));
|
|
165
|
+
|
|
166
|
+
if (escapeCode && code) {
|
|
167
|
+
if (pre[index + 1] === '\n') {
|
|
168
|
+
ret += wrapAnsi(code);
|
|
169
|
+
} else if (character === '\n') {
|
|
170
|
+
ret += wrapAnsi(escapeCode);
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
return ret;
|
|
176
|
+
};
|
|
177
|
+
|
|
178
|
+
// For each newline, invoke the method separately
|
|
179
|
+
module.exports = (string, columns, options) => {
|
|
180
|
+
return String(string)
|
|
181
|
+
.normalize()
|
|
182
|
+
.replace(/\r\n/g, '\n')
|
|
183
|
+
.split('\n')
|
|
184
|
+
.map(line => exec(line, columns, options))
|
|
185
|
+
.join('\n');
|
|
186
|
+
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (sindresorhus.com)
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
6
|
+
|
|
7
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
8
|
+
|
|
9
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "wrap-ansi",
|
|
3
|
+
"version": "6.2.0",
|
|
4
|
+
"description": "Wordwrap a string with ANSI escape codes",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"repository": "chalk/wrap-ansi",
|
|
7
|
+
"author": {
|
|
8
|
+
"name": "Sindre Sorhus",
|
|
9
|
+
"email": "sindresorhus@gmail.com",
|
|
10
|
+
"url": "sindresorhus.com"
|
|
11
|
+
},
|
|
12
|
+
"engines": {
|
|
13
|
+
"node": ">=8"
|
|
14
|
+
},
|
|
15
|
+
"scripts": {
|
|
16
|
+
"test": "xo && nyc ava"
|
|
17
|
+
},
|
|
18
|
+
"files": [
|
|
19
|
+
"index.js"
|
|
20
|
+
],
|
|
21
|
+
"keywords": [
|
|
22
|
+
"wrap",
|
|
23
|
+
"break",
|
|
24
|
+
"wordwrap",
|
|
25
|
+
"wordbreak",
|
|
26
|
+
"linewrap",
|
|
27
|
+
"ansi",
|
|
28
|
+
"styles",
|
|
29
|
+
"color",
|
|
30
|
+
"colour",
|
|
31
|
+
"colors",
|
|
32
|
+
"terminal",
|
|
33
|
+
"console",
|
|
34
|
+
"cli",
|
|
35
|
+
"string",
|
|
36
|
+
"tty",
|
|
37
|
+
"escape",
|
|
38
|
+
"formatting",
|
|
39
|
+
"rgb",
|
|
40
|
+
"256",
|
|
41
|
+
"shell",
|
|
42
|
+
"xterm",
|
|
43
|
+
"log",
|
|
44
|
+
"logging",
|
|
45
|
+
"command-line",
|
|
46
|
+
"text"
|
|
47
|
+
],
|
|
48
|
+
"dependencies": {
|
|
49
|
+
"ansi-styles": "^4.0.0",
|
|
50
|
+
"string-width": "^4.1.0",
|
|
51
|
+
"strip-ansi": "^6.0.0"
|
|
52
|
+
},
|
|
53
|
+
"devDependencies": {
|
|
54
|
+
"ava": "^2.1.0",
|
|
55
|
+
"chalk": "^2.4.2",
|
|
56
|
+
"coveralls": "^3.0.3",
|
|
57
|
+
"has-ansi": "^3.0.0",
|
|
58
|
+
"nyc": "^14.1.1",
|
|
59
|
+
"xo": "^0.24.0"
|
|
60
|
+
}
|
|
61
|
+
}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
# wrap-ansi [](https://travis-ci.org/chalk/wrap-ansi) [](https://coveralls.io/github/chalk/wrap-ansi?branch=master)
|
|
2
|
+
|
|
3
|
+
> Wordwrap a string with [ANSI escape codes](https://en.wikipedia.org/wiki/ANSI_escape_code#Colors_and_Styles)
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
## Install
|
|
7
|
+
|
|
8
|
+
```
|
|
9
|
+
$ npm install wrap-ansi
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
## Usage
|
|
14
|
+
|
|
15
|
+
```js
|
|
16
|
+
const chalk = require('chalk');
|
|
17
|
+
const wrapAnsi = require('wrap-ansi');
|
|
18
|
+
|
|
19
|
+
const input = 'The quick brown ' + chalk.red('fox jumped over ') +
|
|
20
|
+
'the lazy ' + chalk.green('dog and then ran away with the unicorn.');
|
|
21
|
+
|
|
22
|
+
console.log(wrapAnsi(input, 20));
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
<img width="331" src="screenshot.png">
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
## API
|
|
29
|
+
|
|
30
|
+
### wrapAnsi(string, columns, options?)
|
|
31
|
+
|
|
32
|
+
Wrap words to the specified column width.
|
|
33
|
+
|
|
34
|
+
#### string
|
|
35
|
+
|
|
36
|
+
Type: `string`
|
|
37
|
+
|
|
38
|
+
String with ANSI escape codes. Like one styled by [`chalk`](https://github.com/chalk/chalk). Newline characters will be normalized to `\n`.
|
|
39
|
+
|
|
40
|
+
#### columns
|
|
41
|
+
|
|
42
|
+
Type: `number`
|
|
43
|
+
|
|
44
|
+
Number of columns to wrap the text to.
|
|
45
|
+
|
|
46
|
+
#### options
|
|
47
|
+
|
|
48
|
+
Type: `object`
|
|
49
|
+
|
|
50
|
+
##### hard
|
|
51
|
+
|
|
52
|
+
Type: `boolean`<br>
|
|
53
|
+
Default: `false`
|
|
54
|
+
|
|
55
|
+
By default the wrap is soft, meaning long words may extend past the column width. Setting this to `true` will make it hard wrap at the column width.
|
|
56
|
+
|
|
57
|
+
##### wordWrap
|
|
58
|
+
|
|
59
|
+
Type: `boolean`<br>
|
|
60
|
+
Default: `true`
|
|
61
|
+
|
|
62
|
+
By default, an attempt is made to split words at spaces, ensuring that they don't extend past the configured columns. If wordWrap is `false`, each column will instead be completely filled splitting words as necessary.
|
|
63
|
+
|
|
64
|
+
##### trim
|
|
65
|
+
|
|
66
|
+
Type: `boolean`<br>
|
|
67
|
+
Default: `true`
|
|
68
|
+
|
|
69
|
+
Whitespace on all lines is removed by default. Set this option to `false` if you don't want to trim.
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
## Related
|
|
73
|
+
|
|
74
|
+
- [slice-ansi](https://github.com/chalk/slice-ansi) - Slice a string with ANSI escape codes
|
|
75
|
+
- [cli-truncate](https://github.com/sindresorhus/cli-truncate) - Truncate a string to a specific width in the terminal
|
|
76
|
+
- [chalk](https://github.com/chalk/chalk) - Terminal string styling done right
|
|
77
|
+
- [jsesc](https://github.com/mathiasbynens/jsesc) - Generate ASCII-only output from Unicode strings. Useful for creating test fixtures.
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
## Maintainers
|
|
81
|
+
|
|
82
|
+
- [Sindre Sorhus](https://github.com/sindresorhus)
|
|
83
|
+
- [Josh Junon](https://github.com/qix-)
|
|
84
|
+
- [Benjamin Coe](https://github.com/bcoe)
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
---
|
|
88
|
+
|
|
89
|
+
<div align="center">
|
|
90
|
+
<b>
|
|
91
|
+
<a href="https://tidelift.com/subscription/pkg/npm-wrap_ansi?utm_source=npm-wrap-ansi&utm_medium=referral&utm_campaign=readme">Get professional support for this package with a Tidelift subscription</a>
|
|
92
|
+
</b>
|
|
93
|
+
<br>
|
|
94
|
+
<sub>
|
|
95
|
+
Tidelift helps make open source sustainable for maintainers while giving companies<br>assurances about security, maintenance, and licensing for their dependencies.
|
|
96
|
+
</sub>
|
|
97
|
+
</div>
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
# Change Log
|
|
2
|
+
|
|
3
|
+
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
### [4.0.3](https://www.github.com/yargs/y18n/compare/y18n-v4.0.2...y18n-v4.0.3) (2021-04-07)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Bug Fixes
|
|
10
|
+
|
|
11
|
+
* **release:** 4.x.x should not enforce Node 10 ([#126](https://www.github.com/yargs/y18n/issues/126)) ([1e21a53](https://www.github.com/yargs/y18n/commit/1e21a536e9135d8403a47be88922157a706b7cde))
|
|
12
|
+
|
|
13
|
+
### 4.0.1 (2020-11-30)
|
|
14
|
+
|
|
15
|
+
### Bug Fixes
|
|
16
|
+
|
|
17
|
+
* address prototype pollution issue ([#108](https://www.github.com/yargs/y18n/issues/108)) ([a9ac604](https://www.github.com/yargs/y18n/commit/a9ac604abf756dec9687be3843e2c93bfe581f25))
|
|
18
|
+
|
|
19
|
+
<a name="4.0.0"></a>
|
|
20
|
+
# [4.0.0](https://github.com/yargs/y18n/compare/v3.2.1...v4.0.0) (2017-10-10)
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
### Bug Fixes
|
|
24
|
+
|
|
25
|
+
* allow support for falsy values like 0 in tagged literal ([#45](https://github.com/yargs/y18n/issues/45)) ([c926123](https://github.com/yargs/y18n/commit/c926123))
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
### Features
|
|
29
|
+
|
|
30
|
+
* **__:** added tagged template literal support ([#44](https://github.com/yargs/y18n/issues/44)) ([0598daf](https://github.com/yargs/y18n/commit/0598daf))
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
### BREAKING CHANGES
|
|
34
|
+
|
|
35
|
+
* **__:** dropping Node 0.10/Node 0.12 support
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
Copyright (c) 2015, Contributors
|
|
2
|
+
|
|
3
|
+
Permission to use, copy, modify, and/or distribute this software for any purpose
|
|
4
|
+
with or without fee is hereby granted, provided that the above copyright notice
|
|
5
|
+
and this permission notice appear in all copies.
|
|
6
|
+
|
|
7
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
8
|
+
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
|
9
|
+
FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
10
|
+
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
|
|
11
|
+
OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
|
|
12
|
+
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
|
|
13
|
+
THIS SOFTWARE.
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
# y18n
|
|
2
|
+
|
|
3
|
+
[![Build Status][travis-image]][travis-url]
|
|
4
|
+
[![Coverage Status][coveralls-image]][coveralls-url]
|
|
5
|
+
[![NPM version][npm-image]][npm-url]
|
|
6
|
+
[![js-standard-style][standard-image]][standard-url]
|
|
7
|
+
[](https://conventionalcommits.org)
|
|
8
|
+
|
|
9
|
+
The bare-bones internationalization library used by yargs.
|
|
10
|
+
|
|
11
|
+
Inspired by [i18n](https://www.npmjs.com/package/i18n).
|
|
12
|
+
|
|
13
|
+
## Examples
|
|
14
|
+
|
|
15
|
+
_simple string translation:_
|
|
16
|
+
|
|
17
|
+
```js
|
|
18
|
+
var __ = require('y18n').__
|
|
19
|
+
|
|
20
|
+
console.log(__('my awesome string %s', 'foo'))
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
output:
|
|
24
|
+
|
|
25
|
+
`my awesome string foo`
|
|
26
|
+
|
|
27
|
+
_using tagged template literals_
|
|
28
|
+
|
|
29
|
+
```js
|
|
30
|
+
var __ = require('y18n').__
|
|
31
|
+
var str = 'foo'
|
|
32
|
+
|
|
33
|
+
console.log(__`my awesome string ${str}`)
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
output:
|
|
37
|
+
|
|
38
|
+
`my awesome string foo`
|
|
39
|
+
|
|
40
|
+
_pluralization support:_
|
|
41
|
+
|
|
42
|
+
```js
|
|
43
|
+
var __n = require('y18n').__n
|
|
44
|
+
|
|
45
|
+
console.log(__n('one fish %s', '%d fishes %s', 2, 'foo'))
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
output:
|
|
49
|
+
|
|
50
|
+
`2 fishes foo`
|
|
51
|
+
|
|
52
|
+
## JSON Language Files
|
|
53
|
+
|
|
54
|
+
The JSON language files should be stored in a `./locales` folder.
|
|
55
|
+
File names correspond to locales, e.g., `en.json`, `pirate.json`.
|
|
56
|
+
|
|
57
|
+
When strings are observed for the first time they will be
|
|
58
|
+
added to the JSON file corresponding to the current locale.
|
|
59
|
+
|
|
60
|
+
## Methods
|
|
61
|
+
|
|
62
|
+
### require('y18n')(config)
|
|
63
|
+
|
|
64
|
+
Create an instance of y18n with the config provided, options include:
|
|
65
|
+
|
|
66
|
+
* `directory`: the locale directory, default `./locales`.
|
|
67
|
+
* `updateFiles`: should newly observed strings be updated in file, default `true`.
|
|
68
|
+
* `locale`: what locale should be used.
|
|
69
|
+
* `fallbackToLanguage`: should fallback to a language-only file (e.g. `en.json`)
|
|
70
|
+
be allowed if a file matching the locale does not exist (e.g. `en_US.json`),
|
|
71
|
+
default `true`.
|
|
72
|
+
|
|
73
|
+
### y18n.\_\_(str, arg, arg, arg)
|
|
74
|
+
|
|
75
|
+
Print a localized string, `%s` will be replaced with `arg`s.
|
|
76
|
+
|
|
77
|
+
This function can also be used as a tag for a template literal. You can use it
|
|
78
|
+
like this: <code>__`hello ${'world'}`</code>. This will be equivalent to
|
|
79
|
+
`__('hello %s', 'world')`.
|
|
80
|
+
|
|
81
|
+
### y18n.\_\_n(singularString, pluralString, count, arg, arg, arg)
|
|
82
|
+
|
|
83
|
+
Print a localized string with appropriate pluralization. If `%d` is provided
|
|
84
|
+
in the string, the `count` will replace this placeholder.
|
|
85
|
+
|
|
86
|
+
### y18n.setLocale(str)
|
|
87
|
+
|
|
88
|
+
Set the current locale being used.
|
|
89
|
+
|
|
90
|
+
### y18n.getLocale()
|
|
91
|
+
|
|
92
|
+
What locale is currently being used?
|
|
93
|
+
|
|
94
|
+
### y18n.updateLocale(obj)
|
|
95
|
+
|
|
96
|
+
Update the current locale with the key value pairs in `obj`.
|
|
97
|
+
|
|
98
|
+
## License
|
|
99
|
+
|
|
100
|
+
ISC
|
|
101
|
+
|
|
102
|
+
[travis-url]: https://travis-ci.org/yargs/y18n
|
|
103
|
+
[travis-image]: https://img.shields.io/travis/yargs/y18n.svg
|
|
104
|
+
[coveralls-url]: https://coveralls.io/github/yargs/y18n
|
|
105
|
+
[coveralls-image]: https://img.shields.io/coveralls/yargs/y18n.svg
|
|
106
|
+
[npm-url]: https://npmjs.org/package/y18n
|
|
107
|
+
[npm-image]: https://img.shields.io/npm/v/y18n.svg
|
|
108
|
+
[standard-image]: https://img.shields.io/badge/code%20style-standard-brightgreen.svg
|
|
109
|
+
[standard-url]: https://github.com/feross/standard
|
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
var fs = require('fs')
|
|
2
|
+
var path = require('path')
|
|
3
|
+
var util = require('util')
|
|
4
|
+
|
|
5
|
+
function Y18N (opts) {
|
|
6
|
+
// configurable options.
|
|
7
|
+
opts = opts || {}
|
|
8
|
+
this.directory = opts.directory || './locales'
|
|
9
|
+
this.updateFiles = typeof opts.updateFiles === 'boolean' ? opts.updateFiles : true
|
|
10
|
+
this.locale = opts.locale || 'en'
|
|
11
|
+
this.fallbackToLanguage = typeof opts.fallbackToLanguage === 'boolean' ? opts.fallbackToLanguage : true
|
|
12
|
+
|
|
13
|
+
// internal stuff.
|
|
14
|
+
this.cache = Object.create(null)
|
|
15
|
+
this.writeQueue = []
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
Y18N.prototype.__ = function () {
|
|
19
|
+
if (typeof arguments[0] !== 'string') {
|
|
20
|
+
return this._taggedLiteral.apply(this, arguments)
|
|
21
|
+
}
|
|
22
|
+
var args = Array.prototype.slice.call(arguments)
|
|
23
|
+
var str = args.shift()
|
|
24
|
+
var cb = function () {} // start with noop.
|
|
25
|
+
|
|
26
|
+
if (typeof args[args.length - 1] === 'function') cb = args.pop()
|
|
27
|
+
cb = cb || function () {} // noop.
|
|
28
|
+
|
|
29
|
+
if (!this.cache[this.locale]) this._readLocaleFile()
|
|
30
|
+
|
|
31
|
+
// we've observed a new string, update the language file.
|
|
32
|
+
if (!this.cache[this.locale][str] && this.updateFiles) {
|
|
33
|
+
this.cache[this.locale][str] = str
|
|
34
|
+
|
|
35
|
+
// include the current directory and locale,
|
|
36
|
+
// since these values could change before the
|
|
37
|
+
// write is performed.
|
|
38
|
+
this._enqueueWrite([this.directory, this.locale, cb])
|
|
39
|
+
} else {
|
|
40
|
+
cb()
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
return util.format.apply(util, [this.cache[this.locale][str] || str].concat(args))
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
Y18N.prototype._taggedLiteral = function (parts) {
|
|
47
|
+
var args = arguments
|
|
48
|
+
var str = ''
|
|
49
|
+
parts.forEach(function (part, i) {
|
|
50
|
+
var arg = args[i + 1]
|
|
51
|
+
str += part
|
|
52
|
+
if (typeof arg !== 'undefined') {
|
|
53
|
+
str += '%s'
|
|
54
|
+
}
|
|
55
|
+
})
|
|
56
|
+
return this.__.apply(null, [str].concat([].slice.call(arguments, 1)))
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
Y18N.prototype._enqueueWrite = function (work) {
|
|
60
|
+
this.writeQueue.push(work)
|
|
61
|
+
if (this.writeQueue.length === 1) this._processWriteQueue()
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
Y18N.prototype._processWriteQueue = function () {
|
|
65
|
+
var _this = this
|
|
66
|
+
var work = this.writeQueue[0]
|
|
67
|
+
|
|
68
|
+
// destructure the enqueued work.
|
|
69
|
+
var directory = work[0]
|
|
70
|
+
var locale = work[1]
|
|
71
|
+
var cb = work[2]
|
|
72
|
+
|
|
73
|
+
var languageFile = this._resolveLocaleFile(directory, locale)
|
|
74
|
+
var serializedLocale = JSON.stringify(this.cache[locale], null, 2)
|
|
75
|
+
|
|
76
|
+
fs.writeFile(languageFile, serializedLocale, 'utf-8', function (err) {
|
|
77
|
+
_this.writeQueue.shift()
|
|
78
|
+
if (_this.writeQueue.length > 0) _this._processWriteQueue()
|
|
79
|
+
cb(err)
|
|
80
|
+
})
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
Y18N.prototype._readLocaleFile = function () {
|
|
84
|
+
var localeLookup = {}
|
|
85
|
+
var languageFile = this._resolveLocaleFile(this.directory, this.locale)
|
|
86
|
+
|
|
87
|
+
try {
|
|
88
|
+
localeLookup = JSON.parse(fs.readFileSync(languageFile, 'utf-8'))
|
|
89
|
+
} catch (err) {
|
|
90
|
+
if (err instanceof SyntaxError) {
|
|
91
|
+
err.message = 'syntax error in ' + languageFile
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
if (err.code === 'ENOENT') localeLookup = {}
|
|
95
|
+
else throw err
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
this.cache[this.locale] = localeLookup
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
Y18N.prototype._resolveLocaleFile = function (directory, locale) {
|
|
102
|
+
var file = path.resolve(directory, './', locale + '.json')
|
|
103
|
+
if (this.fallbackToLanguage && !this._fileExistsSync(file) && ~locale.lastIndexOf('_')) {
|
|
104
|
+
// attempt fallback to language only
|
|
105
|
+
var languageFile = path.resolve(directory, './', locale.split('_')[0] + '.json')
|
|
106
|
+
if (this._fileExistsSync(languageFile)) file = languageFile
|
|
107
|
+
}
|
|
108
|
+
return file
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
// this only exists because fs.existsSync() "will be deprecated"
|
|
112
|
+
// see https://nodejs.org/api/fs.html#fs_fs_existssync_path
|
|
113
|
+
Y18N.prototype._fileExistsSync = function (file) {
|
|
114
|
+
try {
|
|
115
|
+
return fs.statSync(file).isFile()
|
|
116
|
+
} catch (err) {
|
|
117
|
+
return false
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
Y18N.prototype.__n = function () {
|
|
122
|
+
var args = Array.prototype.slice.call(arguments)
|
|
123
|
+
var singular = args.shift()
|
|
124
|
+
var plural = args.shift()
|
|
125
|
+
var quantity = args.shift()
|
|
126
|
+
|
|
127
|
+
var cb = function () {} // start with noop.
|
|
128
|
+
if (typeof args[args.length - 1] === 'function') cb = args.pop()
|
|
129
|
+
|
|
130
|
+
if (!this.cache[this.locale]) this._readLocaleFile()
|
|
131
|
+
|
|
132
|
+
var str = quantity === 1 ? singular : plural
|
|
133
|
+
if (this.cache[this.locale][singular]) {
|
|
134
|
+
str = this.cache[this.locale][singular][quantity === 1 ? 'one' : 'other']
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
// we've observed a new string, update the language file.
|
|
138
|
+
if (!this.cache[this.locale][singular] && this.updateFiles) {
|
|
139
|
+
this.cache[this.locale][singular] = {
|
|
140
|
+
one: singular,
|
|
141
|
+
other: plural
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
// include the current directory and locale,
|
|
145
|
+
// since these values could change before the
|
|
146
|
+
// write is performed.
|
|
147
|
+
this._enqueueWrite([this.directory, this.locale, cb])
|
|
148
|
+
} else {
|
|
149
|
+
cb()
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
// if a %d placeholder is provided, add quantity
|
|
153
|
+
// to the arguments expanded by util.format.
|
|
154
|
+
var values = [str]
|
|
155
|
+
if (~str.indexOf('%d')) values.push(quantity)
|
|
156
|
+
|
|
157
|
+
return util.format.apply(util, values.concat(args))
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
Y18N.prototype.setLocale = function (locale) {
|
|
161
|
+
this.locale = locale
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
Y18N.prototype.getLocale = function () {
|
|
165
|
+
return this.locale
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
Y18N.prototype.updateLocale = function (obj) {
|
|
169
|
+
if (!this.cache[this.locale]) this._readLocaleFile()
|
|
170
|
+
|
|
171
|
+
for (var key in obj) {
|
|
172
|
+
this.cache[this.locale][key] = obj[key]
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
module.exports = function (opts) {
|
|
177
|
+
var y18n = new Y18N(opts)
|
|
178
|
+
|
|
179
|
+
// bind all functions to y18n, so that
|
|
180
|
+
// they can be used in isolation.
|
|
181
|
+
for (var key in y18n) {
|
|
182
|
+
if (typeof y18n[key] === 'function') {
|
|
183
|
+
y18n[key] = y18n[key].bind(y18n)
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
return y18n
|
|
188
|
+
}
|