fepper-utils
Advanced tools
Comparing version 1.3.6 to 1.3.7-rc.0
75
index.js
@@ -14,2 +14,39 @@ 'use strict'; | ||
// ///////////////////////////////////////////////////////////////////////////// | ||
// Internationalization. | ||
// ///////////////////////////////////////////////////////////////////////////// | ||
/** | ||
* Translate using an English key. | ||
* | ||
* @param {string} key - The phrase in English. | ||
* @returns {string} The phrase in another language (or an English alternative). | ||
*/ | ||
exports.t = (key) => { | ||
const lang = exports.deepGet(global, 'pref.lang') || 'en'; | ||
let i18nFileStr; | ||
if ( | ||
exports.deepGet(global, 'conf.ui.paths.source.ui') && | ||
fs.existsSync(`${global.conf.ui.paths.source.ui}/i18n/${lang}.json`) | ||
) { | ||
i18nFileStr = fs.readFileSync(`${global.conf.ui.paths.source.ui}/i18n/${lang}.json`, enc); | ||
} | ||
else if (fs.existsSync(`${global.workDir}/source/_ui/i18n/${lang}.json`)) { | ||
i18nFileStr = fs.readFileSync(`${global.workDir}/source/_ui/i18n/${lang}.json`, enc); | ||
} | ||
else { | ||
i18nFileStr = fs.readFileSync(`${global.appDir}/excludes/profiles/base/source/_ui/i18n/en.json`, enc); | ||
} | ||
const i18nData = JSON5.parse(i18nFileStr); | ||
if (i18nData[key]) { | ||
return i18nData[key]; | ||
} | ||
else { | ||
return key; | ||
} | ||
}; | ||
// ///////////////////////////////////////////////////////////////////////////// | ||
// Conf and global vars. | ||
@@ -20,5 +57,7 @@ // ///////////////////////////////////////////////////////////////////////////// | ||
// exports.conf() must always be run before exports.pref(). | ||
// Cannot internationalize messages because conf and pref have not been loaded yet. | ||
// Do not JSDoc. | ||
exports.conf = () => { | ||
const rootDir = global.rootDir; | ||
global.t = exports.t; | ||
@@ -36,3 +75,3 @@ // Return if global.conf already set. | ||
const yml = fs.readFileSync(`${rootDir}/conf.yml`, enc); | ||
conf = yaml.safeLoad(yml); | ||
conf = global.conf = yaml.safeLoad(yml); | ||
} | ||
@@ -108,3 +147,3 @@ catch (err) { | ||
conf.scrape = { | ||
limit_error_msg: 'Submitting too many requests per minute.', | ||
limit_error_msg: 'Submitting too many requests per minute', | ||
limit_time: 30000, | ||
@@ -114,6 +153,2 @@ scraper_file: `00-html-scraper${conf.ui.patternExtension}` | ||
// Write to global object. | ||
// This assignment is deprecated and will be removed. The assignment should be explicit where .conf() is invoked. | ||
global.conf = conf; | ||
return conf; | ||
@@ -133,9 +168,10 @@ }; | ||
else { | ||
// this.findup() will replace backslashes with slashes. | ||
rootDir = this.findup('fepper.command', dirname); | ||
// exports.findup() will replace backslashes with slashes. | ||
rootDir = exports.findup('fepper.command', dirname); | ||
} | ||
if (!rootDir) { | ||
this.error('Fepper cannot find the directory in which to start working! ' + | ||
'You may need to submit it as a constructor argument! Exiting!'); | ||
// eslint-disable-next-line max-len | ||
exports.error(`${('Fepper cannot find the directory in which to start working! You may need to submit it as a constructor argument!')} ` + | ||
t('Exiting!')); | ||
throw new Error('EINVAL'); | ||
@@ -162,7 +198,7 @@ } | ||
const yml = fs.readFileSync(`${global.rootDir}/pref.yml`, enc); | ||
pref = yaml.safeLoad(yml); | ||
pref = global.pref = yaml.safeLoad(yml); | ||
} | ||
catch (err) { | ||
exports.error(err); | ||
exports.error('Missing or malformed pref.yml! Exiting!'); | ||
exports.error(`${t('Missing or malformed')} pref.yml! ${t('Exiting!')}`); | ||
@@ -181,3 +217,3 @@ return; | ||
exports.error(err); | ||
exports.error('Missing or malformed excludes/pref.yml! Exiting!'); | ||
exports.error(`${t('Missing or malformed')} excludes/pref.yml! ${t('Exiting!')}`); | ||
@@ -204,6 +240,2 @@ return; | ||
// Write to global object. | ||
// This assignment is deprecated and will be removed. The assignment should be explicit where .pref() is invoked. | ||
global.pref = pref; | ||
return pref; | ||
@@ -302,3 +334,4 @@ }; | ||
try { | ||
throw new Error('fepper-utils deepGet() requires a valid path parameter, i.e. `deepGet(nest, \'egg.yolk\')`'); | ||
// eslint-disable-next-line max-len | ||
throw new Error(`${t('fepper-utils deepGet() requires a valid path parameter, e.g. deepGet(nest, \'egg.yolk\')')}`); | ||
} | ||
@@ -532,3 +565,3 @@ catch (err) { | ||
exports.error(`The ${ext} extension contains invalid characters!`); | ||
exports.error(`${ext} ${t('extension contains invalid characters!')}`); | ||
} | ||
@@ -612,7 +645,7 @@ | ||
if (!uiObj || !uiObj.paths || !uiObj.paths.source) { | ||
throw 'Missing or malformed paths.source property!'; | ||
throw `${t('Missing or malformed')} paths.source!`; | ||
} | ||
if (!uiObj.paths.public) { | ||
throw 'Missing or malformed paths.public property!'; | ||
throw `${t('Missing or malformed')} paths.public!`; | ||
} | ||
@@ -619,0 +652,0 @@ |
{ | ||
"name": "fepper-utils", | ||
"version": "1.3.6", | ||
"version": "1.3.7-rc.0", | ||
"description": "Fepper utilities", | ||
@@ -44,3 +44,3 @@ "main": "index.js", | ||
"dependencies": { | ||
"js-beautify": "1.10.3", | ||
"js-beautify": "1.11.0", | ||
"rcloader": "^0.2.2" | ||
@@ -47,0 +47,0 @@ }, |
@@ -22,2 +22,5 @@ # Fepper Utilities | ||
<dl> | ||
<dt><a href="#t">t(key)</a> ⇒ <code>string</code></dt> | ||
<dd><p>Translate using an English key.</p> | ||
</dd> | ||
<dt><a href="#beautifyTemplate">beautifyTemplate(extendedTemplate)</a> ⇒ <code>string</code></dt> | ||
@@ -92,2 +95,14 @@ <dd><p>Beautify an HTML-like template. Any Feplet/Mustache code within will be beautified as well.</p> | ||
<a name="t"></a> | ||
## t(key) ⇒ <code>string</code> | ||
Translate using an English key. | ||
**Kind**: exported function | ||
**Returns**: <code>string</code> - The phrase in another language (or an English alternative). | ||
| Param | Type | Description | | ||
| --- | --- | --- | | ||
| key | <code>string</code> | The phrase in English. | | ||
<a name="beautifyTemplate"></a> | ||
@@ -94,0 +109,0 @@ |
Deprecated
MaintenanceThe maintainer of the package marked it as deprecated. This could indicate that a single version should not be used, or that the package is no longer maintained and any new vulnerabilities will not be fixed.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
43139
719
353
1
1
+ Addedjs-beautify@1.11.0(transitive)
+ Addedmkdirp@1.0.4(transitive)
- Removedjs-beautify@1.10.3(transitive)
- Removedminimist@1.2.8(transitive)
- Removedmkdirp@0.5.6(transitive)
Updatedjs-beautify@1.11.0