You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP
Socket
Book a DemoInstallSign in
Socket

look-it-up

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

look-it-up

Find a file or directory by walking up parent directories recursively. Zero dependency.

2.1.0
latest
Source
npmnpm
Version published
Maintainers
1
Created
Source

look-it-up

Find a file or directory by walking up parent directories recursively. Zero dependency.

npm github workflow Codecov branch libera manifesto

Install

npm install look-it-up

Usage

import { existsSync } from 'fs'
import { join } from 'path'
import { lookItUp, lookItUpSync, exists } from 'look-it-up'

const contains = async (file, dir) => (await exists(join(dir, file))) ? dir : null
const containsSync = (file, dir) => existsSync(join(dir, file) ? dir : null

;(async () => {
  await lookItUp('.zshrc') //=> '~/.zshrc'

  await lookItUp(dir => containsSync('.zshrc', dir)) //=> '~'

  await lookItUp(async dir => await contains('.zshrc', dir)) //=> '~'
})()

lookItUpSync('.zshrc') //=> '~/.zshrc'

lookItUpSync(dir => containsSync('.zshrc', dir)) //=> '~'

API

declare type MatcherResult = string | null | symbol
declare type Matcher = string | ((dir: string) => MatcherResult | Promise<MatcherResult>)
declare type MatcherSync = string | ((dir: string) => MatcherResult)

declare const lookItUp: (matcher: Matcher, dir?: string) => Promise<string | null>

declare const lookItUpSync: (matcher: MatcherSync, dir?: string) => string | null | never

declare const exists: (path: string) => Promise<boolean>
declare const stop: unique symbol

export { exists, lookItUp, lookItUpSync, stop }

License

MIT License © 2021 Exuanbo

Keywords

look-up

FAQs

Package last updated on 05 Dec 2021

Did you know?

Socket

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