1
0
Fork 0
mirror of https://github.com/jellyfin/jellyfin-web synced 2025-03-30 19:56:21 +00:00

update shared components

This commit is contained in:
Luke Pulverenti 2016-03-14 16:27:35 -04:00
parent b29e4cd59d
commit 0a1cafc981
11 changed files with 306 additions and 66 deletions

View file

@ -1,15 +1,15 @@
{
"name": "query-string",
"homepage": "https://github.com/sindresorhus/query-string",
"version": "3.0.1",
"_release": "3.0.1",
"version": "2.3.0",
"_release": "2.3.0",
"_resolution": {
"type": "version",
"tag": "v3.0.1",
"commit": "9fbb928f67f493a7a7458cdb82c15b40ceb4124b"
"tag": "2.3.0",
"commit": "89837373db79e73fb8bade647b46c188c69d761a"
},
"_source": "git://github.com/sindresorhus/query-string.git",
"_target": "~3.0.1",
"_target": "~2.3.0",
"_originalSource": "query-string",
"_direct": true
}

View file

@ -0,0 +1,12 @@
{
"node": true,
"esnext": true,
"bitwise": true,
"curly": true,
"immed": true,
"newcap": true,
"noarg": true,
"undef": true,
"unused": "vars",
"strict": true
}

View file

@ -1,6 +1,6 @@
sudo: false
language: node_js
node_js:
- 'stable'
- 'iojs'
- '0.12'
- '0.10'

View file

@ -1,11 +1,11 @@
'use strict';
var strictUriEncode = require('strict-uri-encode');
exports.extract = function (str) {
return str.split('?')[1] || '';
window.queryString = {};
window.queryString.extract = function (maybeUrl) {
return maybeUrl.split('?')[1] || '';
};
exports.parse = function (str) {
window.queryString.parse = function (str) {
if (typeof str !== 'string') {
return {};
}
@ -18,13 +18,10 @@ exports.parse = function (str) {
return str.split('&').reduce(function (ret, 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;
var key = parts[0];
var val = parts[1];
key = decodeURIComponent(key);
// missing `=` should be `null`:
// http://w3.org/TR/2012/WD-url-20120524/#collect-url-parameters
val = val === undefined ? null : decodeURIComponent(val);
@ -41,26 +38,16 @@ exports.parse = function (str) {
}, {});
};
exports.stringify = function (obj) {
window.queryString.stringify = function (obj) {
return obj ? Object.keys(obj).sort().map(function (key) {
var val = obj[key];
if (val === undefined) {
return '';
}
if (val === null) {
return key;
}
if (Array.isArray(val)) {
return val.slice().sort().map(function (val2) {
return strictUriEncode(key) + '=' + strictUriEncode(val2);
return val.sort().map(function (val2) {
return encodeURIComponent(key) + '=' + encodeURIComponent(val2);
}).join('&');
}
return strictUriEncode(key) + '=' + strictUriEncode(val);
}).filter(function (x) {
return x.length > 0;
return encodeURIComponent(key) + '=' + encodeURIComponent(val);
}).join('&') : '';
};

View file

@ -1,23 +1,7 @@
{
"name": "query-string",
"version": "3.0.1",
"version": "2.3.0",
"description": "Parse and stringify URL query strings",
"license": "MIT",
"repository": "sindresorhus/query-string",
"author": {
"name": "Sindre Sorhus",
"email": "sindresorhus@gmail.com",
"url": "sindresorhus.com"
},
"engines": {
"node": ">=0.10.0"
},
"scripts": {
"test": "xo && ava"
},
"files": [
"index.js"
],
"keywords": [
"browser",
"querystring",
@ -33,11 +17,23 @@
"encode",
"decode"
],
"dependencies": {
"strict-uri-encode": "^1.0.0"
"license": "MIT",
"author": {
"name": "Sindre Sorhus",
"email": "sindresorhus@gmail.com",
"url": "sindresorhus.com"
},
"files": [
"index.js"
],
"repository": "sindresorhus/query-string",
"scripts": {
"test": "mocha"
},
"devDependencies": {
"ava": "*",
"xo": "*"
"mocha": "*"
},
"engines": {
"node": ">=0.10.0"
}
}

View file

@ -13,19 +13,19 @@ $ npm install --save query-string
## Usage
```js
const queryString = require('query-string');
var queryString = require('query-string');
console.log(location.search);
//=> '?foo=bar'
//=> ?foo=bar
const parsed = queryString.parse(location.search);
var parsed = queryString.parse(location.search);
console.log(parsed);
//=> {foo: 'bar'}
console.log(location.hash);
//=> '#token=bada55cafe'
//=> #token=bada55cafe
const parsedHash = queryString.parse(location.hash);
var parsedHash = queryString.parse(location.hash);
console.log(parsedHash);
//=> {token: 'bada55cafe'}
@ -35,7 +35,7 @@ parsed.ilike = 'pizza';
location.search = queryString.stringify(parsed);
console.log(location.search);
//=> '?foo=unicorn&ilike=pizza'
//=> ?foo=unicorn&ilike=pizza
```
@ -56,7 +56,7 @@ Extract a query string from a URL that can be passed into `.parse()`.
## Nesting
This module intentionally doesn't support nesting as it's not spec'd and varies between implementations, which causes a lot of [edge cases](https://github.com/visionmedia/node-querystring/issues).
This module intentionally doesn't support nesting as it's not specced and varies between implementations, which causes a lot of [edge cases](https://github.com/visionmedia/node-querystring/issues).
You're much better off just converting the object to a JSON string:
@ -67,7 +67,7 @@ queryString.stringify({
unicorn: 'cake'
})
});
//=> 'foo=bar&nested=%7B%22unicorn%22%3A%22cake%22%7D'
//=> foo=bar&nested=%7B%22unicorn%22%3A%22cake%22%7D
```

View file

@ -0,0 +1,91 @@
'use strict';
var assert = require('assert');
var qs = require('./');
describe('.parse()', function () {
it('query strings starting with a `?`', function () {
assert.deepEqual(qs.parse('?foo=bar'), {foo: 'bar'});
});
it('query strings starting with a `#`', function () {
assert.deepEqual(qs.parse('#foo=bar'), {foo: 'bar'});
});
it('query strings starting with a `&', function () {
assert.deepEqual(qs.parse('&foo=bar&foo=baz'), {foo: ['bar', 'baz']});
});
it('parse a query string', function () {
assert.deepEqual(qs.parse('foo=bar'), {foo: 'bar'});
});
it('parse multiple query string', function () {
assert.deepEqual(qs.parse('foo=bar&key=val'), {foo: 'bar', key: 'val'});
});
it('parse query string without a value', function () {
assert.deepEqual(qs.parse('foo'), {foo: null});
assert.deepEqual(qs.parse('foo&key'), {foo: null, key: null});
assert.deepEqual(qs.parse('foo=bar&key'), {foo: 'bar', key: null});
});
it('return empty object if no qss can be found', function () {
assert.deepEqual(qs.parse('?'), {});
assert.deepEqual(qs.parse('&'), {});
assert.deepEqual(qs.parse('#'), {});
assert.deepEqual(qs.parse(' '), {});
});
it('handle `+` correctly', function () {
assert.deepEqual(qs.parse('foo+faz=bar+baz++'), {'foo faz': 'bar baz '});
});
it('handle multiple of the same key', function () {
assert.deepEqual(qs.parse('foo=bar&foo=baz'), {foo: ['bar', 'baz']});
});
it('query strings params including embedded `=`', function () {
assert.deepEqual(qs.parse('?param=http%3A%2F%2Fsomeurl%3Fid%3D2837'), {param: 'http://someurl?id=2837'});
});
});
describe('.stringify()', function () {
it('stringify', function () {
assert.strictEqual(qs.stringify({foo: 'bar'}), 'foo=bar');
assert.strictEqual(qs.stringify({foo: 'bar', bar: 'baz'}), 'bar=baz&foo=bar');
});
it('different types', function () {
assert.strictEqual(qs.stringify(), '');
assert.strictEqual(qs.stringify(0), '');
});
it('URI encode', function () {
assert.strictEqual(qs.stringify({'foo bar': 'baz faz'}), 'foo%20bar=baz%20faz');
});
it('handle array value', function () {
assert.strictEqual(qs.stringify({abc: 'abc', foo: ['bar', 'baz']}), 'abc=abc&foo=bar&foo=baz');
});
});
describe('.extract()', function () {
it('should extract qs from url', function () {
assert.equal(qs.extract('http://foo.bar/?abc=def&hij=klm'), 'abc=def&hij=klm');
assert.equal(qs.extract('http://foo.bar/?'), '');
});
it('should handle strings not containing qs', function () {
assert.equal(qs.extract('http://foo.bar/'), '');
assert.equal(qs.extract(''), '');
});
it('should throw for invalid values', function() {
assert.throws(function() {
qs.extract(null);
}, TypeError);
assert.throws(function() {
qs.extract(undefined);
}, TypeError);
});
});