Security News
The Risks of Misguided Research in Supply Chain Security
Snyk's use of malicious npm packages for research raises ethical concerns, highlighting risks in public deployment, data exfiltration, and unauthorized testing.
@rentspree/path
Advanced tools
URL path params/query resolve with ease
This is a helper librarly that combine the use of path-to-regexp with qs query string library. While those librarly work independently, the former is for generating path with path params, the latter is for generating query string from object (or in the reverse). This library combinses the use of these two path to build url.
The library is written in ES6 most advance syntax.
Please enjoy!
$ npm install --save @rentspree/path
or if you are a fan of Yarn
$ yarn add @rentspree/path
import { buildPath } from "@rentspree/path";
// return "/api/user/1234?name=John&lastName=Doe"
buildPath("/api/user/:id", {id: "1234"}, {name: "John", lastName: "Doe"})
Or if you are interested in only using the query string append, you can surely do it
import { query } from "@rentspree/path"
// return "?name=John&lastName=Doe"
query.stringify({name: "John", lastName: "Doe"})
// returns {query: "hello", consulta: "hola"}
query.parse("?query=hello&consulta=hola")
Build path from path regexp and params and optionally append query suffix to the path
path
String the path regexparams
Object the params to interpolate in pathquery
Object? the query object to be converted to string// return /api/user/123456?name=John&lastName=Doe
buildPath("/api/user/:id", {id: "123456"}, {name: "John", lastName: "Doe"}
// return /content/post/this-is-a-good-post
buildPath("/content/post/:slug", {slug: "this-is-a-good-post"})
Returns (String | null) the built path
Default error class
Set the Error class which would be thrown when buildPath function failed
error
Class an Error class which would be thrown// if you set
setErrorClass(SomeClass)
// when the buildPath function failed it will throw something like this
throw new SomeClass()
This method parse a query string into object
str
String the string to parse (optional, default ""
)// returns {str1: "hello", str2: "hola"}
parse("?str1=hello&str2=hola")
// returns {name: "John", lastName: "Doe"}
parse("name=John&lastName=Doe")
Returns Object the query object parsed from query string
This method stringify object into query string
obj
Object the object to be stringify (optional, default {}
)// returns "?name=John&lastName=Doe"
stringify({name: "John", lastName: "Doe"})
Returns String the stringified query result
Build URL from URL-JOIN library
args
String all path what you need to join// return /api/user/123456?name=John&lastName=Doe
urlJoin("/api/user/123456", "?name=John&lastName=Doe")
// return /content/post/this-is-a-good-post
urlJoin("/content/post///", "//this-is-a-good-post")
Returns String the built path
MIT © Potsawee Vechpanich
FAQs
URL path params/query resolve with ease
The npm package @rentspree/path receives a total of 23 weekly downloads. As such, @rentspree/path popularity was classified as not popular.
We found that @rentspree/path demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers collaborating on the project.
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.
Security News
Snyk's use of malicious npm packages for research raises ethical concerns, highlighting risks in public deployment, data exfiltration, and unauthorized testing.
Research
Security News
Socket researchers found several malicious npm packages typosquatting Chalk and Chokidar, targeting Node.js developers with kill switches and data theft.
Security News
pnpm 10 blocks lifecycle scripts by default to improve security, addressing supply chain attack risks but sparking debate over compatibility and workflow changes.