Skip to content

Function: isWithin()

ts
function isWithin(directory, path): boolean;

检查路径是否在指定目录内。

Parameters

ParameterTypeDescription
directorystring基准目录
pathstring要检查的路径

Returns

boolean

如果路径在目录内则返回 true,否则返回 false

Example

ts
isWithin('/foo/bar', '/foo/bar/baz')     // => true
isWithin('/foo/bar', '/foo/bar')         // => true
isWithin('/foo/bar', '/foo/baz')         // => false
isWithin('/foo/bar', '/foo/bar/../baz')  // => false

Since

1.0.0

Released under the MIT License.