-
Notifications
You must be signed in to change notification settings - Fork 31
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Expand the list with some new replacements #192
Comments
This came out more than I expected, if I find anything else I'll post it in a separate issue. Would love to hear community feedback on this. |
what's the native implementation for clamp? |
const clamp = (value, min, max) => Math.min(Math.max(value, min), max); However, this doesn't handle the case when const clamp = (value, min, max) =>
min < max
? Math.min(Math.max(value, min), max)
: Math.min(Math.max(value, max), min); This will be a 1:1 port of the mentioned dependency |
To be clear tho, that's not a native implementation, that's inlining the implementation of the function. A native implementation would be like |
You're absolutely right with this point. I've chosen not the best terminology for this |
this is a great list, really good detail
adding these to the replacements repo makes sense, but its probably also a good idea to open related issues in the cleanup repo. others in the community may be able to help us find high impact dependents we can start replacing these in |
1. querystring
Current Status: Deprecated.
Author Message: "The querystring API is considered Legacy. New code should use the URLSearchParams API instead."
Replacement: URLSearchParams API.
Reference: npmjs [1], also an indication in the README of the repository [2]
Package Using
querysting
@redux-devtools/remote
(Last Month Downloads: ~28,000)node-quickbooks
(Last Month Downloads: ~140,000)enigma.js
(Last Month Downloads: ~70,000)2. request
Current Status: Deprecated.
Author Message: "The most valuable thing request can do for the JavaScript ecosystem is to go into maintenance mode and stop considering new features or major releases."
Reference: Issue [1]
Replacement:
request(url, callback)
await fetch(url)
request.post(url)
fetch(url, {method: 'POST'})
request(url).pipe(fs.createWriteStream())
pipeline(response.body, fs.createWriteStream())
request.post(url, {form: data})
fetch(url, {body: new URLSearchParams(data)})
request.post(url, {formData: data})
fetch(url, {body: new FormData()})
request({url, json: true})
await fetch(url).then(r => r.json())
request({headers: {...}})
fetch(url, {headers: {...}})
request.get(url).auth(user, pass)
fetch(url, {headers: {'Authorization': 'Basic ' + btoa(user + ':' + pass)}})
request.get(url).auth(null, null, true, token)
fetch(url, {headers: {'Authorization': 'Bearer ' + token}})
request({qs: {key: 'value'}})
new URL(url).searchParams.set('key', 'value')
request({jar: true})
fetch(url, {credentials: 'include'})
request({followRedirect: false})
fetch(url, {redirect: 'manual'})
request({timeout: 1000})
AbortController + setTimeout
request({proxy: 'http://....'})
fetch(url, {agent: new HttpsProxyAgent()})
request({cert: fs.readFileSync()})
fetch(url, {agent: new https.Agent({cert: ...})})
request({gzip: true})
fetch(url)
request({ca: fs.readFileSync()})
fetch(url, {agent: new https.Agent({ca: ...})})
request({forever: true})
fetch(url, {agent: new http.Agent({keepAlive: true})})
Note
I haven't dived deep enough so the list at the top is not 100% feature coverage, but the cases here should cover up to trivial 90+% needs of previous request users. Also check out the article down below.
References:
Also check this article for more possible replacements.
Package's npmjs
3. clamp
Current Status: Simple utility for clamping values.
Replacement: Could be inlined
Package's npmjs
4. uniq
Current Status: Utility for removing duplicates from arrays.
Replacement: Native Set
Package's npmjs
5. isomorphic-fetch
&node-fetch
Warning
This needs further investigation, but it looks like this can be fully replaced with native fetch by now.
Package's npmjs (isomorphic fetch)
Package's npmjs (node-fetch)
According to caniuse:
Also check out this thread
The text was updated successfully, but these errors were encountered: