@coorpacademy/translate
Advanced tools
Comparing version 6.1.5 to 6.1.6-alpha.340
@@ -31,2 +31,10 @@ import test from 'ava'; | ||
}); | ||
test('should accept nested value', t => { | ||
const translate = createTranslate({ | ||
foo: { | ||
foo_none: 'I have no apples' | ||
} | ||
}); | ||
t.is(translate('foo.foo_none'), 'I have no apples'); | ||
}); | ||
test('should use the regular key when count property is passed and equal to 1 or not a number', t => { | ||
@@ -117,2 +125,10 @@ const translate = createTranslate({ | ||
}); | ||
test("should throw error if nested template couldn't be found", t => { | ||
const translate = createTranslate({ | ||
foo: 'Foo' | ||
}); | ||
t.throws(() => translate('foo.foo_none'), { | ||
message: 'Key foo.foo_none not found!' | ||
}); | ||
}); | ||
//# sourceMappingURL=translate.js.map |
@@ -6,2 +6,3 @@ import _replace from "lodash/fp/replace"; | ||
import _has from "lodash/fp/has"; | ||
import _getOr from "lodash/fp/getOr"; | ||
import _get from "lodash/fp/get"; | ||
@@ -11,3 +12,3 @@ const interpolation = /\{\{([\s\S]+?)\}\}/g; | ||
function getTemplate(locales, key, count) { | ||
const regularTemplate = locales[key]; | ||
const regularTemplate = _get(key, locales); | ||
@@ -19,3 +20,3 @@ if (!_isNumber(count)) { | ||
if (count === 0) { | ||
return locales[`${key}_none`] || regularTemplate; | ||
return _getOr(regularTemplate, `${key}_none`, locales); | ||
} | ||
@@ -27,3 +28,3 @@ | ||
return locales[`${key}_plural`] || regularTemplate; | ||
return _getOr(regularTemplate, `${key}_plural`, locales); | ||
} | ||
@@ -30,0 +31,0 @@ |
@@ -37,2 +37,10 @@ "use strict"; | ||
}); | ||
(0, _ava.default)('should accept nested value', t => { | ||
const translate = (0, _translate.default)({ | ||
foo: { | ||
foo_none: 'I have no apples' | ||
} | ||
}); | ||
t.is(translate('foo.foo_none'), 'I have no apples'); | ||
}); | ||
(0, _ava.default)('should use the regular key when count property is passed and equal to 1 or not a number', t => { | ||
@@ -123,2 +131,10 @@ const translate = (0, _translate.default)({ | ||
}); | ||
(0, _ava.default)("should throw error if nested template couldn't be found", t => { | ||
const translate = (0, _translate.default)({ | ||
foo: 'Foo' | ||
}); | ||
t.throws(() => translate('foo.foo_none'), { | ||
message: 'Key foo.foo_none not found!' | ||
}); | ||
}); | ||
//# sourceMappingURL=translate.js.map |
"use strict"; | ||
exports.__esModule = true; | ||
exports.default = void 0; | ||
exports.mockTranslate = mockTranslate; | ||
exports.default = void 0; | ||
@@ -17,2 +17,4 @@ var _replace2 = _interopRequireDefault(require("lodash/fp/replace")); | ||
var _getOr2 = _interopRequireDefault(require("lodash/fp/getOr")); | ||
var _get2 = _interopRequireDefault(require("lodash/fp/get")); | ||
@@ -25,3 +27,3 @@ | ||
function getTemplate(locales, key, count) { | ||
const regularTemplate = locales[key]; | ||
const regularTemplate = (0, _get2.default)(key, locales); | ||
@@ -33,3 +35,3 @@ if (!(0, _isNumber2.default)(count)) { | ||
if (count === 0) { | ||
return locales[`${key}_none`] || regularTemplate; | ||
return (0, _getOr2.default)(regularTemplate, `${key}_none`, locales); | ||
} | ||
@@ -41,3 +43,3 @@ | ||
return locales[`${key}_plural`] || regularTemplate; | ||
return (0, _getOr2.default)(regularTemplate, `${key}_plural`, locales); | ||
} | ||
@@ -44,0 +46,0 @@ |
{ | ||
"name": "@coorpacademy/translate", | ||
"version": "6.1.5", | ||
"version": "6.1.6-alpha.340+87e8913ff", | ||
"description": "", | ||
@@ -50,3 +50,3 @@ "main": "lib/translate.js", | ||
"author": "CoorpAcademy", | ||
"gitHead": "fd256574b0fba67126be17e1498830eac1278c32" | ||
"gitHead": "87e8913fff56755b6f822a3946dfffe2494b09cf" | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Manifest confusion
Supply chain riskThis package has inconsistent metadata. This could be malicious or caused by an error when publishing the package.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
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
35534
374
2
2