1.0.1 • Published 9 years ago
get-first-from-filepath v1.0.1
Get the very first directory name from file path
./foo/bar/baz
->foo
or../a/b/c
->../a
Useful when you just want first real directory from given file path
Install
npm i --save get-first-from-filepath
npm test
Usage
For more use-cases see the tests
var getFirstFromFilepath = require('get-first-from-filepath');
getFirstFromFilepath('foo/bar/baz');
//=> 'foo'
getFirstFromFilepath('/foo/bar/baz');
//=> 'foo'
getFirstFromFilepath('./foo/bar/baz');
//=> 'foo'
getFirstFromFilepath('../foo/bar/baz');
//=> '../foo'
getFirstFromFilepath('..foo/bar/baz');
//=> '..foo'
Author
Charlike Mike Reagent
License
Copyright (c) 2015 Charlike Mike Reagent, contributors.
Released under the MIT
license.
Powered and automated by kdf, February 27, 2015