Skip to content

Commit

Permalink
fix: rename inPath to includePath
Browse files Browse the repository at this point in the history
  • Loading branch information
zhangfisher committed Jan 16, 2025
1 parent ecd152d commit f2dfb67
Showing 1 changed file with 34 additions and 34 deletions.
68 changes: 34 additions & 34 deletions src/fs/inPath.ts → src/fs/includePath.ts
Original file line number Diff line number Diff line change
@@ -1,34 +1,34 @@
/**
*
* 判断某个文件夹或文件是否在指定的文件夹下
*
* const p1 = "c:/temp/a/b/c"
* const p2 = "d:/temp/a/b/c"
* const base = "c:/temp"
*
* includePath(p1,base) // true
* includePath(p2,base) // false
*
*
*
*/

import path from "path"


export function includePath(src: string, basePath: string): boolean {
// 将路径字符串转换为目录对象
let srcDir = path.normalize(src);
let baseDir = path.normalize(basePath);
return srcDir.startsWith(baseDir)
}



// const p1 = "c:/temp/a/b/c"
// const p2 = "d:/temp/c"
// const p3 = "d:/temp/a/b/c.zip"
// const base = "c:/temp"
// console.log(includePath(p1,base)) // true
// console.log(includePath(p2,base)) // false
// console.log(includePath(p3,base)) // false
/**
*
* 判断某个文件夹或文件是否在指定的文件夹下
*
* const p1 = "c:/temp/a/b/c"
* const p2 = "d:/temp/a/b/c"
* const base = "c:/temp"
*
* includePath(p1,base) // true
* includePath(p2,base) // false
*
*
*
*/

import path from "path"


export function includePath(src: string, basePath: string): boolean {
// 将路径字符串转换为目录对象
let srcDir = path.normalize(src);
let baseDir = path.normalize(basePath);
return srcDir.startsWith(baseDir)
}



// const p1 = "c:/temp/a/b/c"
// const p2 = "d:/temp/c"
// const p3 = "d:/temp/a/b/c.zip"
// const base = "c:/temp"
// console.log(includePath(p1,base)) // true
// console.log(includePath(p2,base)) // false
// console.log(includePath(p3,base)) // false

0 comments on commit f2dfb67

Please sign in to comment.