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

@neodx/fs

v0.0.12

Published

File system helpers

Downloads

5,807

Readme

@neodx/fs

File system enhancements and common stuff.

API`s overview:

  • scan(path, ['*.js', '*.module.ts', '!*.test.{ts,js}']) - glob reader with multiple inputs support
  • ensureDir(path), ensureFile(path) - Safe file/dir creation with all required ancestors
  • exists(path), isFile(path), isDirectory(path) - Safe path checks
  • deepReadDir(path) - Deep version of readdir
  • parseJson(input), serializeJson(input) - Safe JSON parser and serializer with JSONC support
  • getFileHash(path), getHash(content) - Returns file hash based on its content (HEX)

API

scan

Glob-based (via tiny-glob) multiple patterns scanner with exclusion support

import { scan } from '@neodx/fs';

await scan(process.cwd(), ['*.js', '!*.config.js']);
await scan(process.cwd(), '**/*.ts', '**/*.js');

ensureFile(path) and ensureDir(path)

Recursively creates missed file or dir with all required ancestors if one of them is not exists.

Automatically avoid duplicated calls:

import { ensureFile, ensureDir } from '@neodx/fs';

// Everything works as expected
await Promise.all([
  ensureDir('foo/baz'),
  ensureFile('foo/bar/2.ts'),
  ensureDir('foo/bar'),
  ensureFile('foo/bar/1.ts'),
  ensureDir('foo')
]);

isFile, isDirectory, exists

The following APIs are useful for safe paths checking.

  • exists(path) - Returns true if the path exists
  • isFile(path) - Returns true if the path exists, and it's a file
  • isDirectory(path) - Returns true if the path exists, and it's a directory

deepReadDir(path, { absolute = false })

Returns flat list with all children's paths. Paths are relative by default.

import { deepReadDir, isFile } from '@neodx/fs';

const files = await deepReadDir(myPath);

for (const file of files) {
  if (await isFile(file)) {
    await doSmth(file);
  }
}

parseJson and serializeJson

import { parseJson, serializeJson } from '@neodx/fs';
import { writeFile, readFile } from 'fs/promises';

const json = parseJson(await readFile('tsconfig.json', 'utf-8'));

await writeFile(
  'tsconfig.json',
  serializeJson({
    ...json,
    compilerOptions: {
      ...json.compilerOptions,
      target: 'esnext'
    }
  }),
  'utf-8'
);

Inspired by fs-extra and others.