Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/shinnn/node-is-path-from-ancestor
Check if a given path starts with parent directory reference
https://github.com/shinnn/node-is-path-from-ancestor
javascript
Last synced: 27 days ago
JSON representation
Check if a given path starts with parent directory reference
- Host: GitHub
- URL: https://github.com/shinnn/node-is-path-from-ancestor
- Owner: shinnn
- Created: 2014-09-09T04:28:58.000Z (about 10 years ago)
- Default Branch: master
- Last Pushed: 2019-01-29T23:27:14.000Z (almost 6 years ago)
- Last Synced: 2024-10-04T19:04:41.321Z (about 1 month ago)
- Topics: javascript
- Language: JavaScript
- Homepage:
- Size: 55.7 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# is-path-from-ancestor
[![npm version](https://img.shields.io/npm/v/is-path-from-ancestor.svg)](https://www.npmjs.com/package/is-path-from-ancestor)
[![Build Status](https://travis-ci.com/shinnn/node-is-path-from-ancestor.svg?branch=master)](https://travis-ci.com/shinnn/node-is-path-from-ancestor)
[![Coverage Status](https://img.shields.io/coveralls/shinnn/node-is-path-from-ancestor.svg)](https://coveralls.io/github/shinnn/node-is-path-from-ancestor)A [Node.js](https://nodejs.org/) module to check if a given path starts with parent directory reference
```javascript
const isPathFromAncestor = require('is-path-from-ancestor');// On POSIX
isPathFromAncestor('../foo'); //=> true
isPathFromAncestor('foo'); //=> false// On Windows
isPathFromAncestor('..\\foo'); //=> true
```## Installation
[Use](https://docs.npmjs.com/cli/install) [npm](https://docs.npmjs.com/about-npm/).
```
npm install is-path-from-ancestor
```## API
```javascript
const isPathFromAncestor = require('is-path-from-ancestor');
```### isPathFromAncestor(*path*)
*path*: `string`
Return: `boolean`It returns `true` if *path* starts with `../` (POSIX) or `..\\` (Windows), otherwise returns `false`.
It [normalizes](https://nodejs.org/api/path.html#path_path_normalize_p) the path before checking.
```javascript
// On POSIXisPathFromAncestor('foo/../../'); //=> true
isPathFromAncestor('foo/../'); //=> false
```## License
[Creative Commons Zero v1.0 Universal](https://creativecommons.org/publicdomain/zero/1.0/deed)