Saber2pr's Blog

获取文件夹名

出自 webpack 插件 enhanced-resolve:

CachedInputFileSystem

const dirname = path => {
  let idx = path.length - 1
  while (idx >= 0) {
    const c = path.charCodeAt(idx)
    // slash or backslash
    if (c === 47 || c === 92) break
    idx--
  }
  if (idx < 0) return ''
  return path.slice(0, idx)
}