jupyter笔记
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

198 lines
3.9 KiB

{
"cells": [
{
"cell_type": "markdown",
"id": "e28a05ae-c5c5-4dc5-88b4-9090492f13e2",
"metadata": {},
"source": [
"# qs\n",
"- A querystring parsing and stringifying library with some added security.\n",
"- [https://www.npmjs.com/package/qs](https://www.npmjs.com/package/qs)\n"
]
},
{
"cell_type": "code",
"execution_count": 1,
"id": "a1d79a6e-3479-41cc-bc94-bd4d5b55e788",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"{ a: 'b', c: 'd' }"
]
},
"execution_count": 1,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"import qs from \"qs\"\n",
"qs.parse('?a=b&c=d', { ignoreQueryPrefix: true })"
]
},
{
"cell_type": "code",
"execution_count": 1,
"id": "b6a27923-d70c-4403-b977-9d3901a9c204",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"/admin/reginfo?id=123&regId=456&category=789\n"
]
},
{
"data": {
"text/plain": [
"undefined"
]
},
"execution_count": 1,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"import qs from \"qs\"\n",
"const item = {id:123,regId:456,category:789}\n",
"const url = `/admin/reginfo?${qs.stringify(item)}`\n",
"console.log(url)"
]
},
{
"cell_type": "code",
"execution_count": 8,
"id": "0425adb4-a182-47a5-8fc2-8df4815069eb",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"{ a: 'b' }"
]
},
"execution_count": 8,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"import qs from \"qs\"\n",
"qs.parse('a=b&c=d', { parameterLimit: 1 });"
]
},
{
"cell_type": "code",
"execution_count": 13,
"id": "f7f2490d-52b3-41c8-a19f-d6be53095d09",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"{ a: 'b', c: 'd' }"
]
},
"execution_count": 13,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"import qs from \"qs\"\n",
"qs.parse('?a=b&c=d', { ignoreQueryPrefix: true })"
]
},
{
"cell_type": "code",
"execution_count": 15,
"id": "a317f8a9-6944-47f5-99b8-9cabac49608e",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"{ a: 'b', c: 'd' }"
]
},
"execution_count": 15,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"import qs from \"qs\"\n",
"qs.parse('a=b;c=d', { delimiter: ';' })"
]
},
{
"cell_type": "code",
"execution_count": 17,
"id": "da3327c1-6146-43f5-9301-dd066170ec53",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"{ a: 'b', c: 'd', e: 'f' }"
]
},
"execution_count": 17,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"import qs from \"qs\"\n",
"qs.parse('a=b;c=d,e=f', { delimiter: /[;,]/ })"
]
},
{
"cell_type": "code",
"execution_count": 18,
"id": "c32e7427-7d1a-4f0d-a84f-b20403290883",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"undefined"
]
},
"execution_count": 18,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"var qs = require('qs');\n",
"var assert = require('assert');\n",
"\n",
"var obj = qs.parse('a=c');\n",
"assert.deepEqual(obj, { a: 'c' });\n",
"\n",
"var str = qs.stringify(obj);\n",
"assert.equal(str, 'a=c');\n"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "jp-Babel (Node.js)",
"language": "babel",
"name": "babel"
},
"language_info": {
"file_extension": ".js",
"mimetype": "application/javascript",
"name": "javascript",
"version": "17.9.0"
}
},
"nbformat": 4,
"nbformat_minor": 5
}