Socket
Socket
Sign inDemoInstall

react-localization

Package Overview
Dependencies
0
Maintainers
1
Versions
47
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.0.16 to 0.0.17

2

lib/LocalizedStrings.js

@@ -27,2 +27,3 @@ 'use strict';

var DEFAULT_VALUE = 'en-US';
var reservedNames = ["_getInterfaceLanguage", "_getBestMatchingLanguage", "setContent", "_interfaceLanguage", "_defaultLanguage", "_defaultLanguageFirstLevelKeys", "_props"];

@@ -61,3 +62,2 @@ var LocalizedStrings = function () {

//Add property before checking for use of reserved words...
this._interfaceLanguage = this._getInterfaceLanguage();

@@ -64,0 +64,0 @@ this._language = this._interfaceLanguage;

{
"name": "react-localization",
"version": "0.0.16",
"version": "0.0.17",
"description": "Simple module to localize the React interface using the same syntax used in the ReactNativeLocalization module, use 'npm run build' before publishing",

@@ -5,0 +5,0 @@ "scripts": {

import LocalizedStrings from './../src/LocalizedStrings';
let strings = new LocalizedStrings({

@@ -40,4 +41,18 @@ en:{

}
}
const contentForTesting = {
en: {
a: {
b: { x: "a.b.x", y: "a.b.y" },
c: { z: "a.c.z" }
}
}
};
const forbiddenContent = {
en:{
language:"language",
_language:"language is forbidden"
}
}

@@ -108,2 +123,25 @@

it('Switch to different props not working', function () {
strings = new LocalizedStrings({
en: {
a: {
b: { x: "foo", y: "bar" },
c: { z: "baz" }
}
}
});
strings.setContent(
contentForTesting
)
strings.setLanguage("en");
expect(strings.a.b.x).toEqual('a.b.x');
});
it('Should throw an exception if a reserved word is used', function(){
expect( function(){
strings = new LocalizedStrings(forbiddenContent);
} ).toThrow(new Error("_language cannot be used as a key. It is a reserved word."));
});
});

@@ -19,3 +19,7 @@ 'use strict';

const DEFAULT_VALUE = 'en-US';
let reservedNames = [ '_interfaceLanguage',
'_language',
'_defaultLanguage',
'_defaultLanguageFirstLevelKeys',
'_props' ];
export default class LocalizedStrings {

@@ -49,3 +53,2 @@ _getInterfaceLanguage() {

constructor(props) {
//Add property before checking for use of reserved words...
this._interfaceLanguage = this._getInterfaceLanguage();

@@ -75,3 +78,3 @@ this._language = this._interfaceLanguage;

Object.keys(props).map(key => {
if (this.hasOwnProperty(key)) throw new Error(`${key} cannot be used as a key. It is a reserved word.`)
if (reservedNames.indexOf(key)>=0) throw new Error(`${key} cannot be used as a key. It is a reserved word.`)
})

@@ -78,0 +81,0 @@ }

SocketSocket SOC 2 Logo

Product

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

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc