Skip to content
This repository has been archived by the owner on Dec 20, 2024. It is now read-only.

Commit

Permalink
Replace use of forEach() and Array#indexOf()
Browse files Browse the repository at this point in the history
  • Loading branch information
vweevers committed Apr 9, 2021
1 parent 73b19b4 commit e3ed6e4
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
11 changes: 6 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use strict'

const encodings = require('./lib/encodings')
const rangeOptions = new Set(['lt', 'gt', 'lte', 'gte'])

module.exports = Codec

Expand Down Expand Up @@ -62,19 +63,19 @@ Codec.prototype.encodeBatch = function (ops, opts) {
})
}

const ltgtKeys = ['lt', 'gt', 'lte', 'gte']

Codec.prototype.encodeLtgt = function (ltgt) {
const ret = {}
Object.keys(ltgt).forEach((key) => {

for (const key of Object.keys(ltgt)) {
if (key === 'start' || key === 'end') {
throw new Error('Legacy range options ("start" and "end") have been removed')
}

ret[key] = ltgtKeys.indexOf(key) > -1
ret[key] = rangeOptions.has(key)
? this.encodeKey(ltgt[key], ltgt)
: ltgt[key]
})
}

return ret
}

Expand Down
6 changes: 3 additions & 3 deletions lib/encodings.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict'

const Buffer = require('buffer').Buffer
const { Buffer } = require('buffer')

exports.utf8 = exports['utf-8'] = {
encode: function (data) {
Expand Down Expand Up @@ -46,7 +46,7 @@ const bufferEncodings = [
'utf-16le'
]

bufferEncodings.forEach(function (type) {
for (const type of bufferEncodings) {
exports[type] = {
encode: function (data) {
return isBinary(data) ? data : Buffer.from(data, type)
Expand All @@ -57,7 +57,7 @@ bufferEncodings.forEach(function (type) {
buffer: true,
type: type
}
})
}

function identity (value) {
return value
Expand Down

0 comments on commit e3ed6e4

Please sign in to comment.