url-search-params-polyfill
Advanced tools
Comparing version 1.1.0 to 1.2.0
17
index.js
@@ -170,3 +170,20 @@ /** | ||
/** | ||
* Sort all name-value pairs | ||
*/ | ||
prototype.sort = function () { | ||
var dict = this[__URLSearchParams__], keys = [], k, i, ret = {}; | ||
for (k in dict) { | ||
keys.push(k); | ||
} | ||
keys.sort(); | ||
for (i = 0; i < keys.length; i ++) { | ||
ret[keys[i]] = dict[keys[i]]; | ||
} | ||
this[__URLSearchParams__] = ret; | ||
}; | ||
/** | ||
* Returns an iterator allowing to go through all keys of | ||
@@ -173,0 +190,0 @@ * the key/value pairs contained in this object. |
{ | ||
"name": "url-search-params-polyfill", | ||
"version": "1.1.0", | ||
"version": "1.2.0", | ||
"description": "a simple polyfill for javascript URLSearchParams", | ||
@@ -5,0 +5,0 @@ "homepage": "https://github.com/jerrybendy/url-search-params-polyfill", |
@@ -100,2 +100,8 @@ # URLSearchParams polyfill [![](https://img.shields.io/npm/v/url-search-params-polyfill.svg)](https://www.npmjs.com/package/url-search-params-polyfill) | ||
### sort | ||
```javascript | ||
search.sort(); | ||
``` | ||
### forEach | ||
@@ -102,0 +108,0 @@ |
@@ -22,5 +22,5 @@ /** | ||
describe('构造函数', function () { | ||
describe('Constructor', function () { | ||
it('通过 search 字符串构建', function () { | ||
it('Construct with a search string', function () { | ||
var a = new URLSearchParams('?a=1&b=2'); | ||
@@ -30,3 +30,3 @@ expect(a.toString()).to.be.equal('a=1&b=2'); | ||
it('通过不带问号的 search 字符串构建', function () { | ||
it('Construct with a search string without "?"', function () { | ||
var a = new URLSearchParams('a=1&b=2'); | ||
@@ -36,3 +36,3 @@ expect(a.toString()).to.be.equal('a=1&b=2'); | ||
it('使用对象构建', function () { | ||
it('Construct with an object', function () { | ||
var a = new URLSearchParams({ | ||
@@ -50,3 +50,3 @@ a: 1, | ||
it('创建空的对象', function () { | ||
it('Construct an empty object', function () { | ||
var a = new URLSearchParams(); | ||
@@ -58,3 +58,3 @@ expect(a.toString()).to.be.equal(''); | ||
it('使用另一个 URLSearchParams 对象构造', function () { | ||
it('Construct with another URLSearchParams object', function () { | ||
var obj = getSimpleObj(); | ||
@@ -67,5 +67,5 @@ var b = new URLSearchParams(obj); | ||
describe('Append 插入数据', function () { | ||
describe('Append data', function () { | ||
it('Append 插入数据', function () { | ||
it('Append data', function () { | ||
var a = getSimpleObj(); | ||
@@ -76,3 +76,3 @@ a.append("id", 1); | ||
it('Append 重复插入相同 key 的数据', function () { | ||
it('Append data with repetitive key', function () { | ||
var a = getSimpleObj(); | ||
@@ -87,5 +87,5 @@ a.append('id', 1); | ||
describe('Get 读取数据', function () { | ||
describe('Get data', function () { | ||
it('读取简单数据', function () { | ||
it('Get simple data', function () { | ||
var a = getSimpleObj(); | ||
@@ -95,3 +95,3 @@ expect(a.get('a')).to.be.equal('1'); | ||
it('读取布尔值数据,要返回字符串', function () { | ||
it('Get a boolean data, should return string', function () { | ||
var a = new URLSearchParams('a=true'); | ||
@@ -101,3 +101,3 @@ expect(a.get('a')).to.be.equal('true'); | ||
it('读取 append 添加的数据', function () { | ||
it('Get data which from append', function () { | ||
var a = getSimpleObj(); | ||
@@ -108,3 +108,3 @@ a.append('id', 'xx'); | ||
it('读取 key 重复的数据,应返回第一条的结果', function () { | ||
it('Get data with repetitive key, should return the first one', function () { | ||
var a = getSimpleObj(); | ||
@@ -116,3 +116,3 @@ a.append('id', 'xx'); | ||
it('GetAll 读取简单数据,应返回数组', function () { | ||
it('GetAll read simple data, should return an array', function () { | ||
var a = getSimpleObj(); | ||
@@ -122,3 +122,3 @@ expect(a.getAll('a')).to.be.deep.equal(['1']); | ||
it('GetAll 读取 key 重复的数据,应返回所有数据的数组', function () { | ||
it('GetAll read data with repetitive key, should return all data with same key', function () { | ||
var a = getKeyRepeatObj(); | ||
@@ -131,5 +131,5 @@ expect(a.getAll('id')).to.be.deep.equal(['xx', 'yy', 'zz']); | ||
describe('Delete 删除数据', function () { | ||
describe('Delete data', function () { | ||
it('删除简单数据', function () { | ||
it('Remove simple data', function () { | ||
var a = getSimpleObj(); | ||
@@ -140,3 +140,3 @@ a.delete('a'); | ||
it('删除 key 重复的数据', function () { | ||
it('Remove data with repetitive key', function () { | ||
var a = getKeyRepeatObj(); | ||
@@ -147,3 +147,3 @@ a.delete('id'); | ||
it('删除不存在的数据', function () { | ||
it('Remove data which doesn\'t exists', function () { | ||
var a = getSimpleObj(); | ||
@@ -156,5 +156,5 @@ a.delete('notExists'); | ||
describe('Has 检查 key 是否存在', function () { | ||
describe('Has check key exists', function () { | ||
it('检查 key 是否存在', function () { | ||
it('Check the key exists', function () { | ||
var a = getSimpleObj(); | ||
@@ -168,5 +168,5 @@ expect(a.has('a')).to.be.equal(true); | ||
describe('Set 设置值', function () { | ||
describe('Set data', function () { | ||
it('设置新值', function () { | ||
it('Set a new data', function () { | ||
var a = getSimpleObj(); | ||
@@ -177,3 +177,3 @@ a.set('a', 'xx'); | ||
it('设置不存在的 key 值', function () { | ||
it('Set a nonexistent key', function () { | ||
var a = getSimpleObj(); | ||
@@ -187,5 +187,5 @@ a.set('id', 'xx'); | ||
describe('ForEach 循环遍历', function () { | ||
describe('ForEach', function () { | ||
it('遍历', function () { | ||
it('ForEach', function () { | ||
var a = getSimpleObj(), | ||
@@ -208,3 +208,3 @@ ret = {}; | ||
describe('Iterator 迭代器', function () { | ||
describe('Iterator', function () { | ||
@@ -249,4 +249,14 @@ it('entries', function () { | ||
describe('其它', function () { | ||
describe('Sort', function () { | ||
it ('Sort keys', function () { | ||
var obj = new URLSearchParams('q=flag&key=hello&s=world'); | ||
obj.sort(); | ||
expect(obj.toString()).to.be.equal('key=hello&q=flag&s=world'); | ||
}); | ||
}); | ||
describe('Others', function () { | ||
var testObj = { | ||
@@ -261,3 +271,3 @@ a: '你好', | ||
it('URL 编码', function () { | ||
it('URL encode', function () { | ||
var a = new URLSearchParams(testObj); | ||
@@ -267,3 +277,3 @@ expect(a.toString()).to.be.equal(testStr); | ||
it('URL 解码', function () { | ||
it('URL decode', function () { | ||
var a = new URLSearchParams(testStr); | ||
@@ -270,0 +280,0 @@ var ret = {}; |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
16364
434
144