本文整理汇总了TypeScript中src/UrlSearchParams.get函数的典型用法代码示例。如果您正苦于以下问题:TypeScript get函数的具体用法?TypeScript get怎么用?TypeScript get使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了get函数的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: checkParams
construct: (function () {
function checkParams(params: UrlSearchParams) {
assert.deepEqual(params.getAll('foo'), [ 'bar', 'baz' ]);
assert.deepEqual(params.getAll('bar'), [ 'foo' ]);
assert.deepEqual(params.getAll('baz'), [ '' ]);
}
return {
empty() {
// Empty UrlSearchParams should have no properties
const params = new UrlSearchParams();
assert.isNull(params.get('foo'));
},
// Next three tests should generate 'params' objects with same contents
object() {
const params = new UrlSearchParams({ foo: [ 'bar', 'baz' ], bar: 'foo', baz: null });
checkParams(params);
},
string() {
let params = new UrlSearchParams('foo=bar&foo=baz&bar=foo&baz');
checkParams(params);
// Assignments after the first will be ignored
params = new UrlSearchParams('foo=bar=baz');
assert.deepEqual(params.getAll('foo'), [ 'bar' ]);
// Handle empty keys
params = new UrlSearchParams('=foo&');
assert.deepEqual(params.getAll(''), [ 'foo', '' ]);
},
UrlSearchParams() {
const params1 = new UrlSearchParams({ foo: [ 'bar', 'baz' ], bar: 'foo', baz: null });
const params = new UrlSearchParams(params1);
checkParams(params);
}
}
})(),
示例2: UrlSearchParams
const params = new UrlSearchParams();
params.append('foo', 'bar');
assert.deepEqual(params.getAll('foo'), [ 'bar' ]);
},
'existing key'() {
const params = new UrlSearchParams({ foo: 'bar' });
params.append('foo', 'baz');
assert.deepEqual(params.getAll('foo'), [ 'bar', 'baz' ]);
}
},
'#delete'() {
const params = new UrlSearchParams({ foo: 'bar' });
params.delete('foo');
assert.isNull(params.get('foo'));
},
'#get'() {
// Get should always return the first entry for a key
const params1 = new UrlSearchParams({ foo: [ 'bar', 'baz' ] });
const params2 = new UrlSearchParams({ foo: [ 'baz', 'bar' ] });
assert.strictEqual(params1.get('foo'), 'bar');
assert.strictEqual(params2.get('foo'), 'baz');
assert.isNull(params2.get('bar'));
},
'#getAll'() {
const params = new UrlSearchParams({ foo: [ 'bar', 'baz' ] });
assert.deepEqual(params.getAll('foo'), [ 'bar', 'baz' ]);
assert.isNull(params.getAll('bar'));