i18next-scanner
Advanced tools
Comparing version 4.5.0 to 4.6.0
@@ -26,9 +26,9 @@ "use strict"; | ||
// | ||
var flattenObjectKeys = function flattenObjectKeys(obj) { | ||
var _flattenObjectKeys = function flattenObjectKeys(obj) { | ||
var keys = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : []; | ||
return Object.keys(obj).reduce(function (acc, key) { | ||
var o = (0, _isPlainObject["default"])(obj[key]) && Object.keys(obj[key]).length > 0 || Array.isArray(obj[key]) && obj[key].length > 0 ? flattenObjectKeys(obj[key], keys.concat(key)) : [keys.concat(key)]; | ||
var o = (0, _isPlainObject["default"])(obj[key]) && Object.keys(obj[key]).length > 0 || Array.isArray(obj[key]) && obj[key].length > 0 ? _flattenObjectKeys(obj[key], keys.concat(key)) : [keys.concat(key)]; | ||
return acc.concat(o); | ||
}, []); | ||
}; | ||
var _default = exports["default"] = flattenObjectKeys; | ||
var _default = exports["default"] = _flattenObjectKeys; |
@@ -40,3 +40,3 @@ "use strict"; | ||
var nodesToString = function nodesToString(nodes, options) { | ||
var _nodesToString = function nodesToString(nodes, options) { | ||
var supportBasicHtmlNodes = (0, _ensureType.ensureBoolean)(options === null || options === void 0 ? void 0 : options.supportBasicHtmlNodes); | ||
@@ -99,6 +99,6 @@ var keepBasicHtmlNodesFor = (0, _ensureType.ensureArray)(options === null || options === void 0 ? void 0 : options.keepBasicHtmlNodesFor); | ||
// expected e.g. dolor <strong>bold</strong> amet | ||
memo += "<".concat(nodeType, ">").concat(nodesToString(node.children, options), "</").concat(nodeType, ">"); | ||
memo += "<".concat(nodeType, ">").concat(_nodesToString(node.children, options), "</").concat(nodeType, ">"); | ||
} else { | ||
// regular case mapping the inner children | ||
memo += "<".concat(nodeIndex, ">").concat(nodesToString(node.children, options), "</").concat(nodeIndex, ">"); | ||
memo += "<".concat(nodeIndex, ">").concat(_nodesToString(node.children, options), "</").concat(nodeIndex, ">"); | ||
} | ||
@@ -109,2 +109,2 @@ } | ||
}; | ||
var _default = exports["default"] = nodesToString; | ||
var _default = exports["default"] = _nodesToString; |
@@ -24,3 +24,3 @@ "use strict"; | ||
// | ||
var unsetEmptyObject = function unsetEmptyObject(obj) { | ||
var _unsetEmptyObject = function unsetEmptyObject(obj) { | ||
Object.keys(obj).forEach(function (key) { | ||
@@ -30,3 +30,3 @@ if (!(0, _isPlainObject["default"])(obj[key])) { | ||
} | ||
unsetEmptyObject(obj[key]); | ||
_unsetEmptyObject(obj[key]); | ||
if ((0, _isPlainObject["default"])(obj[key]) && Object.keys(obj[key]).length === 0) { | ||
@@ -40,4 +40,4 @@ obj[key] = undefined; | ||
var omitEmptyObject = function omitEmptyObject(obj) { | ||
return unsetEmptyObject((0, _cloneDeep["default"])(obj)); | ||
return _unsetEmptyObject((0, _cloneDeep["default"])(obj)); | ||
}; | ||
var _default = exports["default"] = omitEmptyObject; |
@@ -29,4 +29,4 @@ "use strict"; | ||
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); } | ||
function _objectWithoutProperties(e, t) { if (null == e) return {}; var o, r, i = _objectWithoutPropertiesLoose(e, t); if (Object.getOwnPropertySymbols) { var n = Object.getOwnPropertySymbols(e); for (r = 0; r < n.length; r++) o = n[r], t.indexOf(o) >= 0 || {}.propertyIsEnumerable.call(e, o) && (i[o] = e[o]); } return i; } | ||
function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (e.indexOf(n) >= 0) continue; t[n] = r[n]; } return t; } | ||
function _objectWithoutProperties(e, t) { if (null == e) return {}; var o, r, i = _objectWithoutPropertiesLoose(e, t); if (Object.getOwnPropertySymbols) { var s = Object.getOwnPropertySymbols(e); for (r = 0; r < s.length; r++) o = s[r], t.includes(o) || {}.propertyIsEnumerable.call(e, o) && (i[o] = e[o]); } return i; } | ||
function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (e.includes(n)) continue; t[n] = r[n]; } return t; } | ||
function _createForOfIteratorHelper(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (!t) { if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) { t && (r = t); var _n = 0, F = function F() {}; return { s: F, n: function n() { return _n >= r.length ? { done: !0 } : { done: !1, value: r[_n++] }; }, e: function e(r) { throw r; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var o, a = !0, u = !1; return { s: function s() { t = t.call(r); }, n: function n() { var r = t.next(); return a = r.done, r; }, e: function e(r) { u = !0, o = r; }, f: function f() { try { a || null == t["return"] || t["return"](); } finally { if (u) throw o; } } }; } | ||
@@ -735,3 +735,3 @@ function _toConsumableArray(r) { return _arrayWithoutHoles(r) || _iterableToArray(r) || _unsupportedIterableToArray(r) || _nonIterableSpread(); } | ||
}; | ||
var walk = function walk(nodes) { | ||
var _walk = function walk(nodes) { | ||
nodes.forEach(function (node) { | ||
@@ -747,10 +747,10 @@ if (node.attrs) { | ||
if (node.childNodes) { | ||
walk(node.childNodes); | ||
_walk(node.childNodes); | ||
} | ||
if (node.content && node.content.childNodes) { | ||
walk(node.content.childNodes); | ||
_walk(node.content.childNodes); | ||
} | ||
}); | ||
}; | ||
walk(ast.childNodes); | ||
_walk(ast.childNodes); | ||
return this; | ||
@@ -775,3 +775,3 @@ } | ||
var resStore = {}; | ||
if (this.options.removeUnusedKeys) { | ||
if (!!this.options.removeUnusedKeys) { | ||
// Merge two objects `resStore` and `resScan` deeply, returning a new merged object with the elements from both `resStore` and `resScan`. | ||
@@ -790,4 +790,8 @@ var overwriteMerge = function overwriteMerge(destinationArray, sourceArray, options) { | ||
for (var i = 0; i < unusedKeys.length; ++i) { | ||
_lodash["default"].unset(resMerged[lng][ns], unusedKeys[i]); | ||
_this7.log("Removed an unused translation key { ".concat(_chalk["default"].red(JSON.stringify(unusedKeys[i])), " from ").concat(_chalk["default"].red(JSON.stringify(_this7.formatResourceLoadPath(lng, ns))))); | ||
var unusedKey = unusedKeys[i]; | ||
var isRemovable = typeof _this7.options.removeUnusedKeys === 'function' ? _this7.options.removeUnusedKeys(lng, ns, unusedKey) : !!_this7.options.removeUnusedKeys; | ||
if (isRemovable) { | ||
_lodash["default"].unset(resMerged[lng][ns], unusedKey); | ||
_this7.log("Removed an unused translation key { ".concat(_chalk["default"].red(JSON.stringify(unusedKey)), " } from ").concat(_chalk["default"].red(JSON.stringify(_this7.formatResourceLoadPath(lng, ns))))); | ||
} | ||
} | ||
@@ -794,0 +798,0 @@ |
{ | ||
"name": "i18next-scanner", | ||
"version": "4.5.0", | ||
"version": "4.6.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", |
@@ -573,6 +573,27 @@ # 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) | ||
Type: `Boolean` Default: `false` | ||
Type: `Boolean` or `Function` Default: `false` | ||
Set to `true` to remove unused translation keys from i18n resource files. | ||
Set to `true` to remove unused translation keys from i18n resource files. By default, this is set to `false`. | ||
```js | ||
{ // Default | ||
removeUnusedKeys: false, | ||
} | ||
``` | ||
If a function is provided, it will be used to decide whether an unused translation key should be removed. | ||
```js | ||
// Available since 4.6.0 | ||
// | ||
// @param {string} lng The language of the unused translation key. | ||
// @param {string} ns The namespace of the unused translation key. | ||
// @param {array} key The translation key in its array form. | ||
// @return {boolean} Returns true if the unused translation key should be removed. | ||
removeUnusedKeys: function(lng, ns, key) { | ||
if (ns === 'resource') { | ||
return true; | ||
} | ||
return false; | ||
} | ||
``` | ||
#### sort | ||
@@ -598,3 +619,3 @@ | ||
You can set attr to `false` to disable parsing attribute as below: | ||
You can set `attr` to `false` to disable parsing attribute as below: | ||
```js | ||
@@ -620,3 +641,3 @@ { | ||
You can set func to `false` to disable parsing translation function as below: | ||
You can set `func` to `false` to disable parsing translation function as below: | ||
```js | ||
@@ -655,3 +676,3 @@ { | ||
You can set trans to `false` to disable parsing Trans component as below: | ||
You can set `trans` to `false` to disable parsing Trans component as below: | ||
```js | ||
@@ -663,3 +684,3 @@ { | ||
The fallbackKey can either be a boolean value, or a function like so: | ||
The `fallbackKey` can either be a boolean value, or a function like so: | ||
```js | ||
@@ -666,0 +687,0 @@ fallbackKey: function(ns, value) { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
101114
1438
951