From e564190c64c9b18be7594fe30ece1c38d723ba3a Mon Sep 17 00:00:00 2001 From: kazuya kawaguchi Date: Sun, 26 Apr 2020 02:58:57 +0900 Subject: [PATCH] fix: alternative array includes closes #851 --- src/components/number.js | 4 ++-- src/index.js | 7 ++++--- src/util.js | 4 ++++ 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/src/components/number.js b/src/components/number.js index d0c139a03..a99030229 100644 --- a/src/components/number.js +++ b/src/components/number.js @@ -1,6 +1,6 @@ /* @flow */ -import { warn, isObject, numberFormatKeys } from '../util' +import { warn, isObject, includes, numberFormatKeys } from '../util' export default { name: 'i18n-n', @@ -43,7 +43,7 @@ export default { // Filter out number format options only options = Object.keys(props.format).reduce((acc, prop) => { - if (numberFormatKeys.includes(prop)) { + if (includes(numberFormatKeys, prop)) { return Object.assign({}, acc, { [prop]: props.format[prop] }) } return acc diff --git a/src/index.js b/src/index.js index 90b7f9a9b..e86418de4 100644 --- a/src/index.js +++ b/src/index.js @@ -10,6 +10,7 @@ import { isObject, looseClone, remove, + includes, merge, numberFormatKeys } from './util' @@ -398,7 +399,7 @@ export default class VueI18n { // Remove the leading @:, @.case: and the brackets const linkPlaceholder: string = link.replace(linkPrefix, '').replace(bracketsMatcher, '') - if (visitedLinkStack.includes(linkPlaceholder)) { + if (includes(visitedLinkStack, linkPlaceholder)) { if (process.env.NODE_ENV !== 'production') { warn(`Circular reference found. "${link}" is already visited in the chain of ${visitedLinkStack.reverse().join(' <- ')}`) } @@ -462,7 +463,7 @@ export default class VueI18n { _appendItemToChain (chain: Array, item: Locale, blocks: any): any { let follow = false - if (!chain.includes(item)) { + if (!includes(chain, item)) { follow = true if (item) { follow = item[item.length - 1] !== '!' @@ -931,7 +932,7 @@ export default class VueI18n { // Filter out number format options only options = Object.keys(args[0]).reduce((acc, key) => { - if (numberFormatKeys.includes(key)) { + if (includes(numberFormatKeys, key)) { return Object.assign({}, acc, { [key]: args[0][key] }) } return acc diff --git a/src/util.js b/src/util.js index 04c021edd..aa5e0f122 100644 --- a/src/util.js +++ b/src/util.js @@ -92,6 +92,10 @@ export function remove (arr: Array, item: any): Array | void { } } +export function includes (arr: Array, item: any): boolean { + return !!~arr.indexOf(item) +} + const hasOwnProperty = Object.prototype.hasOwnProperty export function hasOwn (obj: Object | Array<*>, key: string): boolean { return hasOwnProperty.call(obj, key)