1.0.2 • Published 8 years ago

ufr v1.0.2

Weekly downloads
2
License
LGPL-3.0
Repository
github
Last release
8 years ago

Universal File Resolver

JavaScript Promise based library to quickly find the first accessible file in a set of filenames and paths. Resolves both local and http(s) url paths.

Installation and usage

npm install --save ufr
const resolve = require('ufr');

const filename = 'resolve.js';

const paths = [
    '/home/user/',
    'https://example.com/',
    'https://github.com/StefanHamminga/universal-file-resolver.js/raw/master/',
    '/tmp/'
];

resolve(filename, paths).then(match => {
        console.log("Found your file:\n", match);
    }).catch(error => {
        console.log(error);
    });

/* Output:
Found your file:
 { name: 'https://github.com/StefanHamminga/universal-file-resolver.js/raw/master/resolve.js',
  path: 'https://github.com/StefanHamminga/universal-file-resolver.js/raw/master/',
  filename: 'resolve.js',
  url: true }
*/

Try the above running example.js in this repository or online: Tonic.

Arguments

Input

Arg.TypesDescription
filenameString, ArrayEither one filename or an array of filenames to test. Required.
pathsString, Array, undefinedSingle path, array of paths or empty.

Output

// Resolve:

Object {
    name:     String  - 'Merged and resolved path to valid file'
    path:     String  - 'Path, as provided, for successfull resolve'
    filename: String  - 'Lucky filename'
    url:      Boolean - 'Was this resolved as an URL?'
}

// Reject:

Error { ... }

Notes and license

This project is available on GitHub and npm.

The project is licensed as LGPL v3.0 and may be freely used and distributed as such.

Copyright 2016 Stefan Hamminga - prjct.net