Socket
Socket
Sign inDemoInstall

i18next-scanner

Package Overview
Dependencies
Maintainers
1
Versions
92
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

i18next-scanner - npm Package Compare versions

Comparing version 1.9.2 to 1.9.3

2

lib/index.js

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

customTransform.call(this, file, enc, done);
return;

@@ -72,3 +71,2 @@ }

customFlush.call(this, done);
return;

@@ -75,0 +73,0 @@ }

47

lib/parser.js

@@ -379,22 +379,35 @@ 'use strict';

if (endsWithComma) {
var _opts = _extends({}, opts),
propsFilter = _opts.propsFilter;
var code = matchBalancedParentheses(content.substr(re.lastIndex));
var syntax = (0, _esprima.parse)('(' + code + ')');
var props = (0, _get2.default)(syntax, 'body[0].expression.properties') || [];
// http://i18next.com/docs/options/
var supportedOptions = ['defaultValue', 'count', 'context', 'ns'];
props.forEach(function (prop) {
if ((0, _includes2.default)(supportedOptions, prop.key.name)) {
if (prop.value.type === 'Literal') {
options[prop.key.name] = prop.value.value;
} else if (prop.value.type === 'TemplateLiteral') {
options[prop.key.name] = prop.value.quasis.map(function (element) {
return element.value.cooked;
}).join('');
} else {
// Unable to get value of the property
options[prop.key.name] = '';
if (typeof propsFilter === 'function') {
code = propsFilter(code);
}
try {
var syntax = (0, _esprima.parse)('(' + code + ')');
var props = (0, _get2.default)(syntax, 'body[0].expression.properties') || [];
// http://i18next.com/docs/options/
var supportedOptions = ['defaultValue', 'count', 'context', 'ns'];
props.forEach(function (prop) {
if ((0, _includes2.default)(supportedOptions, prop.key.name)) {
if (prop.value.type === 'Literal') {
options[prop.key.name] = prop.value.value;
} else if (prop.value.type === 'TemplateLiteral') {
options[prop.key.name] = prop.value.quasis.map(function (element) {
return element.value.cooked;
}).join('');
} else {
// Unable to get value of the property
options[prop.key.name] = '';
}
}
}
});
});
} catch (err) {
_this2.debuglog('Unable to parse code "' + code + '"');
_this2.debuglog(err);
}
}

@@ -401,0 +414,0 @@

{
"name": "i18next-scanner",
"version": "1.9.2",
"version": "1.9.3",
"description": "Scan your code, extract translation keys/values, and merge them into i18n resource files.",

@@ -5,0 +5,0 @@ "homepage": "https://github.com/i18next/i18next-scanner",

@@ -28,3 +28,2 @@ import fs from 'fs';

customTransform.call(this, file, enc, done);
return;

@@ -44,3 +43,2 @@ }

customFlush.call(this, done);
return;

@@ -47,0 +45,0 @@ }

@@ -293,27 +293,39 @@ /* eslint no-console: 0 */

if (endsWithComma) {
const code = matchBalancedParentheses(content.substr(re.lastIndex));
const syntax = parse('(' + code + ')');
const props = get(syntax, 'body[0].expression.properties') || [];
// http://i18next.com/docs/options/
const supportedOptions = [
'defaultValue',
'count',
'context',
'ns'
];
const { propsFilter } = { ...opts };
props.forEach((prop) => {
if (includes(supportedOptions, prop.key.name)) {
if (prop.value.type === 'Literal') {
options[prop.key.name] = prop.value.value;
} else if (prop.value.type === 'TemplateLiteral') {
options[prop.key.name] = prop.value.quasis
.map(element => element.value.cooked)
.join('');
} else {
// Unable to get value of the property
options[prop.key.name] = '';
let code = matchBalancedParentheses(content.substr(re.lastIndex));
if (typeof propsFilter === 'function') {
code = propsFilter(code);
}
try {
const syntax = parse('(' + code + ')');
const props = get(syntax, 'body[0].expression.properties') || [];
// http://i18next.com/docs/options/
const supportedOptions = [
'defaultValue',
'count',
'context',
'ns'
];
props.forEach((prop) => {
if (includes(supportedOptions, prop.key.name)) {
if (prop.value.type === 'Literal') {
options[prop.key.name] = prop.value.value;
} else if (prop.value.type === 'TemplateLiteral') {
options[prop.key.name] = prop.value.quasis
.map(element => element.value.cooked)
.join('');
} else {
// Unable to get value of the property
options[prop.key.name] = '';
}
}
}
});
});
} catch (err) {
this.debuglog(`Unable to parse code "${code}"`);
this.debuglog(err);
}
}

@@ -320,0 +332,0 @@

@@ -349,3 +349,3 @@ import fs from 'fs';

const content = fs.readFileSync(path.resolve(__dirname, 'fixtures/plural.js'), 'utf-8');
parser.parseFuncFromString(content);
parser.parseFuncFromString(content, { propsFilter: props => props });
t.same(parser.get(), {

@@ -386,3 +386,3 @@ en: {

const content = fs.readFileSync(path.resolve(__dirname, 'fixtures/context.js'), 'utf-8');
parser.parseFuncFromString(content);
parser.parseFuncFromString(content, { propsFilter: props => props });
t.same(parser.get(), {

@@ -555,2 +555,2 @@ en: {

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