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

iotdb-fs

v2.1.5

Published

POP file system operations

Downloads

68

Readme

iotdb-fs

Pipeline Oriented Programming (POP) FS functions

Examples

There is sample code in samples/fs.js.

All examples set up with:

const _ = require("iotdb-helpers")
const fs = require("iotdb-fs")

Note that this can probably be used async style, but I haven't tried it

let self;

self = await fs.list({ path: "." })
self = await fs.all(fs.read.json)(self)

console.log(self.jsons)

fs.all: apply a function to all self.paths

The results are returned in:

  • self.jsons - all valid JSON results
  • self.documents - all valid documents
  • self.outputs - all results

Each output looks like:

  • self.path - the path
  • self.json - JSON document, if any
  • self.document - document, if any
  • self.document_media_type - media type, if any
  • self.error - error reported, if any

read all JSON files

Failures will reported in self.outputs. sd.jsons will only contain files successfully read

_.promise.make({
    path: ".",
    fs$filter_name: name => name.endsWith(".json"),
})
    .then(fs.list)
    .then(fs.all(fs.read.json))
    .then(sd => console.log("+", "ok", sd.jsons))

read all documents files

_.promise.make({
    path: ".",
})
    .then(fs.list)
    .then(fs.all(fs.read.utf8))
    .then(sd => console.log("+", "ok", sd.documents))

fs.list: list contents of a folder

single folder

_.promise.make({
    path: ".",
})
    .then(fs.list)
    .then(sd => console.log("+", "ok", sd.paths))

recursive

_.promise.make({
    path: ".",
})
    .then(fs.list.recursive)
    .then(sd => console.log("+", "ok", sd.paths))

filter

filter checks the filename. filter_path is also available.

This will only return files named *.json.

_.promise.make({
    path: ".",
    fs$file_name: name => name.endsWith(".json"),
})
    .then(fs.list.recursive)
    .then(sd => console.log("+", "ok", sd.paths))

parer

parer checks the filename; if it does not match that particular file will not be considered for recursion. parer_path is also available.

In the following examples, files in the .git folder are ignored (note that the .git folder itself will be listed).

_.promise.make({
    path: ".",
    fs$parer_name: name === ".git",
})
    .then(fs.list.recursive)
    .then(sd => console.log("+", "ok", sd.paths))

search depth first

_.promise.make({
    path: ".",
    fs$parer_name: name === ".git",
})
    .then(fs.list.depth_first)
    .then(sd => console.log("+", "ok", sd.paths))

sort names

_.promise.make({
    path: ".",
    fs$sorter: fs.sorter.natural_ignore_case,
})
    .then(fs.list)
    .then(sd => console.log("+", "ok", sd.paths))

Options (so far) are:

  • fs.sorter.natural - A, B, C, a, b, c,
  • fs.sorter.natural_ignore_case - A, a, B, b, C, c

We need to add an option for a locale-sensitive sort

fs.make.directory: make directories

Note that no error is reported if the folder already exists

_.promise.make({
    path: "delete-me",
})
    .then(fs.make.directory.parent)

fs.make.directory.parent - make parent folder

_.promise.make({
    path: "delete-me/write-json.json",
    json: { "hello": "world" },
})
    .then(fs.make.directory.parent)
    .then(fs.write.json)

fs.read - read files

Reading documents will modify:

  • self.document
  • self.document_media_type

The document may be a String or Buffer depending on the function you choose.

The one except is fs.read.json, that returns its result in self.json

fs.read - prefer versions below

fs.read.buffer - read into buffer

fs.read.json - read into JSON

_.promise.make({
    path: "info.json",
})
    .then(fs.read.json)
    .then(sd => console.log("+", "ok", sd.json))

fs.read.json -- magic JSON reading

This will work with .csv, .txt and .yaml files, as well as "-" for stdin.

You must independently install js-yaml and/or csvtojson according to your needs.

fs.read.utf8 - read UTF-8 document

_.promise.make({
    path: "doc.txt",
})
    .then(fs.read.utf8)
    .then(sd => console.log("+", "ok", sd.document_media_type, sd.document))

fs.read.stdin - read stdin

fs.write

fs.write.utf8: write UTF-8 document

_.promise.make({
    path: "write.txt",
    document: "Hello, world / 你好,世界\n",
})
    .then(fs.make.directory.parent)
    .then(fs.write.utf8)
    .then(sd => console.log("+", "ok", sd.path))

fs.write.buffer: write Buffer

_.promise.make({
    path: "write.txt",
    document: Buffer.from("Hello, world / 你好,世界\n", "utf-8"),
})
    .then(fs.make.directory.parent)
    .then(fs.write.buffer)
    .then(sd => console.log("+", "ok", sd.path))

fs.remove: remove file

Note that no error is reported if the file does not exist

fs.remove.directory: remove directory

Note that no error is reported if the directory does not exist

fs.remove.recursive: remove a bunch off stuff

NOT IMPLEMENTED

fs.tmpfile: make a temporary file

The path of the file will be placed in self.path. The file will disappear when the process exits.

fs.truncate: truncate a file

self.document_length can be used to control where the truncation happens

fs.exists: does it exist?

Test whether an object on the filesystem exists. self.exists will be set to true or false as appropriate

_.promise.make({
    path: "doc.txt",
})
    .then(fs.exists)
    .then(sd => console.log("+", "ok", sd.path, sd.exists)

fs.is.*: test file type

Test whether an object is of a certain type self.exists will be set to true or false as appropriate

fs.is.file: is it a normal file type

NOT IMPLEMENTED YET

_.promise.make({
    path: "doc.txt",
})
    .then(fs.is.file)
    .then(sd => console.log("+", "ok", sd.path, "is-file", sd.exists)

fs.is.file: is it a normal file type

NOT IMPLEMENTED YET

_.promise.make({
    path: ".",
})
    .then(fs.is.directory)
    .then(sd => console.log("+", "ok", sd.path, "is-directory", sd.exists)

fs.is.symbolic_link: is it a symbolic link

NOT IMPLEMENTED YET

_.promise.make({
    path: ".",
})
    .then(fs.is.symbolic_link)
    .then(sd => console.log("+", "ok", sd.path, "is-symbolic-link", sd.exists)

Contributed Software

For security and efficiency reason, some code from third party modules has been directly included in this module (in ./contrib)

  • https://www.npmjs.com/package/mkdirp