fliphub-resolve
v0.0.12
Published
resolve objects, arrays, strings, to app, monorepo, or custom scopes
Downloads
37
Maintainers
Readme
🎯 fliphub-resolve
📦 usage
yarn add fliphub-resolve
npm i fliphub-resolve --save
- if it's a monorepo package, it will default resolve relative to the monorepo root
- otherwise, it will default resolve relative to the the package root
- the root can be set once, and all other resolving using it will default to that root
- the root can be set for multiple scopes
flipfile used to detect
🥕 mono-root to find root
const resolve = require('fliphub-resolve')
resolve('./path-from-root')
📘 examples
scope
// resolve all with this scope
const localResolver = resolve.scoped('local', __dirname)
// default is monorepo
const monoResolver = resolve.scoped('mono')
// how many folders to check up
const appResolver = resolve.scoped('app').setRoot(1)
- a
number
can be passed for shorthanddepth
obj
- forProps, fn
const obj = {
fixtures: './fixtures',
simple: './fixtures/somePath',
simplejs: './fixtures/somePath.js',
}
// all properties resolved to absolute paths, if they are relative
const resolvedObj = resolve.obj(obj)
arr
- resolves objects, arrays, with multiple scopes.
const arr = ['./fixtures', './fixtures/somePath']
// all relative strings in the array are resolved
const resolvedArr = resolver.arr(arr)
auto
const arr = ['./fixtures', './fixtures/somePath']
const obj = {
fixtures: './fixtures',
simple: './fixtures/somePath',
simplejs: './fixtures/somePath.js',
}
// will auto-resolve based on type
const resolvedArr = resolver(arr)
const resolvedObj = resolve(obj)
resolve-scoped
// or resolve with a scope
const apps = resolve.scope('app')('./eh.js')
const monos = resolve.scope('mono')('./eh.js')
const locals = resolve.scope('app')(arr)