

GitHub - lukeed/qss: A tiny (294b) browser utility for encoding & decoding a...
以下为 快照 页面,建议前往来源网站查看,会有更好的阅读体验。
原文链接: https://github.com/lukeed/qss
readme.md
qss 
A tiny (294B) browser utility for stringifying a query Object.
You should only consider using this within a browser context since Node's built-in querystring.stringify
is much faster and should be used in a Node environment! An ideal use case is serializing a query object before an API request is sent.
This module exposes three module definitions:
- ES Module:
dist/qss.mjs
- CommonJS:
dist/qss.js
- UMD:
dist/qss.min.js
Install
$ npm install --save qss
Usage
import { encode, decode } from 'qss'; encode({ foo:'hello', bar:[1,2,3], baz:true }); //=> 'foo=hello&bar=1&bar=2&bar=3&baz=true' encode({ foo:123 }, '?'); //=> '?foo=123' encode({ bar:'world' }, 'foo=hello&'); //=> 'foo=hello&bar=world' decode('foo=hello&bar=1&bar=2&bar=3&baz=true'); //=> { foo:'hello', bar:[1,2,3], baz:true };
API
qss.encode(params, prefix)
Returns: String
Returns the formatted querystring.
params
Type: Object
The object that contains all query parameter keys & their values.
prefix
Type: String
Default: ''
An optional prefix. The stringified params
will be appended to this value, so it must end with your desired joiner; eg ?
.
Important: No checks or validations will run on your
prefix
. Similarly, no character is used to "glue" the query string to yourprefix
string.
qss.decode(query)
Returns: Object
Returns an Object with decoded keys and values.
Repetitive keys will form an Array of its values. Also, qss
will attempt to typecast Boolean
and Number
values.
query
Type: String
The query string, without its leading ?
character.
qss.decode( location.search.substring(1) // removes the "?" );
Benchmarks
Running Node v10.13.0
Encode
qss x 1,104,287 ops/sec ±0.18% (96 runs sampled)
native x 5,420,126 ops/sec ±0.21% (94 runs sampled)
querystringify x 958,591 ops/sec ±0.64% (95 runs sampled)
query-string x 347,465 ops/sec ±1.05% (91 runs sampled)
qs x 729,840 ops/sec ±0.62% (92 runs sampled)
Decode
qss x 454,177 ops/sec ±0.17% (93 runs sampled)
native x 189,677 ops/sec ±0.45% (94 runs sampled)
querystringify x 300,793 ops/sec ±0.15% (96 runs sampled)
query-string x 197,520 ops/sec ±0.71% (97 runs sampled)
qs x 178,188 ops/sec ±0.34% (97 runs sampled)
License
MIT © Luke Edwards
猜你喜欢
-
107
dset - A tiny (135B) utility for safely writing deep Object values~!
-
49
readme.md dequal
-
53
ColorbarCoder is PHP class for encoding and decoding color barcode image. - Susros/ColorbarCoder
-
38
A common task for iOS apps is to save data and send it over the network. But before you can do that, you need to convert the data to a suitable format through a process called encoding or serialization...
-
16
README.rst Jansson README
-
0
Swift Codable: Decoding / Encoding With Context Swift Codable: Decoding / Encoding With Context February 5th, 2020 The Codable protocols are one of the coolest recent additions to Sw...
-
0
A 2-part tutorial series on encoding and decoding strings in Python 2.x and Python 3.x. HTML Parser: How to scrape HTML co...
-
2
Base64 Encoding and Decoding in JavaScript in Adobe AIR Thursday, June 12, 2008 I have been working on a JavaScript AIR app for the past week or so while on the on AIR Tour in Europe, and ran into the need to Base64 enc...
-
56
readme.md dimport
-
101
sade - Smooth (CLI) Operator ?
关于极客头条
聚合每日国内外有价值,有趣的链接。