path-is-inside

WebJar for path-is-inside

License

License

MIT
Categories

Categories

IDE Development Tools
GroupId

GroupId

org.webjars.npm
ArtifactId

ArtifactId

path-is-inside
Last Version

Last Version

1.0.2
Release Date

Release Date

Type

Type

jar
Description

Description

path-is-inside
WebJar for path-is-inside
Project URL

Project URL

http://webjars.org
Source Code Management

Source Code Management

https://github.com/domenic/path-is-inside

Download path-is-inside

How to add to project

<!-- https://jarcasting.com/artifacts/org.webjars.npm/path-is-inside/ -->
<dependency>
    <groupId>org.webjars.npm</groupId>
    <artifactId>path-is-inside</artifactId>
    <version>1.0.2</version>
</dependency>
// https://jarcasting.com/artifacts/org.webjars.npm/path-is-inside/
implementation 'org.webjars.npm:path-is-inside:1.0.2'
// https://jarcasting.com/artifacts/org.webjars.npm/path-is-inside/
implementation ("org.webjars.npm:path-is-inside:1.0.2")
'org.webjars.npm:path-is-inside:jar:1.0.2'
<dependency org="org.webjars.npm" name="path-is-inside" rev="1.0.2">
  <artifact name="path-is-inside" type="jar" />
</dependency>
@Grapes(
@Grab(group='org.webjars.npm', module='path-is-inside', version='1.0.2')
)
libraryDependencies += "org.webjars.npm" % "path-is-inside" % "1.0.2"
[org.webjars.npm/path-is-inside "1.0.2"]

Dependencies

There are no dependencies for this project. It is a standalone project that does not depend on any other jars.

Project Modules

There are no modules declared in this project.

Is This Path Inside This Other Path?

It turns out this question isn't trivial to answer using Node's built-in path APIs. A naive indexOf-based solution will fail sometimes on Windows, which is case-insensitive (see e.g. isaacs/npm#4214). You might then think to be clever with path.resolve, but you have to be careful to account for situations whether the paths have different drive letters, or else you'll cause bugs like isaacs/npm#4313. And let's not even get started on trailing slashes.

The path-is-inside package will give you a robust, cross-platform way of detecting whether a given path is inside another path.

Usage

Pretty simple. First the path being tested; then the potential parent. Like so:

var pathIsInside = require("path-is-inside");

pathIsInside("/x/y/z", "/x/y") // true
pathIsInside("/x/y", "/x/y/z") // false

Paths are considered to be inside themselves:

pathIsInside("/x/y", "/x/y"); // true

OS-Specific Behavior

Like Node's built-in path module, path-is-inside treats all file paths on Windows as case-insensitive, whereas it treats all file paths on *-nix operating systems as case-sensitive. Keep this in mind especially when working on a Mac, where, despite Node's defaults, the OS usually treats paths case-insensitively.

In practice, this means:

// On Windows

pathIsInside("C:\\X\\Y\\Z", "C:\\x\\y") // true

// On *-nix, including Mac OS X

pathIsInside("/X/Y/Z", "/x/y") // false

Versions

Version
1.0.2
1.0.1