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

i18next-parser

Package Overview
Dependencies
Maintainers
1
Versions
144
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

i18next-parser - npm Package Compare versions

Comparing version 1.0.0-beta37 to 1.0.0-beta38

16

dist/lexers/javascript-lexer.js

@@ -1,2 +0,2 @@

'use strict';Object.defineProperty(exports, "__esModule", { value: true });var _createClass = function () {function defineProperties(target, props) {for (var i = 0; i < props.length; i++) {var descriptor = props[i];descriptor.enumerable = descriptor.enumerable || false;descriptor.configurable = true;if ("value" in descriptor) descriptor.writable = true;Object.defineProperty(target, descriptor.key, descriptor);}}return function (Constructor, protoProps, staticProps) {if (protoProps) defineProperties(Constructor.prototype, protoProps);if (staticProps) defineProperties(Constructor, staticProps);return Constructor;};}();var _baseLexer = require('./base-lexer');var _baseLexer2 = _interopRequireDefault(_baseLexer);
'use strict';Object.defineProperty(exports, "__esModule", { value: true });var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) {return typeof obj;} : function (obj) {return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;};var _createClass = function () {function defineProperties(target, props) {for (var i = 0; i < props.length; i++) {var descriptor = props[i];descriptor.enumerable = descriptor.enumerable || false;descriptor.configurable = true;if ("value" in descriptor) descriptor.writable = true;Object.defineProperty(target, descriptor.key, descriptor);}}return function (Constructor, protoProps, staticProps) {if (protoProps) defineProperties(Constructor.prototype, protoProps);if (staticProps) defineProperties(Constructor, staticProps);return Constructor;};}();var _baseLexer = require('./base-lexer');var _baseLexer2 = _interopRequireDefault(_baseLexer);
var _typescript = require('typescript');var ts = _interopRequireWildcard(_typescript);function _interopRequireWildcard(obj) {if (obj && obj.__esModule) {return obj;} else {var newObj = {};if (obj != null) {for (var key in obj) {if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key];}}newObj.default = obj;return newObj;}}function _interopRequireDefault(obj) {return obj && obj.__esModule ? obj : { default: obj };}function _classCallCheck(instance, Constructor) {if (!(instance instanceof Constructor)) {throw new TypeError("Cannot call a class as a function");}}function _possibleConstructorReturn(self, call) {if (!self) {throw new ReferenceError("this hasn't been initialised - super() hasn't been called");}return call && (typeof call === "object" || typeof call === "function") ? call : self;}function _inherits(subClass, superClass) {if (typeof superClass !== "function" && superClass !== null) {throw new TypeError("Super expression must either be null or a function, not " + typeof superClass);}subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } });if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass;}var

@@ -77,5 +77,19 @@

if (entry.ns) {
if (typeof entry.ns === 'string') {
entry.namespace = entry.ns;
} else if (_typeof(entry.ns) === 'object' && entry.ns.length) {
entry.namespace = entry.ns[0];
}
} else if (this.defaultNamespace) {
entry.namespace = this.defaultNamespace;
}
return entry;
}
if (node.expression.escapedText === 'useTranslation' && node.arguments.length) {
this.defaultNamespace = node.arguments[0].text;
}
return null;

@@ -82,0 +96,0 @@ } }, { key: 'concatenateString', value: function concatenateString(

@@ -46,7 +46,9 @@ 'use strict';Object.defineProperty(exports, "__esModule", { value: true });var _createClass = function () {function defineProperties(target, props) {for (var i = 0; i < props.length; i++) {var descriptor = props[i];descriptor.enumerable = descriptor.enumerable || false;descriptor.configurable = true;if ("value" in descriptor) descriptor.writable = true;Object.defineProperty(target, descriptor.key, descriptor);}}return function (Constructor, protoProps, staticProps) {if (protoProps) defineProperties(Constructor.prototype, protoProps);if (staticProps) defineProperties(Constructor, staticProps);return Constructor;};}();var _javascriptLexer = require('./javascript-lexer');var _javascriptLexer2 = _interopRequireDefault(_javascriptLexer);

var getKey = function getKey(node) {
var attribute = node.attributes.properties.find(function (attr) {return attr.name.text === _this3.attr;});
var getPropValue = function getPropValue(node, tagName) {
var attribute = node.attributes.properties.find(function (attr) {return attr.name.text === tagName;});
return attribute && attribute.initializer.text;
};
var getKey = function getKey(node) {return getPropValue(node, _this3.attr);};
if (tagNode.tagName.text === "Trans") {

@@ -66,2 +68,7 @@ var entry = {};

var namespace = getPropValue(tagNode, 'ns');
if (namespace) {
entry.namespace = namespace;
}
return entry.key ? entry : null;

@@ -68,0 +75,0 @@ } else

2

package.json

@@ -5,3 +5,3 @@ {

"name": "i18next-parser",
"version": "1.0.0-beta37",
"version": "1.0.0-beta38",
"license": "MIT",

@@ -8,0 +8,0 @@ "main": "dist/index.js",

@@ -77,5 +77,19 @@ import BaseLexer from './base-lexer'

if (entry.ns) {
if (typeof entry.ns === 'string') {
entry.namespace = entry.ns
} else if (typeof entry.ns === 'object' && entry.ns.length) {
entry.namespace = entry.ns[0]
}
} else if (this.defaultNamespace) {
entry.namespace = this.defaultNamespace
}
return entry
}
if(node.expression.escapedText === 'useTranslation' && node.arguments.length) {
this.defaultNamespace = node.arguments[0].text
}
return null

@@ -82,0 +96,0 @@ }

@@ -46,7 +46,9 @@ import JavascriptLexer from './javascript-lexer'

const getKey = (node) => {
const attribute = node.attributes.properties.find(attr => attr.name.text === this.attr)
const getPropValue = (node, tagName) => {
const attribute = node.attributes.properties.find(attr => attr.name.text === tagName)
return attribute && attribute.initializer.text
}
const getKey = (node) => getPropValue(node, this.attr)
if (tagNode.tagName.text === "Trans") {

@@ -66,2 +68,7 @@ const entry = {}

const namespace = getPropValue(tagNode, 'ns')
if (namespace) {
entry.namespace = namespace
}
return entry.key ? entry : null

@@ -68,0 +75,0 @@ }

@@ -126,2 +126,15 @@ import { assert } from 'chai'

})
it('extracts default namespace from useTranslation hook', () => {
const Lexer = new JavascriptLexer()
const content = 'const {t} = useTranslation("foo"); t("bar");'
assert.deepEqual(Lexer.extract(content), [{ namespace: 'foo', key: 'bar' }])
})
it('uses namespace from t function with priority', () => {
const Lexer = new JavascriptLexer()
const content = 'const {t} = useTranslation("foo"); t("bar", {ns: "baz"});'
assert.deepEqual(Lexer.extract(content), [{ namespace: 'baz', key: 'bar', ns: 'baz' }])
})
})

@@ -122,2 +122,10 @@ import { assert, expect } from 'chai'

})
it('uses the ns (namespace) prop', (done) => {
const Lexer = new JsxLexer()
const content = `<Trans ns="foo">bar</Trans>`
assert.deepEqual(Lexer.extract(content), [{ key: 'bar', defaultValue: 'bar', namespace: 'foo' }])
done()
})
})

@@ -124,0 +132,0 @@

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