Comparing version 1.0.1 to 1.0.2
@@ -247,306 +247,86 @@ /** | ||
var strictUriEncode = str => encodeURIComponent(str).replace(/[!'()*]/g, x => `%${x.charCodeAt(0).toString(16).toUpperCase()}`); | ||
var strictUriEncode = function (str) { | ||
return encodeURIComponent(str).replace(/[!'()*]/g, function (c) { | ||
return '%' + c.charCodeAt(0).toString(16).toUpperCase(); | ||
}); | ||
}; | ||
var token = '%[a-f0-9]{2}'; | ||
var singleMatcher = new RegExp(token, 'gi'); | ||
var multiMatcher = new RegExp('(' + token + ')+', 'gi'); | ||
function decodeComponents(components, split) { | ||
try { | ||
// Try to decode the entire string first | ||
return decodeURIComponent(components.join('')); | ||
} catch (err) { | ||
// Do nothing | ||
} | ||
if (components.length === 1) { | ||
return components; | ||
} | ||
split = split || 1; | ||
// Split the array in 2 parts | ||
var left = components.slice(0, split); | ||
var right = components.slice(split); | ||
return Array.prototype.concat.call([], decodeComponents(left), decodeComponents(right)); | ||
function encode(value, strict) { | ||
return strict ? strictUriEncode(value) : encodeURIComponent(value); | ||
} | ||
function decode(input) { | ||
try { | ||
return decodeURIComponent(input); | ||
} catch (err) { | ||
var tokens = input.match(singleMatcher); | ||
for (var i = 1; i < tokens.length; i++) { | ||
input = decodeComponents(tokens, i).join(''); | ||
tokens = input.match(singleMatcher); | ||
} | ||
return input; | ||
} | ||
} | ||
function customDecodeURIComponent(input) { | ||
// Keep track of all the replacements and prefill the map with the `BOM` | ||
var replaceMap = { | ||
'%FE%FF': '\uFFFD\uFFFD', | ||
'%FF%FE': '\uFFFD\uFFFD' | ||
}; | ||
var match = multiMatcher.exec(input); | ||
while (match) { | ||
try { | ||
// Decode as big chunks as possible | ||
replaceMap[match[0]] = decodeURIComponent(match[0]); | ||
} catch (err) { | ||
var result = decode(match[0]); | ||
if (result !== match[0]) { | ||
replaceMap[match[0]] = result; | ||
} | ||
} | ||
match = multiMatcher.exec(input); | ||
} | ||
// Add `%C2` at the end of the map to make sure it does not replace the combinator before everything else | ||
replaceMap['%C2'] = '\uFFFD'; | ||
var entries = Object.keys(replaceMap); | ||
for (var i = 0; i < entries.length; i++) { | ||
// Replace all decoded components | ||
var key = entries[i]; | ||
input = input.replace(new RegExp(key, 'g'), replaceMap[key]); | ||
} | ||
return input; | ||
} | ||
var decodeUriComponent = function (encodedURI) { | ||
if (typeof encodedURI !== 'string') { | ||
throw new TypeError('Expected `encodedURI` to be of type `string`, got `' + typeof encodedURI + '`'); | ||
} | ||
try { | ||
encodedURI = encodedURI.replace(/\+/g, ' '); | ||
// Try the built in decoder first | ||
return decodeURIComponent(encodedURI); | ||
} catch (err) { | ||
// Fallback to a more advanced decoder | ||
return customDecodeURIComponent(encodedURI); | ||
} | ||
var extract = function (str) { | ||
return str.split('?')[1] || ''; | ||
}; | ||
function encoderForArrayFormat(options) { | ||
switch (options.arrayFormat) { | ||
case 'index': | ||
return (key, value, index) => { | ||
return value === null ? [ | ||
encode(key, options), | ||
'[', | ||
index, | ||
']' | ||
].join('') : [ | ||
encode(key, options), | ||
'[', | ||
encode(index, options), | ||
']=', | ||
encode(value, options) | ||
].join(''); | ||
}; | ||
case 'bracket': | ||
return (key, value) => { | ||
return value === null ? [encode(key, options), '[]'].join('') : [ | ||
encode(key, options), | ||
'[]=', | ||
encode(value, options) | ||
].join(''); | ||
}; | ||
default: | ||
return (key, value) => { | ||
return value === null ? encode(key, options) : [ | ||
encode(key, options), | ||
'=', | ||
encode(value, options) | ||
].join(''); | ||
}; | ||
} | ||
} | ||
function parserForArrayFormat(options) { | ||
let result; | ||
switch (options.arrayFormat) { | ||
case 'index': | ||
return (key, value, accumulator) => { | ||
result = /\[(\d*)\]$/.exec(key); | ||
key = key.replace(/\[\d*\]$/, ''); | ||
if (!result) { | ||
accumulator[key] = value; | ||
return; | ||
} | ||
if (accumulator[key] === undefined) { | ||
accumulator[key] = {}; | ||
} | ||
accumulator[key][result[1]] = value; | ||
}; | ||
case 'bracket': | ||
return (key, value, accumulator) => { | ||
result = /(\[\])$/.exec(key); | ||
key = key.replace(/\[\]$/, ''); | ||
if (!result) { | ||
accumulator[key] = value; | ||
return; | ||
} | ||
if (accumulator[key] === undefined) { | ||
accumulator[key] = [value]; | ||
return; | ||
} | ||
accumulator[key] = [].concat(accumulator[key], value); | ||
}; | ||
default: | ||
return (key, value, accumulator) => { | ||
if (accumulator[key] === undefined) { | ||
accumulator[key] = value; | ||
return; | ||
} | ||
accumulator[key] = [].concat(accumulator[key], value); | ||
}; | ||
} | ||
} | ||
function encode(value, options) { | ||
if (options.encode) { | ||
return options.strict ? strictUriEncode(value) : encodeURIComponent(value); | ||
} | ||
return value; | ||
} | ||
function decode$1(value, options) { | ||
if (options.decode) { | ||
return decodeUriComponent(value); | ||
} | ||
return value; | ||
} | ||
function keysSorter(input) { | ||
if (Array.isArray(input)) { | ||
return input.sort(); | ||
} | ||
if (typeof input === 'object') { | ||
return keysSorter(Object.keys(input)) | ||
.sort((a, b) => Number(a) - Number(b)) | ||
.map(key => input[key]); | ||
} | ||
return input; | ||
} | ||
function extract(input) { | ||
const queryStart = input.indexOf('?'); | ||
if (queryStart === -1) { | ||
return ''; | ||
} | ||
return input.slice(queryStart + 1); | ||
} | ||
function parse(input, options) { | ||
options = Object.assign({decode: true, arrayFormat: 'none'}, options); | ||
const formatter = parserForArrayFormat(options); | ||
var parse = function (str) { | ||
// Create an object with no prototype | ||
const ret = Object.create(null); | ||
// https://github.com/sindresorhus/query-string/issues/47 | ||
var ret = Object.create(null); | ||
if (typeof input !== 'string') { | ||
if (typeof str !== 'string') { | ||
return ret; | ||
} | ||
input = input.trim().replace(/^[?#&]/, ''); | ||
str = str.trim().replace(/^(\?|#|&)/, ''); | ||
if (!input) { | ||
if (!str) { | ||
return ret; | ||
} | ||
for (const param of input.split('&')) { | ||
let [key, value] = param.replace(/\+/g, ' ').split('='); | ||
str.split('&').forEach(function (param) { | ||
var parts = param.replace(/\+/g, ' ').split('='); | ||
// Firefox (pre 40) decodes `%3D` to `=` | ||
// https://github.com/sindresorhus/query-string/pull/37 | ||
var key = parts.shift(); | ||
var val = parts.length > 0 ? parts.join('=') : undefined; | ||
// Missing `=` should be `null`: | ||
key = decodeURIComponent(key); | ||
// missing `=` should be `null`: | ||
// http://w3.org/TR/2012/WD-url-20120524/#collect-url-parameters | ||
value = value === undefined ? null : decode$1(value, options); | ||
val = val === undefined ? null : decodeURIComponent(val); | ||
formatter(decode$1(key, options), value, ret); | ||
} | ||
return Object.keys(ret).sort().reduce((result, key) => { | ||
const value = ret[key]; | ||
if (Boolean(value) && typeof value === 'object' && !Array.isArray(value)) { | ||
// Sort object keys, not values | ||
result[key] = keysSorter(value); | ||
if (ret[key] === undefined) { | ||
ret[key] = val; | ||
} else if (Array.isArray(ret[key])) { | ||
ret[key].push(val); | ||
} else { | ||
result[key] = value; | ||
ret[key] = [ret[key], val]; | ||
} | ||
}); | ||
return result; | ||
}, Object.create(null)); | ||
} | ||
return ret; | ||
}; | ||
var extract_1 = extract; | ||
var parse_1 = parse; | ||
var stringify = function (obj, opts) { | ||
opts = opts || {}; | ||
var stringify = (obj, options) => { | ||
if (!obj) { | ||
return ''; | ||
} | ||
var strict = opts.strict !== false; | ||
options = Object.assign({ | ||
encode: true, | ||
strict: true, | ||
arrayFormat: 'none' | ||
}, options); | ||
return obj ? Object.keys(obj).sort().map(function (key) { | ||
var val = obj[key]; | ||
const formatter = encoderForArrayFormat(options); | ||
const keys = Object.keys(obj); | ||
if (options.sort !== false) { | ||
keys.sort(options.sort); | ||
} | ||
return keys.map(key => { | ||
const value = obj[key]; | ||
if (value === undefined) { | ||
if (val === undefined) { | ||
return ''; | ||
} | ||
if (value === null) { | ||
return encode(key, options); | ||
if (val === null) { | ||
return key; | ||
} | ||
if (Array.isArray(value)) { | ||
const result = []; | ||
if (Array.isArray(val)) { | ||
var result = []; | ||
for (const value2 of value.slice()) { | ||
if (value2 === undefined) { | ||
continue; | ||
val.slice().sort().forEach(function (val2) { | ||
if (val2 === undefined) { | ||
return; | ||
} | ||
result.push(formatter(key, value2, result.length)); | ||
} | ||
if (val2 === null) { | ||
result.push(encode(key, strict)); | ||
} else { | ||
result.push(encode(key, strict) + '=' + encode(val2, strict)); | ||
} | ||
}); | ||
@@ -556,23 +336,12 @@ return result.join('&'); | ||
return encode(key, options) + '=' + encode(value, options); | ||
}).filter(x => x.length > 0).join('&'); | ||
return encode(key, strict) + '=' + encode(val, strict); | ||
}).filter(function (x) { | ||
return x.length > 0; | ||
}).join('&') : ''; | ||
}; | ||
var parseUrl = (input, options) => { | ||
const hashStart = input.indexOf('#'); | ||
if (hashStart !== -1) { | ||
input = input.slice(0, hashStart); | ||
} | ||
return { | ||
url: input.split('?')[0] || '', | ||
query: parse(extract(input), options) | ||
}; | ||
}; | ||
var queryString = { | ||
extract: extract_1, | ||
parse: parse_1, | ||
stringify: stringify, | ||
parseUrl: parseUrl | ||
extract: extract, | ||
parse: parse, | ||
stringify: stringify | ||
}; | ||
@@ -579,0 +348,0 @@ |
@@ -249,306 +249,86 @@ 'use strict'; | ||
var strictUriEncode = str => encodeURIComponent(str).replace(/[!'()*]/g, x => `%${x.charCodeAt(0).toString(16).toUpperCase()}`); | ||
var strictUriEncode = function (str) { | ||
return encodeURIComponent(str).replace(/[!'()*]/g, function (c) { | ||
return '%' + c.charCodeAt(0).toString(16).toUpperCase(); | ||
}); | ||
}; | ||
var token = '%[a-f0-9]{2}'; | ||
var singleMatcher = new RegExp(token, 'gi'); | ||
var multiMatcher = new RegExp('(' + token + ')+', 'gi'); | ||
function decodeComponents(components, split) { | ||
try { | ||
// Try to decode the entire string first | ||
return decodeURIComponent(components.join('')); | ||
} catch (err) { | ||
// Do nothing | ||
} | ||
if (components.length === 1) { | ||
return components; | ||
} | ||
split = split || 1; | ||
// Split the array in 2 parts | ||
var left = components.slice(0, split); | ||
var right = components.slice(split); | ||
return Array.prototype.concat.call([], decodeComponents(left), decodeComponents(right)); | ||
function encode(value, strict) { | ||
return strict ? strictUriEncode(value) : encodeURIComponent(value); | ||
} | ||
function decode(input) { | ||
try { | ||
return decodeURIComponent(input); | ||
} catch (err) { | ||
var tokens = input.match(singleMatcher); | ||
for (var i = 1; i < tokens.length; i++) { | ||
input = decodeComponents(tokens, i).join(''); | ||
tokens = input.match(singleMatcher); | ||
} | ||
return input; | ||
} | ||
} | ||
function customDecodeURIComponent(input) { | ||
// Keep track of all the replacements and prefill the map with the `BOM` | ||
var replaceMap = { | ||
'%FE%FF': '\uFFFD\uFFFD', | ||
'%FF%FE': '\uFFFD\uFFFD' | ||
}; | ||
var match = multiMatcher.exec(input); | ||
while (match) { | ||
try { | ||
// Decode as big chunks as possible | ||
replaceMap[match[0]] = decodeURIComponent(match[0]); | ||
} catch (err) { | ||
var result = decode(match[0]); | ||
if (result !== match[0]) { | ||
replaceMap[match[0]] = result; | ||
} | ||
} | ||
match = multiMatcher.exec(input); | ||
} | ||
// Add `%C2` at the end of the map to make sure it does not replace the combinator before everything else | ||
replaceMap['%C2'] = '\uFFFD'; | ||
var entries = Object.keys(replaceMap); | ||
for (var i = 0; i < entries.length; i++) { | ||
// Replace all decoded components | ||
var key = entries[i]; | ||
input = input.replace(new RegExp(key, 'g'), replaceMap[key]); | ||
} | ||
return input; | ||
} | ||
var decodeUriComponent = function (encodedURI) { | ||
if (typeof encodedURI !== 'string') { | ||
throw new TypeError('Expected `encodedURI` to be of type `string`, got `' + typeof encodedURI + '`'); | ||
} | ||
try { | ||
encodedURI = encodedURI.replace(/\+/g, ' '); | ||
// Try the built in decoder first | ||
return decodeURIComponent(encodedURI); | ||
} catch (err) { | ||
// Fallback to a more advanced decoder | ||
return customDecodeURIComponent(encodedURI); | ||
} | ||
var extract = function (str) { | ||
return str.split('?')[1] || ''; | ||
}; | ||
function encoderForArrayFormat(options) { | ||
switch (options.arrayFormat) { | ||
case 'index': | ||
return (key, value, index) => { | ||
return value === null ? [ | ||
encode(key, options), | ||
'[', | ||
index, | ||
']' | ||
].join('') : [ | ||
encode(key, options), | ||
'[', | ||
encode(index, options), | ||
']=', | ||
encode(value, options) | ||
].join(''); | ||
}; | ||
case 'bracket': | ||
return (key, value) => { | ||
return value === null ? [encode(key, options), '[]'].join('') : [ | ||
encode(key, options), | ||
'[]=', | ||
encode(value, options) | ||
].join(''); | ||
}; | ||
default: | ||
return (key, value) => { | ||
return value === null ? encode(key, options) : [ | ||
encode(key, options), | ||
'=', | ||
encode(value, options) | ||
].join(''); | ||
}; | ||
} | ||
} | ||
function parserForArrayFormat(options) { | ||
let result; | ||
switch (options.arrayFormat) { | ||
case 'index': | ||
return (key, value, accumulator) => { | ||
result = /\[(\d*)\]$/.exec(key); | ||
key = key.replace(/\[\d*\]$/, ''); | ||
if (!result) { | ||
accumulator[key] = value; | ||
return; | ||
} | ||
if (accumulator[key] === undefined) { | ||
accumulator[key] = {}; | ||
} | ||
accumulator[key][result[1]] = value; | ||
}; | ||
case 'bracket': | ||
return (key, value, accumulator) => { | ||
result = /(\[\])$/.exec(key); | ||
key = key.replace(/\[\]$/, ''); | ||
if (!result) { | ||
accumulator[key] = value; | ||
return; | ||
} | ||
if (accumulator[key] === undefined) { | ||
accumulator[key] = [value]; | ||
return; | ||
} | ||
accumulator[key] = [].concat(accumulator[key], value); | ||
}; | ||
default: | ||
return (key, value, accumulator) => { | ||
if (accumulator[key] === undefined) { | ||
accumulator[key] = value; | ||
return; | ||
} | ||
accumulator[key] = [].concat(accumulator[key], value); | ||
}; | ||
} | ||
} | ||
function encode(value, options) { | ||
if (options.encode) { | ||
return options.strict ? strictUriEncode(value) : encodeURIComponent(value); | ||
} | ||
return value; | ||
} | ||
function decode$1(value, options) { | ||
if (options.decode) { | ||
return decodeUriComponent(value); | ||
} | ||
return value; | ||
} | ||
function keysSorter(input) { | ||
if (Array.isArray(input)) { | ||
return input.sort(); | ||
} | ||
if (typeof input === 'object') { | ||
return keysSorter(Object.keys(input)) | ||
.sort((a, b) => Number(a) - Number(b)) | ||
.map(key => input[key]); | ||
} | ||
return input; | ||
} | ||
function extract(input) { | ||
const queryStart = input.indexOf('?'); | ||
if (queryStart === -1) { | ||
return ''; | ||
} | ||
return input.slice(queryStart + 1); | ||
} | ||
function parse(input, options) { | ||
options = Object.assign({decode: true, arrayFormat: 'none'}, options); | ||
const formatter = parserForArrayFormat(options); | ||
var parse = function (str) { | ||
// Create an object with no prototype | ||
const ret = Object.create(null); | ||
// https://github.com/sindresorhus/query-string/issues/47 | ||
var ret = Object.create(null); | ||
if (typeof input !== 'string') { | ||
if (typeof str !== 'string') { | ||
return ret; | ||
} | ||
input = input.trim().replace(/^[?#&]/, ''); | ||
str = str.trim().replace(/^(\?|#|&)/, ''); | ||
if (!input) { | ||
if (!str) { | ||
return ret; | ||
} | ||
for (const param of input.split('&')) { | ||
let [key, value] = param.replace(/\+/g, ' ').split('='); | ||
str.split('&').forEach(function (param) { | ||
var parts = param.replace(/\+/g, ' ').split('='); | ||
// Firefox (pre 40) decodes `%3D` to `=` | ||
// https://github.com/sindresorhus/query-string/pull/37 | ||
var key = parts.shift(); | ||
var val = parts.length > 0 ? parts.join('=') : undefined; | ||
// Missing `=` should be `null`: | ||
key = decodeURIComponent(key); | ||
// missing `=` should be `null`: | ||
// http://w3.org/TR/2012/WD-url-20120524/#collect-url-parameters | ||
value = value === undefined ? null : decode$1(value, options); | ||
val = val === undefined ? null : decodeURIComponent(val); | ||
formatter(decode$1(key, options), value, ret); | ||
} | ||
return Object.keys(ret).sort().reduce((result, key) => { | ||
const value = ret[key]; | ||
if (Boolean(value) && typeof value === 'object' && !Array.isArray(value)) { | ||
// Sort object keys, not values | ||
result[key] = keysSorter(value); | ||
if (ret[key] === undefined) { | ||
ret[key] = val; | ||
} else if (Array.isArray(ret[key])) { | ||
ret[key].push(val); | ||
} else { | ||
result[key] = value; | ||
ret[key] = [ret[key], val]; | ||
} | ||
}); | ||
return result; | ||
}, Object.create(null)); | ||
} | ||
return ret; | ||
}; | ||
var extract_1 = extract; | ||
var parse_1 = parse; | ||
var stringify = function (obj, opts) { | ||
opts = opts || {}; | ||
var stringify = (obj, options) => { | ||
if (!obj) { | ||
return ''; | ||
} | ||
var strict = opts.strict !== false; | ||
options = Object.assign({ | ||
encode: true, | ||
strict: true, | ||
arrayFormat: 'none' | ||
}, options); | ||
return obj ? Object.keys(obj).sort().map(function (key) { | ||
var val = obj[key]; | ||
const formatter = encoderForArrayFormat(options); | ||
const keys = Object.keys(obj); | ||
if (options.sort !== false) { | ||
keys.sort(options.sort); | ||
} | ||
return keys.map(key => { | ||
const value = obj[key]; | ||
if (value === undefined) { | ||
if (val === undefined) { | ||
return ''; | ||
} | ||
if (value === null) { | ||
return encode(key, options); | ||
if (val === null) { | ||
return key; | ||
} | ||
if (Array.isArray(value)) { | ||
const result = []; | ||
if (Array.isArray(val)) { | ||
var result = []; | ||
for (const value2 of value.slice()) { | ||
if (value2 === undefined) { | ||
continue; | ||
val.slice().sort().forEach(function (val2) { | ||
if (val2 === undefined) { | ||
return; | ||
} | ||
result.push(formatter(key, value2, result.length)); | ||
} | ||
if (val2 === null) { | ||
result.push(encode(key, strict)); | ||
} else { | ||
result.push(encode(key, strict) + '=' + encode(val2, strict)); | ||
} | ||
}); | ||
@@ -558,23 +338,12 @@ return result.join('&'); | ||
return encode(key, options) + '=' + encode(value, options); | ||
}).filter(x => x.length > 0).join('&'); | ||
return encode(key, strict) + '=' + encode(val, strict); | ||
}).filter(function (x) { | ||
return x.length > 0; | ||
}).join('&') : ''; | ||
}; | ||
var parseUrl = (input, options) => { | ||
const hashStart = input.indexOf('#'); | ||
if (hashStart !== -1) { | ||
input = input.slice(0, hashStart); | ||
} | ||
return { | ||
url: input.split('?')[0] || '', | ||
query: parse(extract(input), options) | ||
}; | ||
}; | ||
var queryString = { | ||
extract: extract_1, | ||
parse: parse_1, | ||
stringify: stringify, | ||
parseUrl: parseUrl | ||
extract: extract, | ||
parse: parse, | ||
stringify: stringify | ||
}; | ||
@@ -581,0 +350,0 @@ |
{ | ||
"name": "snuffles", | ||
"version": "1.0.1", | ||
"version": "1.0.2", | ||
"description": "A wrapper around the native fetch function, returning the response body as a camelCased object", | ||
@@ -62,4 +62,4 @@ "author": "railslove", | ||
"change-case-object": "2.0.0", | ||
"query-string": "6.2.0" | ||
"query-string": "4.1.0" | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
2
153969
1097
+ Addedquery-string@4.1.0(transitive)
+ Addedstrict-uri-encode@1.1.0(transitive)
- Removeddecode-uri-component@0.2.2(transitive)
- Removedquery-string@6.2.0(transitive)
- Removedstrict-uri-encode@2.0.0(transitive)
Updatedquery-string@4.1.0