object-to-querystring

该博客介绍了两种将JavaScript对象转换为URL查询字符串的方法。一种是使用自定义的`objectToQueryString`函数,通过遍历对象并拼接键值对到查询字符串中;另一种是引入`object-to-querystring`库进行转换。示例展示了如何处理包含`undefined`值的参数,并给出了转换结果。

js方法

const objectToQueryString = queryParameters => {
return queryParameters
? Object.entries(queryParameters).reduce((queryString, [key, val], index) => {
const symbol = queryString.length === 0 ? ‘?’ : ‘&’;
queryString += typeof val === ‘string’ ? ${symbol}${key}=${val} : ‘’;
return queryString;
}, ‘’)
: ‘’;
};
原文链接:https://blog.csdn.net/u011519828/article/details/108432394

示例

objectToQueryString({ page: ‘1’, size: ‘2kg’, key: undefined });

结果

?page=1&size=2kg

object-to-querystring

import objectToQuery from ‘object-to-querystring’;

const params = {
name: ‘Justin’,
number: 12345,
};
const querystring = objectToQuery(params);
/*
querystring === ‘?name=Justin&number=12345’
*/
----原文链接:http://www.javascriptcn.com/post/54900

npm WARN deprecated @stylelint/postcss-[email protected]: Use the original unforked package instead: postcss-markdown npm WARN deprecated [email protected]: Package no longer supported. Contact Support at https://www.npmjs.com/support for more info. npm WARN deprecated @hapi/[email protected]: Moved to 'npm install @sideway/address' npm WARN deprecated @hapi/[email protected]: This version has been deprecated and is no longer supported or maintained npm WARN deprecated @hapi/to[email protected]: This version has been deprecated and is no longer supported or maintained npm WARN deprecated @hapi/[email protected]: This version has been deprecated and is no longer supported or maintained npm WARN deprecated [email protected]: This package is deprecated. Use https://socket.dev/npm/package/eta instead. npm WARN deprecated workbox-google-[email protected]: It is not compatible with newer versions of GA starting with v4, as long as you are using GAv3 it should be ok, but the package is not longer being maintained npm WARN deprecated figgy-[email protected]: This module is no longer supported. npm WARN deprecated move-[email protected]: This package is no longer supported. npm WARN deprecated [email protected]: Upgrade to fsevents v2 to mitigate potential security issues npm WARN deprecated [email protected]: Legacy versions of mkdirp are no longer supported. Please update to mkdirp 1.x. (Note that the API surface has changed to use Promises in 1.x.) npm WARN deprecated querystring@0.2.0: The querystring API is considered Legacy. new code should use the URLSearchParams API instead. npm WARN deprecated [email protected]: Glob versions prior to v9 are no longer supported npm WARN deprecated @humanwhocodes/object-[email protected]: Use @eslint/object-schema instead npm WARN deprecated source-map-[email protected]: See https://github.com/lydell/source-map-resolve#deprecated npm WARN deprecated copy-[email protected]: This package is no longer supported. npm WARN deprecated fs-write-stream-ato[email protected]: This package is no longer supported. npm WARN deprecated [email protected]: Rimraf versions prior to v4 are no longer supported npm WARN deprecated [email protected]: Please see https://github.com/lydell/urix#deprecated npm WARN deprecated resolve-[email protected]: https://github.com/lydell/resolve-url#deprecated npm WARN deprecated source-map-[email protected]: See https://github.com/lydell/source-map-url#deprecated
03-08
正在分析单端Sanger测序文件: 013-G2.ab1 INFO [2025-08-11 17:36:10] ------------------------------------------------ INFO [2025-08-11 17:36:10] -------- Creating 'SangerRead' instance -------- INFO [2025-08-11 17:36:10] ------------------------------------------------ INFO [2025-08-11 17:36:10] >> Forward Read: Creating abif & sangerseq ... INFO [2025-08-11 17:36:10] >> Creating Forward Read raw abif ... INFO [2025-08-11 17:36:10] >> Creating Forward Read raw sangerseq ... INFO [2025-08-11 17:36:10] * Making basecall !! INFO [2025-08-11 17:36:10] * Updating slots in 'SangerRead' instance !! SUCCESS [2025-08-11 17:36:11] -------------------------------------------------------- SUCCESS [2025-08-11 17:36:11] -------- 'SangerRead' S4 instance is created !! -------- SUCCESS [2025-08-11 17:36:11] -------------------------------------------------------- SUCCESS [2025-08-11 17:36:11] >> '013-G2.ab1' is created (Forward Read; ABIF). INFO [2025-08-11 17:36:11] >> Read is trimmed by 'M1 - Mott’s trimming algorithm'. DEBUG [2025-08-11 17:36:11] >> For more information, please run 'object'. DEBUG [2025-08-11 17:36:11] >> Run 'object@objectResults@readResultTable' to check the result of the Sanger read 生成质量报告... INFO [2025-08-11 17:36:11] Your input is 'SangerRead' S4 instance INFO [2025-08-11 17:36:11] >>> outputDir : C:\Users\Administrator\AppData\Local\Temp\Rtmp6Pr8wB processing file: SangerRead_Report_ab1.Rmd |................................................. | 95% [unnamed-chunk-9]INFO [2025-08-11 17:36:12] * Making basecall !! INFO [2025-08-11 17:36:12] * Updating slots in 'SangerRead' instance !! output file: SangerRead_Report_ab1.knit.md "C:/PROGRA~1/Pandoc/pandoc" +RTS -K512m -RTS SangerRead_Report_ab1.knit.md --to html4 --from markdown+autolink_bare_uris+tex_math_single_backslash --output pandoc1d4c20606dbd.html --lua-filter "C:\PROGRA~1\R\R-44~1.3\library\RMARKD~1\RMARKD~1\lua\PAGEBR~1.LUA" --lua-filter "C:\PROGRA~1\R\R-44~1.3\library\RMARKD~1\RMARKD~1\lua\LATEX-~1.LUA" --lua-filter "C:\PROGRA~1\R\R-44~1.3\library\RMARKD~1\RMARKD~1\lua\TABLE-~1.LUA" --embed-resources --standalone --variable bs3=TRUE --section-divs --table-of-contents --toc-depth 3 --variable toc_float=1 --variable toc_selectors=h1,h2,h3 --variable toc_collapsed=1 --variable toc_smooth_scroll=1 --variable toc_print=1 --template "C:\PROGRA~1\R\R-44~1.3\library\RMARKD~1\rmd\h\DEFAUL~1.HTM" --no-highlight --variable highlightjs=1 --variable theme=bootstrap --mathjax --variable "mathjax-url=https://mathjax.rstudio.com/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML" --include-in-header "C:\Users\ADMINI~1\AppData\Local\Temp\Rtmp6Pr8wB\rmarkdown-str1d4cef82398.html" [WARNING] Div at SangerRead_Report_ab1.knit.md line 153 column 1 unclosed at SangerRead_Report_ab1.knit.md line 232 column 1, closing implicitly. [WARNING] Div at SangerRead_Report_ab1.knit.md line 147 column 1 unclosed at SangerRead_Report_ab1.knit.md line 232 column 1, closing implicitly. [WARNING] Could not fetch resource https://pro.fontawesome.com/releases/v5.10.0/webfonts/fa-duotone-900.ttf: HttpExceptionRequest Request { host = "pro.fontawesome.com" port = 443 secure = True requestHeaders = [] path = "/releases/v5.10.0/webfonts/fa-duotone-900.ttf" queryString = "" method = "GET" proxy = Nothing rawBody = False redirectCount = 10 responseTimeout = ResponseTimeoutDefault requestVersion = HTTP/1.1 proxySecureMode = ProxySecureWithConnect } (InternalException (HostCannotConnect "pro.fontawesome.com" [Network.Socket.connect: <socket: 852>: failed (Connection timed out (WSAETIMEDOUT)),Network.Socket.connect: <socket: 852>: failed (Connection timed out (WSAETIMEDOUT))])) Output created: C:/Users/Administrator/AppData/Local/Temp/Rtmp6Pr8wB/013-G2/SangerRead_Report_ab1.html Error: 分析失败: $ operator is invalid for atomic vectors Execution halted
最新发布
08-12
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值