@danielcobo/path v1.0.0
path
Extend native nodeJS path module
๐งญ Table of contents
- โจ Benefits
- ๐ Requierments
- ๐ Quickstart
- ๐ Documentation
- ๐ Troubleshooting
- ๐ค Contributing
- ๐งช Testing
- โ๏ธ License
โจ Benefits
- Extends native path module
- Normalizes naming
๐ Requierments
To use this package you will need:
๐ Quickstart
Install
NodeJS
Install using the terminal:
npm install @danielcobo/path
Require the module:
const path = require('@danielcobo/path');
Note: In case you're wondering, @danielcobo/ is just a namespace scope - an NPM feature. Scopes make it easier to name modules and improve security.
Browser
Declare it as a global variable named path by including this script before any script you want to use it in:
<script src="https://cdn.jsdelivr.net/npm/@danielcobo/path@1/dist/iife/path.min.js"></script>
Or import it as an ECMAScript module:
import * as path from 'https://cdn.jsdelivr.net/npm/@danielcobo/path@1/dist/esm/path.min.js';
Also, feel free to download the file if you prefer not to use jsdelivr. In that case just replace the url with the relative file path.
Example use
path.byDepth('have', 'have/a/nice/day', 'have/a/sundae'); //['have','have/a/sundae','have/a/nice/day']
path.dotfile("dir/.git"); //'.git'
path.ext('./ext.js'); //'.js'
path.file('./file.js'); //'file.js'
path.filename('./file.js'); //'file.js'
path.filter(['./hello.txt', './file.js'], '.txt'); //['./hello.txt']
path.isFile('./someFile.js'); //true
path.lvls(['hello', 'foo/bar', 'hello/world', 'hello/world/tidy/']);
/*
[
['hello'],
['foo/bar', 'hello/world'],
['hello/world/tidy/']
]
*/
path.parent('vanilla/chocolate/mint'); //'vanilla/chocolate'
path.rmExt('whatisthis.js'); //'.js'
path.separator = path.sep; //'/' or '\' on Win
path.tree('vanilla/chocolate/mint'); //'vanilla/chocolate/mint'
For details see documentation below.
๐ Documentation
.tree()
Returns tree part of path
Name | Type | Default | Description |
---|---|---|---|
str | string | Path |
Returns
Type | Description |
---|---|
string | Tree |
Source: src/tree.js:5
.rmExt()
Remove file extension
Name | Type | Default | Description |
---|---|---|---|
path | string |
Returns
Type | Description |
---|---|
string |
Source: src/rmExt.js:1
.parent()
Get parent folder
Name | Type | Default | Description |
---|---|---|---|
str | string | Path |
Returns
Type | Description |
---|---|
string | Parent folder |
Source: src/parent.js:5
.lvls()
Sorts paths by depth
Name | Type | Default | Description |
---|---|---|---|
paths | Array<string> |
Returns
Type | Description |
---|---|
Array<Array> |
Source: src/lvls.js:3
.isFile()
True/false if path is a file
Name | Type | Default | Description |
---|---|---|---|
path | string |
Returns
Type | Description |
---|---|
boolean |
Source: src/isFile.js:4
.filter()
Filter by file extension/s or function
Name | Type | Default | Description | ||
---|---|---|---|---|---|
paths | string | Array<string> | |||
filters | string | Array<string> | function | ||
whitelist | boolean | true | True/false for whitelist/blacklist |
Returns
Type | Description |
---|---|
Array<string> | Paths |
Source: src/filter.js:3
.file()
Get filename from path (incl. extension)
Name | Type | Default | Description |
---|---|---|---|
str | string | Path |
Returns
Type | Description |
---|---|
string |
Source: src/file.js:3
.dotfile()
Get dotfile in path
Name | Type | Default | Description |
---|---|---|---|
str | string | Path |
Returns
Type | Description |
---|---|
string | In path |
Source: src/dotfile.js:3
.byDepth()
Get paths by depth (number of path separators). Shallow to deepest. Will also sort by name, but lexicographically (numbers should be left padded by zero)
Name | Type | Default | Description |
---|---|---|---|
paths | Array<string> |
Returns
Type | Description |
---|---|
Array<string> | By depth |
Source: src/byDepth.js:3
๐ Troubleshooting
If you run into trouble or have questions just submit an issue.
๐ค Contributing
Anyone can contribute
Contributions come in many shapes and sizes. All are welcome. You can contribute by:
- asking questions
- suggesting features
- sharing this repo with friends
- improving documentation (even fixing typos counts ๐)
- providing tutorials (if you do, please let me know, I would love to read them)
- improving tests
- contributing code (new features, performance boosts, code readability improvements..)
Rules for contributions
General guidelines:
- there are no dumb questions
- be polite and respectful to others
- do good
When coding remember:
- working > maintainability > performance
- best code is no code
- be descriptive when naming
- keep it DRY
- do test
Contribution licence: All contributions are considered to be under same license as this repository.
๐งช Testing
Testing suite: ๐ Jest | Test command: npm test
Mutation testing suite: ๐ฝ Stryker Mutator | Mutation test command: npm run mutation
If you intend to develop further or contribute code, then please ensure to write and use testing. Strive for 100% code coverage and high mutation scores. Mutation score 100 is great, but it's not always neccessary (if there are valid reasons).
โ๏ธ License
3 years ago