Skip to content

Commit

Permalink
fix: alternative array includes (#857)
Browse files Browse the repository at this point in the history
closes #851
  • Loading branch information
kazupon committed Apr 25, 2020
1 parent 6e70740 commit dea111b
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/components/number.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* @flow */

import { warn, isObject, numberFormatKeys } from '../util'
import { warn, isObject, includes, numberFormatKeys } from '../util'

export default {
name: 'i18n-n',
Expand Down Expand Up @@ -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
Expand Down
7 changes: 4 additions & 3 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
isObject,
looseClone,
remove,
includes,
merge,
numberFormatKeys
} from './util'
Expand Down Expand Up @@ -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(' <- ')}`)
}
Expand Down Expand Up @@ -462,7 +463,7 @@ export default class VueI18n {

_appendItemToChain (chain: Array<Locale>, 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] !== '!'
Expand Down Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions src/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,10 @@ export function remove (arr: Array<any>, item: any): Array<any> | void {
}
}

export function includes (arr: Array<any>, 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)
Expand Down

0 comments on commit dea111b

Please sign in to comment.