Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

i18n-core

Package Overview
Dependencies
Maintainers
1
Versions
19
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

i18n-core - npm Package Compare versions

Comparing version 3.0.0 to 3.1.0

lib/mustacheSimple.js

10

CHANGELOG.md

@@ -5,2 +5,12 @@ # Change Log

<a name="3.1.0"></a>
# [3.1.0](https://github.com/martinheidegger/i18n-core/compare/v3.0.0...v3.1.0) (2017-05-29)
### Features
* **api:** Added absPrefix and absSection api methods for more convenient use of ‘abs’ ([787e33f](https://github.com/martinheidegger/i18n-core/commit/787e33f))
<a name="3.0.0"></a>

@@ -7,0 +17,0 @@ # [3.0.0](https://github.com/martinheidegger/i18n-core/compare/v2.1.1...v3.0.0) (2017-02-19)

8

lib/createNode.js

@@ -31,2 +31,8 @@ 'use strict'

},
absPrefix: function (prefix, allowSubModification) {
if (prefix === null || prefix === undefined) {
throw new Error('Prefix is not allowed to be null or undefined')
}
return createNode(prefix, this.absRoot, this.translator, allowSubModification)
},
prefix: function (prefix, allowSubModification) {

@@ -38,3 +44,3 @@ if (prefix === null || prefix === undefined) {

},
lock: function createClone (lock) {
lock: function createLock (lock) {
if (lock === undefined || lock) {

@@ -41,0 +47,0 @@ var clone = createNode(this.currentPrefix, this.parent, this.translator, true)

2

package.json
{
"name": "i18n-core",
"version": "3.0.0",
"version": "3.1.0",
"description": "Basic i18n translation.",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -5,2 +5,4 @@ 'use strict'

var createRoot = require('./lib/createRoot.js')
var vsprintfSimple = require('./lib/vsprintfSimple.js')
var mustacheSimple = require('./lib/mustacheSimple.js')

@@ -180,4 +182,20 @@ function defaultFallback (key) {

}
api.prefix = function prefix (prefix, allowModification) {
api.absPrefix = function prefix (prefix, allowModification) {
if (allowModification) {
return convertToAPI(node.absPrefix(prefix, allowModification))
}
var subAPI
if (!api.absStorage) {
api.absStorage = {}
} else {
subAPI = api.absStorage[prefix]
}
if (!subAPI) {
subAPI = convertToAPI(node.absPrefix(prefix, allowModification))
api.absStorage[prefix] = subAPI
}
return subAPI
}
api.prefix = function (prefix, allowModification) {
if (allowModification) {
return convertToAPI(node.prefix(prefix, allowModification))

@@ -197,2 +215,8 @@ }

}
api.root = function root () {
return api.absPrefix('')
}
api.absSection = function absSection (section, allowModification) {
return api.absPrefix(section + '.', allowModification)
}
api.section = function section (locale, allowModification) {

@@ -210,22 +234,2 @@ return api.prefix(locale + '.', allowModification)

function mustacheSimple (value, namedValues) {
return value.replace(/{{(.*)}}/ig, function (match, param) {
if (/^{.*}$/.test(param)) {
param = param.substring(0, param.length - 1)
}
var val = namedValues[param]
if (val === null || val === undefined) {
return ''
}
return String(val)
})
}
function vsprintfSimple (value, args) {
var cnt = 0
return value.replace(/%s/ig, function (match) {
return String(args[cnt++])
})
}
module.exports = function (data) {

@@ -238,5 +242,3 @@ var translator = function (value, key, namedValues, args) {

rootAPI.fallback = defaultFallback
rootAPI.mustache = {
render: mustacheSimple
}
rootAPI.mustache = mustacheSimple
rootAPI.vsprintf = vsprintfSimple

@@ -243,0 +245,0 @@ rootAPI.translator = defaultTranslation.bind(rootAPI)

@@ -133,1 +133,49 @@ 'use strict'

})
test('using of an absolute prefix', function (t) {
var root = i18n({a: {b: 1}, b: 2})
var a1 = root.prefix('a.', true)
t.equals(a1('b'), 1)
var a2 = a1.absPrefix('')
t.equals(a2('b'), 2)
t.end()
})
test('using of an absolute prefix that can be modified', function (t) {
var root = i18n({a: {b: 1}, b: 2})
var prefixed = root.absPrefix('', true)
t.equals(prefixed('b'), 2)
prefixed.changePrefix('a.')
t.equals(prefixed('b'), 1)
t.end()
})
test('using of an absolute section', function (t) {
var root = i18n({a: {b: {c: 1}}, b: {c: 2}})
var a1 = root.prefix('a.b.', true)
t.equals(a1('c'), 1)
var a2 = a1.absSection('b')
t.equals(a2('c'), 2)
t.end()
})
test('root will result in the same lookup as absPrefix with ""', function (t) {
var initial = i18n({a: {b: 1}, b: 2})
var a1 = initial.prefix('a.')
var a2 = a1.absPrefix('')
var a3 = a1.root()
t.equals(a2('b'), a3('b'))
t.end()
})
test('an absolute prefix is required like a regular one', function (t) {
var root = i18n({a: {b: 1}, b: 2})
try {
root.absPrefix(null)
} catch (e) {
t.end()
return
}
t.fail('No error thrown.')
t.end()
})
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc