Function: isWithin()
ts
function isWithin(directory, path): boolean;检查路径是否在指定目录内。
Parameters
| Parameter | Type | Description |
|---|---|---|
directory | string | 基准目录 |
path | string | 要检查的路径 |
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') // => falseSince
1.0.0