Skip to content

Commit

Permalink
Refactor code-style
Browse files Browse the repository at this point in the history
  • Loading branch information
wooorm committed May 9, 2021
1 parent 2fbfe3f commit 63f8688
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 15 deletions.
6 changes: 3 additions & 3 deletions build.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,12 @@ function onbody(doc) {
var match = []
var suffix = 'Alias'
var seenHeploc = false
var ignore = [
var ignore = new Set([
// Subdivisions (ISO 3166-2) are not used in BCP 47 tags.
'subdivision',
// Timezones.
'zone'
]
])

visit(fromXml(doc), 'element', onelement)

Expand Down Expand Up @@ -85,7 +85,7 @@ function onbody(doc) {
name = 'variants'
}

if (ignore.includes(name)) {
if (ignore.has(name)) {
return
}

Expand Down
16 changes: 8 additions & 8 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export function bcp47Normalize(value, options) {

// 2. Do fancy, expensive replaces (`ha-latn-gh` -> `ha-gh`).
while (++index < matches.length) {
if (extendedFilter(tag, matches[index].from).length) {
if (extendedFilter(tag, matches[index].from).length > 0) {
replace(schema, matches[index].from, matches[index].to)
tag = stringify(schema)
}
Expand Down Expand Up @@ -133,7 +133,7 @@ function replace(schema, from, to) {

// Remove values from `from`:
for (key in left) {
if (left[key] && left[key].length && remove(schema, key, left[key])) {
if (left[key] && left[key].length > 0 && remove(schema, key, left[key])) {
removed.push(key)
}
}
Expand All @@ -144,8 +144,8 @@ function replace(schema, from, to) {
// `from` or are currently empty.
if (
right[key] &&
right[key].length &&
(removed.indexOf(key) > -1 || !schema[key] || !schema[key].length)
right[key].length > 0 &&
(removed.includes(key) || !schema[key] || schema[key].length === 0)
) {
add(schema, key, right[key])
}
Expand Down Expand Up @@ -183,10 +183,10 @@ function remove(object, key, value) {
while (++index < current.length) {
item = current[index]

if (value.indexOf(item) < 0) {
result.push(item)
} else {
if (value.includes(item)) {
removed = true
} else {
result.push(item)
}
}
} else if (current === value) {
Expand Down Expand Up @@ -224,7 +224,7 @@ function add(object, key, value) {

/* istanbul ignore else - this currently can’t happen, but guard for the
* future. */
if (current.indexOf(item) < 0) {
if (!current.includes(item)) {
current.push(item)
}
}
Expand Down
4 changes: 0 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,6 @@
"xo": {
"prettier": true,
"rules": {
"unicorn/explicit-length-check": "off",
"unicorn/prefer-includes": "off",
"unicorn/prefer-number-properties": "off",
"unicorn/prefer-set-has": "off",
"no-var": "off",
"prefer-arrow-callback": "off"
}
Expand Down

0 comments on commit 63f8688

Please sign in to comment.