From 0ee8ade175b76b53899023ba13d0157d42df9030 Mon Sep 17 00:00:00 2001 From: Kirill Fomichev Date: Sat, 16 Apr 2016 18:25:19 +0300 Subject: [PATCH] indexOf instead switch/case --- index.js | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/index.js b/index.js index 2e44a03..3c2b502 100644 --- a/index.js +++ b/index.js @@ -21,12 +21,10 @@ var Buffer = require('buffer').Buffer; +var bufferEncodings = ['hex', 'utf8', 'utf-8', 'ascii', 'binary', 'base64', 'ucs2', 'ucs-2', 'utf16le', 'utf-16le', 'raw'] var isBufferEncoding = Buffer.isEncoding || function(encoding) { - switch (encoding && encoding.toLowerCase()) { - case 'hex': case 'utf8': case 'utf-8': case 'ascii': case 'binary': case 'base64': case 'ucs2': case 'ucs-2': case 'utf16le': case 'utf-16le': case 'raw': return true; - default: return false; - } + return bufferEncodings.indexOf(encoding.toLowerCase()) !== -1 }