Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

m-io

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

m-io

(Incomplete) replacement for q-io

  • 0.1.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
798
decreased by-62.34%
Maintainers
1
Weekly downloads
 
Created
Source

m-io

NPM version Travis Build Status Coverage Status

(Incomplete) replacement for q-io

This package is a replacement for the functions of q-io that I use in my projects. I have use q-io/fs a lot since it has functions like makeTree, listTree and removeTree. Furthermore, its read and write function work with strings by default, which makes it easier to read text files.

Sadly, q-io@1 depends on collections@1, which overwrites the function Array.prototype.find with an implementation that does not match the ES6-spec. This causes problems in jsdoc-parse. This is another example of why modifying objects you don’t own is a bad practice.

This problem could be solved by using q-io@2 instead of version 1. This version has other problems which were solved in version 1. It may be a silly feeling, but version 2 of q-io vseems not to receive too much care at the moment.

Since I do not use many functions, I have decided to write a drop-in replacement for my own purposes, and this is it: m-io. If you like this and want to provide more methods for your needs, please go ahead and make a PR.

Installation

npm install m-io

Usage

The following example demonstrates how to use this module:

var FS = require('m-io/fs')

// Create some files
FS.makeTree('city/germany')
  .then(() => FS.write('city/germany/darmstadt.md', 'Darmstadt is nice'))
  .then(() => FS.makeTree('city/usa'))
  .then(() => FS.write('city/usa/new-york.md', 'New York is huge'))
  .then(() => FS.makeTree('city/france'))
  .then(() => FS.write('city/france/paris.md', 'Olala'))

  // List files
  .then(() => FS.listTree('city', (filename, stats) => stats.isFile()))
  .then((filelist) => console.log('List files:', filelist.sort()))

  // List dirs and files
  .then(() => FS.listTree('city'))
  .then((list) => console.log('List dirs and files:', list.sort()))

  // Read file contents
  .then(() => FS.read('city/usa/new-york.md'))
  .then((nyc) => console.log('Read file contents:', nyc))

  // Remove subdir
  .then(() => FS.removeTree('city/usa'))
  .done(() => console.log('Done'))

This will generate the following output

List files: [ 'city/france/paris.md',
  'city/germany/darmstadt.md',
  'city/usa/new-york.md' ]
List dirs and files: [ 'city',
  'city/france',
  'city/france/paris.md',
  'city/germany',
  'city/germany/darmstadt.md',
  'city/usa',
  'city/usa/new-york.md' ]
undefined
Read file contents: New York is huge
Done

After deleting city/usa, the city-subtree looks liks this:


city
├─┬ france
│ └── paris.md
└─┬ germany
  └── darmstadt.md

API-reference

require("m-io/fs")

fs

.listTree(directoryPath, filter) ⇒ Promise.<Array.<string>>

Custom implementation of q-io/fs#listTree to avoid dependency on q-io

Kind: static method of fs
Returns: Promise.<Array.<string>> - a promise for the collector, that is fulfilled after traversal

ParamTypeDescription
directoryPathstringthe base path
filterfunctiona function that returns true, false or null to show that a file should be included or ignored and that a directory should be ignored completely (null)

.makeTree(aPath, [mode])

Replacement for q-io/fs#makeTree

Kind: static method of fs

ParamTypeDescription
aPathstringthe directory to be created
[mode]number(e.g. 0644)

.read(aPath)

Replacement for q-io/fs#read

Kind: static method of fs

Param
aPath

License

m-io is published under the MIT-license. See LICENSE.md for details.

Release-Notes

For release notes, see CHANGELOG.md

Contributing guidelines

See CONTRIBUTING.md.

FAQs

Package last updated on 22 Jul 2016

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc