Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: alternative array includes #857

Merged
merged 1 commit into from
Apr 25, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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