Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 400,000 packages pre-installed, including is-path-from-ancestor with all npm packages installed. Try it out:

var isPathFromAncestor = require("is-path-from-ancestor")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

is-path-from-ancestor v2.0.3

Check if a given path starts with parent directory reference

is-path-from-ancestor

npm version Build Status Coverage Status

A Node.js module to check if a given path starts with parent directory reference

const isPathFromAncestor = require('is-path-from-ancestor');

// On POSIX
isPathFromAncestor('../foo'); //=> true
isPathFromAncestor('foo'); //=> false

// On Windows
isPathFromAncestor('..\\foo'); //=> true

Installation

Use npm.

npm install is-path-from-ancestor

API

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 the path before checking.

// On POSIX

isPathFromAncestor('foo/../../'); //=> true
isPathFromAncestor('foo/../'); //=> false

License

Creative Commons Zero v1.0 Universal

Metadata

RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free