From 63684ad65a06d62e423d558934c2456214a6f002 Mon Sep 17 00:00:00 2001 From: Sam Verschueren Date: Wed, 28 Jun 2017 19:44:04 +0200 Subject: [PATCH] add support for older node versions --- .travis.yml | 3 +++ index.js | 24 ++++++++++++------------ package.json | 6 +++--- test.js | 4 ++-- 4 files changed, 20 insertions(+), 17 deletions(-) diff --git a/.travis.yml b/.travis.yml index 2addbdd..23875fc 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,9 @@ language: node_js node_js: + - '8' - '6' - '4' + - '0.12' + - '0.10' after_script: - npm run coveralls diff --git a/index.js b/index.js index fac9f01..1944683 100644 --- a/index.js +++ b/index.js @@ -1,7 +1,7 @@ 'use strict'; -const token = '%[a-f0-9]{2}'; -const singleMatcher = new RegExp(token, 'gi'); -const multiMatcher = new RegExp(`(${token})+`, 'gi'); +var token = '%[a-f0-9]{2}'; +var singleMatcher = new RegExp(token, 'gi'); +var multiMatcher = new RegExp(`(${token})+`, 'gi'); function decodeComponents(components, split) { try { @@ -18,8 +18,8 @@ function decodeComponents(components, split) { split = split || 1; // Split the array in 2 parts - const left = components.slice(0, split); - const right = components.slice(split); + var left = components.slice(0, split); + var right = components.slice(split); return Array.prototype.concat.call([], decodeComponents(left), decodeComponents(right)); } @@ -28,9 +28,9 @@ function decode(input) { try { return decodeURIComponent(input); } catch (err) { - let tokens = input.match(singleMatcher); + var tokens = input.match(singleMatcher); - for (let i = 1; i < tokens.length; i++) { + for (var i = 1; i < tokens.length; i++) { input = decodeComponents(tokens, i).join(''); tokens = input.match(singleMatcher); @@ -42,18 +42,18 @@ function decode(input) { function customDecodeURIComponent(input) { // Keep track of all the replacements and prefill the map with the `BOM` - const replaceMap = new Map([ + var replaceMap = new Map([ ['%FE%FF', '\uFFFD\uFFFD'], ['%FF%FE', '\uFFFD\uFFFD'] ]); - let match = multiMatcher.exec(input); + var match = multiMatcher.exec(input); while (match) { try { // Decode as big chunks as possible replaceMap.set(match[0], decodeURIComponent(match[0])); } catch (err) { - const result = decode(match[0]); + var result = decode(match[0]); if (result !== match[0]) { replaceMap.set(match[0], result); @@ -66,7 +66,7 @@ function customDecodeURIComponent(input) { // Add `%C2` at the end of the map to make sure it does not replace the combinator before everything else replaceMap.set('%C2', '\uFFFD'); - for (const entry of replaceMap.entries()) { + for (var entry of replaceMap.entries()) { // Replace all decoded components input = input.replace(new RegExp(entry[0], 'g'), entry[1]); } @@ -74,7 +74,7 @@ function customDecodeURIComponent(input) { return input; } -module.exports = encodedURI => { +module.exports = function (encodedURI) { if (typeof encodedURI !== 'string') { throw new TypeError(`Expected \`encodedURI\` to be of type \`string\`, got \`${typeof encodedURI}\``); } diff --git a/package.json b/package.json index ad5984b..cbdfab9 100644 --- a/package.json +++ b/package.json @@ -10,7 +10,7 @@ "url": "github.com/SamVerschueren" }, "engines": { - "node": ">=4" + "node": ">=0.10" }, "scripts": { "test": "xo && nyc ava", @@ -29,9 +29,9 @@ "url" ], "devDependencies": { - "ava": "*", + "ava": "^0.17.0", "coveralls": "^2.13.1", "nyc": "^10.3.2", - "xo": "*" + "xo": "^0.16.0" } } diff --git a/test.js b/test.js index 5ff2b0a..85adb1d 100644 --- a/test.js +++ b/test.js @@ -1,8 +1,8 @@ import test from 'ava'; -import m from '.'; +import m from './'; const tests = { - test: 'test', + 'test': 'test', 'a+b': 'a b', 'a+b+c+d': 'a b c d', '=a': '=a',