Socket
Socket
Sign inDemoInstall

urltron

Package Overview
Dependencies
0
Maintainers
1
Versions
13
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    urltron

Stringify and parse json from url query parameters


Version published
Weekly downloads
145
increased by7.41%
Maintainers
1
Install size
11.5 kB
Created
Weekly downloads
 

Readme

Source

CI npm total downloads licence npm version

urltron

Stringify and parse json for url.

Works wonderfully for SPA apps that want to store state in url. Read via location.search and location.hash. Navigate with <a href="...">, history.pushState and location.assign. Can be used with react-router's <Link to={...} and useLocation/useHistory hooks.

Why use urltron?

  • 0 dependencies
  • Tiny (~1kb)
  • Fast
  • Looks like good ol' query params
  • Written in Typescript. Comes with typings when installed.
  • Works on all browsers and Node.js

Usage

Same api as built-in JSON.stringify and JSON.parse.

import urltron from 'urltron';
urltron.stringify({limit: 10, offset: 20, query: 'hello'});
urltron.parse('limit=10&offset=20&query=hello');

Design

  • A flat object looks exactly like query paramters e.g ?k1=v&k2=v.
  • Supports all valid json types (null, boolean, number, string, object and array).
  • Readable and intuitive output. Objects as (a=1&b=2&c=3) and arrays in @(a,b,c)
  • Shorter and readable output compared to encodeURIComponent(JSON.stringify(val))

Examples

urltronjson
hello=world+tour&limit=2&sort{"hello":"world tour","limit":2,"sort":true}
query={"query":""}
num=1.23{"num":1.23}
yep=t{"yep":true}
nah=f{"nah":false}
nada=n{"nada":null}
nStr=~n{"nStr":"n"}
numStr=~123{"numStr":"123"}
arr=@(1,2,3){"arr":[1,2,3]}
jraphql=(id&name&books=(id&name)){"jraphql":{"id":true,"name":true,"books":{"id":true,"name":true}}
@(@(1,2,3),@(4,5,6),@(7,8,9),0)[[1,2,3],[4,5,6],[7,8,9],0]
@(~,hello,t,f,n,1,(a=(b=c)))["","hello",true,false,null,1,{"a":{"b":"c"}}]

Keywords

FAQs

Last updated on 04 Jun 2021

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc