Skip to content

jimmywarting/lazy-resolver

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

lazy-resolver

Skip hoops with promises

npm install lazy-resolver

Do you know how lodash _.get works or angulars $parse works? this lib is kind of like that, you can test deep objects/path but it dose it with promises and by chaining a dummy function to evaluate the code when a promise has been resolved

Example:

const resolve = require('lazy-resolver') // This is a Proxy handler
const fetch = resolve(import('node-fetch')).default

fetch(url)
  .then(response => console.log(response))

Go beond what's possible and make promise chain sync-ish looking

// Node variant
const fetch = resolve(import('node-fetch')).default
fetch('https://httpbin.org/get?items=4&items=2')
  .json()
  .args
  .items
  .map(n => ~~n * 4)
  .then(console.log, console.warn)

// Browser variant
resolve(window)
  .fetch('https://httpbin.org/get?items=4&items=2')
  .json()
  .args
  .items
  .map(n => ~~n * 4)
  .forEach(n => console.log(n))

Test if obj exist, similar to lodash/get or optional chaining

const obj = {}
exist = await resolve(obj).foo.bar().buz[28]

About

Skip hoops with promises, make async code sync-ish looking (it is still async)

Topics

Resources

License

Security policy

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published