npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@disqada/pathfinder

v3.0.0

Published

Easily find files in chosen directories in your project

Downloads

71

Readme

PathFinder

Badges

github npm

version monthly downloads

test Generate and Deploy documentation semantic-release

Table of Contents

About

This tool was made to be able to find file paths using only their names, or getting all the paths of files with "hello" word in their names. The file paths you want to get later must be stored first, this will usually be done at the beginning of the program.

Learn

Check the Getting started guide for first time usage.

License

Copyright © 2023 DisQada

This tool is licensed under the Apache License, Version 2.0.
See the LICENSE file for more information.

Getting started

Store paths

The first thing to do when using this tool is to store all the paths that will be required later on in some other file

To store the wanted file paths, use the function storeFolderPaths() and specify the array of directories to store their file paths.

Store all the paths (once) at the beginning of the discord bot (or application)

Let's say that this is out workspace

<root>
  ├── package.json
  ├── src
  │     ├── a.js
  │     └── b.js
  └── data
        └── a.json

We use this code to store the paths of all files in the src and data folder

import { storeFolderPaths } from '@disqada/pathfinder'
storeFolderPaths(['src', 'data'])

Now we'll have the following paths stored successfully

The file paths are stored in order

.../src/a.js
.../src/b.js
.../data/a.json

Find paths

In another file in the middle of some function, you want to require a module of one of the files stored earlier, you remember it's name but you don't remember it's location and you don't want to modify the path in the require function every time you move one of the files

Here is where this tools comes to help, if you only know the name of the file then you can easily fetch it's full path using the function findPath() or findPaths()

Both functions work the same, it's just that filePath() returns the first match while filePaths() returns them all in an array

Let's say that we want to require the file src/b.js, we use the following code for that

import { findPath } from '@disqada/pathfinder'

const filePath = findPath({ name: 'b' })
const { ... } = (await import(filePath.fullPath)).default

With that we successfully required the module and used it just like normal but without the need to know it's full path

If you have multiple files with the same name, then check Same file names guide

Same file names

Let's say that this is out workspace

<root>
  ├── package.json
  └── src
        ├── a.js
        └── a.json

Now let's say we've written some code and we want to require the file src/a.json, we can use the same code, but there is a problem, the function is returning the path of src/a.js instead of src/a.json because it was stored before and the function will return the first match

To work around this, we have couple of choices

Renaming files

Renaming one of the files to another name will solve this problem, but it's not always something we can do

Receiving all matches

Instead of getting one file path, we can get an array of all the file paths of that name by changing the function from findPath() to findPaths()

import { findPaths } from '@disqada/pathfinder'

const filePaths = findPaths({ name: 'a' })
const { ... } = (await import(filePaths[1].fullPath)).default

This will solve the problem, for now, what if we then added another file named a.js somewhere in our project or the order of the files changed (files order in the workspace or the order of storing)?

Filtering by different properties

More than filtering property can be used at the same time

Extension difference

The best way to work around the problem of file name conflict is by adding more details to the FilterOptions object parameter

Both files have the same file name and path except for only the extension, so we can specify the extension property in the FilterOptions parameter to get our desired file

import { findPath } from '@disqada/pathfinder'

const filePath = findPath({ extension: 'json' })
const { ... } = (await import(filePath.fullPath)).default

Folder difference

If our workspace was instead like this, where both the files' name and extension are identical, but they're in different folder

<root>
  ├── package.json
  ├── src
  │     └── a.js
  └── data
        └── a.js

Then the way we'll get the correct path is as follows

import { findPath } from '@disqada/pathfinder'

const filePath = findPath({ folder: 'data' })
const { ... } = (await import(filePath.fullPath)).default