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

i18next-scanner

Package Overview
Dependencies
Maintainers
1
Versions
93
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 3.1.0 to 3.2.0

4

lib/acorn-jsx-walk.js

@@ -12,5 +12,5 @@ "use strict";

function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }

@@ -17,0 +17,0 @@ function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }

"use strict";
function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }

@@ -56,6 +56,18 @@ Object.defineProperty(exports, "__esModule", {

function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

@@ -65,3 +77,3 @@

function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }

@@ -154,3 +166,5 @@ function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }

}
},
metadata: {} // additional custom options
}; // http://codereview.stackexchange.com/questions/45991/balanced-parentheses

@@ -446,2 +460,46 @@

return fixedString;
}
}, {
key: "handleObjectExpression",
value: function handleObjectExpression(props) {
var _this2 = this;
return props.reduce(function (acc, prop) {
if (prop.type !== 'ObjectMethod') {
var value = _this2.optionsBuilder(prop.value);
if (value !== undefined) {
return _objectSpread(_objectSpread({}, acc), {}, _defineProperty({}, prop.key.name, value));
}
}
return acc;
}, {});
}
}, {
key: "handleArrayExpression",
value: function handleArrayExpression(elements) {
var _this3 = this;
return elements.reduce(function (acc, element) {
return [].concat(_toConsumableArray(acc), [_this3.optionsBuilder(element)]);
}, []);
}
}, {
key: "optionsBuilder",
value: function optionsBuilder(prop) {
if (prop.value && prop.value.type === 'Literal' || prop.type && prop.type === 'Literal') {
return prop.value.value !== undefined ? prop.value.value : prop.value;
} else if (prop.value && prop.value.type === 'TemplateLiteral' || prop.type && prop.type === 'TemplateLiteral') {
return prop.value.quasis.map(function (element) {
return element.value.cooked;
}).join('');
} else if (prop.value && prop.value.type === 'ObjectExpression' || prop.type && prop.type === 'ObjectExpression') {
return this.handleObjectExpression(prop.value.properties);
} else if (prop.value && prop.value.type === 'ArrayExpression' || prop.type && prop.type === 'ArrayExpression') {
return this.handleArrayExpression(prop.elements);
} else {
// Unable to get value of the property
return '';
}
} // i18next.t('ns:foo.bar') // matched

@@ -456,3 +514,3 @@ // i18next.t("ns:foo.bar") // matched

value: function parseFuncFromString(content) {
var _this2 = this;
var _this4 = this;

@@ -490,3 +548,3 @@ var opts = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};

var key = _this2.fixStringAfterRegExp(r[1], true);
var key = _this4.fixStringAfterRegExp(r[1], true);

@@ -498,3 +556,3 @@ if (!key) {

if (r[2] !== undefined) {
var defaultValue = _this2.fixStringAfterRegExp(r[2], false);
var defaultValue = _this4.fixStringAfterRegExp(r[2], false);

@@ -524,21 +582,12 @@ if (!defaultValue) {

var supportedOptions = ['defaultValue', 'defaultValue_plural', 'count', 'context', 'ns', 'keySeparator', 'nsSeparator'];
var supportedOptions = ['defaultValue', 'defaultValue_plural', 'count', 'context', 'ns', 'keySeparator', 'nsSeparator', 'metadata'];
props.forEach(function (prop) {
if (_lodash["default"].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(function (element) {
return element.value.cooked;
}).join('');
} else {
// Unable to get value of the property
options[prop.key.name] = '';
}
options[prop.key.name] = _this4.optionsBuilder(prop);
}
});
} catch (err) {
_this2.error("Unable to parse code \"".concat(code, "\""));
_this4.error("Unable to parse code \"".concat(code, "\""));
_this2.error(err);
_this4.error(err);
}

@@ -552,3 +601,3 @@ }

_this2.set(key, options);
_this4.set(key, options);
};

@@ -569,3 +618,3 @@

value: function parseTransFromString(content) {
var _this3 = this;
var _this5 = this;

@@ -679,3 +728,3 @@ var opts = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};

if (typeof defaultsString !== 'string') {
_this3.log("defaults value must be a static string, saw ".concat(_chalk["default"].yellow(defaultsString)));
_this5.log("defaults value must be a static string, saw ".concat(_chalk["default"].yellow(defaultsString)));
} // https://www.i18next.com/translation-function/essentials#overview-options

@@ -688,3 +737,3 @@

defaultValue: defaultsString || (0, _nodesToString["default"])(node.children, code),
fallbackKey: fallbackKey || _this3.options.trans.fallbackKey
fallbackKey: fallbackKey || _this5.options.trans.fallbackKey
});

@@ -698,3 +747,3 @@

if (typeof attr.ns !== 'string') {
_this3.log("The ns attribute must be a string, saw ".concat(_chalk["default"].yellow(attr.ns)));
_this5.log("The ns attribute must be a string, saw ".concat(_chalk["default"].yellow(attr.ns)));
}

@@ -710,3 +759,3 @@

_this3.set(transKey, options);
_this5.set(transKey, options);
};

@@ -811,3 +860,3 @@

value: function get(key) {
var _this4 = this;
var _this6 = this;

@@ -827,5 +876,5 @@ var opts = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};

Object.keys(this.resStore).forEach(function (lng) {
Object.keys(_this4.resStore[lng]).forEach(function (ns) {
var resStoreKeys = (0, _flattenObjectKeys["default"])(_lodash["default"].get(_this4.resStore, [lng, ns], {}));
var resScanKeys = (0, _flattenObjectKeys["default"])(_lodash["default"].get(_this4.resScan, [lng, ns], {}));
Object.keys(_this6.resStore[lng]).forEach(function (ns) {
var resStoreKeys = (0, _flattenObjectKeys["default"])(_lodash["default"].get(_this6.resStore, [lng, ns], {}));
var resScanKeys = (0, _flattenObjectKeys["default"])(_lodash["default"].get(_this6.resScan, [lng, ns], {}));

@@ -837,3 +886,3 @@ var unusedKeys = _lodash["default"].differenceWith(resStoreKeys, resScanKeys, _lodash["default"].isEqual);

_this4.log("Removed an unused translation key { ".concat(_chalk["default"].red(JSON.stringify(unusedKeys[i])), " from ").concat(_chalk["default"].red(JSON.stringify(_this4.formatResourceLoadPath(lng, ns)))));
_this6.log("Removed an unused translation key { ".concat(_chalk["default"].red(JSON.stringify(unusedKeys[i])), " from ").concat(_chalk["default"].red(JSON.stringify(_this6.formatResourceLoadPath(lng, ns)))));
} // Omit empty object

@@ -904,3 +953,3 @@

value: function set(key) {
var _this5 = this;
var _this7 = this;

@@ -968,8 +1017,8 @@ var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};

lngs.forEach(function (lng) {
var resLoad = _this5.resStore[lng] && _this5.resStore[lng][ns];
var resScan = _this5.resScan[lng] && _this5.resScan[lng][ns];
var resLoad = _this7.resStore[lng] && _this7.resStore[lng][ns];
var resScan = _this7.resScan[lng] && _this7.resScan[lng][ns];
if (!_lodash["default"].isPlainObject(resLoad)) {
// Skip undefined namespace
_this5.error("".concat(_chalk["default"].yellow(JSON.stringify(ns)), " does not exist in the namespaces (").concat(_chalk["default"].yellow(JSON.stringify(_this5.options.ns)), "): key=").concat(_chalk["default"].yellow(JSON.stringify(key)), ", options=").concat(_chalk["default"].yellow(JSON.stringify(options))));
_this7.error("".concat(_chalk["default"].yellow(JSON.stringify(ns)), " does not exist in the namespaces (").concat(_chalk["default"].yellow(JSON.stringify(_this7.options.ns)), "): key=").concat(_chalk["default"].yellow(JSON.stringify(key)), ", options=").concat(_chalk["default"].yellow(JSON.stringify(options))));

@@ -1047,3 +1096,3 @@ return;

if (containsPlural) {
var suffixes = pluralFallback ? _this5.pluralSuffixes[lng] : _this5.pluralSuffixes[lng].slice(1);
var suffixes = pluralFallback ? _this7.pluralSuffixes[lng] : _this7.pluralSuffixes[lng].slice(1);
suffixes.forEach(function (pluralSuffix) {

@@ -1081,3 +1130,3 @@ resKeys.push("".concat(key).concat(pluralSuffix));

_this5.log("Added a new translation key { ".concat(_chalk["default"].yellow(JSON.stringify(resKey)), ": ").concat(_chalk["default"].yellow(JSON.stringify(resLoad[resKey])), " } to ").concat(_chalk["default"].yellow(JSON.stringify(_this5.formatResourceLoadPath(lng, ns)))));
_this7.log("Added a new translation key { ".concat(_chalk["default"].yellow(JSON.stringify(resKey)), ": ").concat(_chalk["default"].yellow(JSON.stringify(resLoad[resKey])), " } to ").concat(_chalk["default"].yellow(JSON.stringify(_this7.formatResourceLoadPath(lng, ns)))));
} else if (options.defaultValue && (!options.defaultValue_plural || !resKey.endsWith("".concat(pluralSeparator, "plural")))) {

@@ -1089,3 +1138,3 @@ if (!resLoad[resKey]) {

// A default value has provided but it's different with the expected default
_this5.log("The translation key ".concat(_chalk["default"].yellow(JSON.stringify(resKey)), " has a different default value, you may need to check the translation key of default language (").concat(defaultLng, ")"));
_this7.log("The translation key ".concat(_chalk["default"].yellow(JSON.stringify(resKey)), " has a different default value, you may need to check the translation key of default language (").concat(defaultLng, ")"));
}

@@ -1098,3 +1147,3 @@ } else if (options.defaultValue_plural && resKey.endsWith("".concat(pluralSeparator, "plural"))) {

// A default value has provided but it's different with the expected default
_this5.log("The translation key ".concat(_chalk["default"].yellow(JSON.stringify(resKey)), " has a different default value, you may need to check the translation key of default language (").concat(defaultLng, ")"));
_this7.log("The translation key ".concat(_chalk["default"].yellow(JSON.stringify(resKey)), " has a different default value, you may need to check the translation key of default language (").concat(defaultLng, ")"));
}

@@ -1101,0 +1150,0 @@ }

{
"name": "i18next-scanner",
"version": "3.1.0",
"version": "3.2.0",
"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",

@@ -127,3 +127,3 @@ # i18next-scanner [![build status](https://travis-ci.org/i18next/i18next-scanner.svg?branch=master)](https://travis-ci.org/i18next/i18next-scanner) [![Coverage Status](https://coveralls.io/repos/i18next/i18next-scanner/badge.svg?branch=master&service=github)](https://coveralls.io/github/i18next/i18next-scanner?branch=master)

acorn: {
ecmaVersion: 10, // defaults to 10
ecmaVersion: 2020,
sourceType: 'module', // defaults to 'module'

@@ -187,3 +187,3 @@ // Check out https://github.com/acornjs/acorn/tree/master/acorn#interface for additional options

const parser = new Parser();
const content = '';
let content = '';

@@ -827,4 +827,10 @@ // Parse Translation Function

#### metadata
Type: `Object` Default: `{}`
This can be used to pass any additional information regarding the string.
## License
MIT
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