JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 214
  • Score
    100M100P100Q82220F
  • License ISC

Promise based path operations, such as read, write, find, fetch, and clean.

Package Exports

  • promise-path

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (promise-path) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

Promise Path

A collection of path based methods brought together as promises.

API

The API currently supports the following methods:

  • read
  • write
  • find
  • fetch
  • clean

Read

Read the contents of a file, and return the result as a promise.

var read = require('promise-path').read;

read('README.md', 'utf8')
    .then(function(contents) {
        console.log(contents);
    });

read('package.json')
    .then(JSON.parse)
    .then(function(json) {
        console.log(JSON.stringify(json), null, '  ');
    });

Write

Write contents to a file, and return a promise.

var write = require('promise-path').write;

var log = ['message 1', 'message 2', 'message 3'];
var file = 'output.log';
write(file, log.join('\n'))
    .then(function() {
        console.log('Contents written to', file);
    });

Find

Find files that match a pattern, and return a promise.

var find = require('promise-path').find;

find('/**/*.js')
    .then(function(files) {
        console.log('JS files:', files);
    });

Fetch

Retrieve a remote file, and return a promise.

var fetch = require('promise-path').fetch;

fetch('https://raw.githubusercontent.com/connected-web/remote-test/master/info.json')
    .then(function(contents) {
        console.log('Remote file:', contents);
    });

Clean

Remove local files and folders, and return a promise.

var clean = require('promise-path').clean;

clean(__dirname + '/temp')
    .then(function() {
        console.log('Temp directory has been removed');
    });

Run

Use child_process.exec to run a command, and return a promise.

var run = require('promise-path').run;

run('cat package.json')
    .then(function(result) {
        console.log('Error', result.error);
        console.log('Std out', result.stdout);
        console.log('Std err', result.stderr);
    });

Depdencies

  • glob
  • fs-extra
  • request

Development

Checkout the code.

npm install
npm test

Changelog

1.1.0

  • Added method with test: run

1.0.0

  • Initial release
  • Supported methods: read, write, find, fetch, clean
  • Created tests