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

fs-funcs

v0.3.0

Published

A very limited subset of fs functions I use every day

Downloads

24

Readme

fs-funcs

A very limited subset of fs functions I use every day

Install

npm i fs-funcs

Package on npm

API


exec-file(file, [args], [options])

Execute the file

| Argument | Action | | :------ | :------- | | file | the executed file | | args | the list of string arguments | | options | optional options, default to { maxBuffer: 20971520 } |

args can be an Array or a String

The default maxBuffer is 20 Mo instead of 200 ko

result is an object with two properties { stdout, stderr }

The EOF chars \n or \r\n are removed from the returned strings stdout and stderr

const execfile = require('fs-funcs/exec-file')

execfile('echo', ['one', 'two']).then(result => {
  // one two
  console.log(result.stdout)
})

execfile('echo', 'abc def').then(result => {
  // abc def
  console.log(result.stdout)
})

exec(command, [options])

Execute the command

| Argument | Action | | :------ | :------- | | command | the executed command | | options | optional options, default to { maxBuffer: 20971520 } |

The default maxBuffer is 20 Mo instead of 200 ko

result is an object with two properties { stdout, stderr }

The EOF chars \n or \r\n are removed from the returned strings stdout and stderr

const exec = require('fs-funcs/exec')

exec('echo one two').then(result => {
  // one two
  console.log(result.stdout)
})

exist(path, [nofollow])

Check if path exists

| Argument | Action | | :------ | :------- | | path | the tested path | | nofollow | optional nofollow, default to false. If true, test the symlink and not is target |

const exist = require('fs-funcs/exist')

exist(__filename).then(result => {
  // true
  console.log(result)
})

first-bytes(path, [length])

Get a Buffer with the first bytes of a file

| Argument | Action | | :------ | :------- | | path | the file path | | length | optional length, default to 15 |

const firstbytes = require('fs-funcs/first-bytes')

firstbytes('/path/to/file').then(result => {
  // <Buffer 89 50 4e 47 0d 0a 1a 0a 00 00 00 0d 49 48 44>
  console.log(result)
})

get-filesize(path)

Get the size of a file

| Argument | Action | | :------ | :------- | | path | the file path |

const getfilesize = require('fs-funcs/get-filesize')

getfilesize('/path/to/file').then(result => {
  // 54318
  console.log(result)
})

is-directory(path, [nothrow])

Check if path is a directory

| Argument | Action | | :------ | :------- | | path | the tested path | | nothrow | optional nothrow, default to false. If true, resolve to false instead of throw an error |

const isdirectory = require('fs-funcs/is-directory')

isdirectory('/path/to/directory').then(result => {
  // true
  console.log(result)
})

isdirectory('/path/to/file')
.then(result => {})
.catch(err => {
  // "path" argument must target a directory
  console.log(err.message)
})

isdirectory('/path/to/file', true).then(result => {
  // false
  console.log(result)
})

is-file(path, [nothrow])

Check if path is a file

| Argument | Action | | :------ | :------- | | path | the tested path | | nothrow | optional nothrow, default to false. If true, resolve to false instead of throw an error |

const isfile = require('fs-funcs/is-file')

isfile('/path/to/file').then(result => {
  // true
  console.log(result)
})

isfile('/path/to/directory')
.then(result => {})
.catch(err => {
  // "path" argument must target a file
  console.log(err.message)
})

isfile('/path/to/directory', true).then(result => {
  // false
  console.log(result)
})

is-symlink(path, [nothrow])

Check if path is a symlink

| Argument | Action | | :------ | :------- | | path | the tested path | | nothrow | optional nothrow, default to false. If true, resolve to false instead of throw an error |

const issymlink = require('fs-funcs/is-symlink')

issymlink('/path/to/symlink').then(result => {
  // true
  console.log(result)
})

issymlink('/path/to/file')
.then(result => {}).catch(err => {
  // "path" argument must target a symlink
  console.log(err.message)
})

issymlink('/path/to/file', true).then(result => {
  // false
  console.log(result)
})

mkdir(path, [pop])

Recursively mkdir

| Argument | Action | | :------ | :------- | | path | the created path | | pop | optional pop, default to false. If true, remove the last part of the path |

const mkdir = require('fs-funcs/mkdir')

mkdir('/path/to/directory').then(result => {
  // /path/to/directory
  console.log(result)
})

mkdir('/path/to/file', true).then(result => {
  // /path/to
  console.log(result)
})

read-json(path)

Read and serialize a JSON file

| Argument | Action | | :------ | :------- | | path | the file path |

const readjson = require('fs-funcs/read-json')

readjson('/path/to/json').then(result => {
  // {a:123, b:"abc"}
  console.log(result)
})

rm(path)

Remove a path

| Argument | Action | | :------ | :------- | | path | the removed path |

const rm = require('fs-funcs/rm')

rm('/path/to/directory').then(result => {
  // /path/to/directory
  console.log(result)
})

stat(path, [nofollow])

Get some data about path

| Argument | Action | | :------ | :------- | | path | the tested path | | nofollow | optional nofollow, default to false. If true, test the symlink and not is target |

The booleans readable, writable and executable are related to the user privileges

const stat = require('fs-funcs/stat')

stat('/path/to/file').then(result => {
  /*
  {
    file: true,
    directory: false,
    symlink: false,
    path: '/path/to/file',
    dirname: '/path/to',
    basename: 'file',
    size: 123,
    readable: true,
    writable: true,
    executable: false
  }
  */
  console.log(result)
})

stat('/path/to/directory').then(result => {
  /*
  {
    file: false,
    directory: true,
    symlink: false,
    path: '/path/to/directory',
    dirname: '/path/to',
    basename: 'directory',
    size: 7,
    readable: true,
    writable: true,
    executable: true
  }
  */
  console.log(result)
})

write-json(path, data, [minify])

Write a prettified JSON file. The directory tree is created if needed

| Argument | Action | | :------ | :------- | | path | the created path | | data | the stringified data | | minify | optional minify, default to false. If true, the JSON will not be beautified |

const writejson = require('fs-funcs/write-json')

writejson('/path/to/json', {a:123, b:"abc"}).then(result => {
  // {a:123, b:"abc"}
  console.log(result)
})

License

MIT