mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-16 02:44:51 +00:00
26 lines
730 B
TypeScript
26 lines
730 B
TypeScript
import { basename, extname } from 'pathe'
|
|
import { kebabCase, pascalCase } from 'scule'
|
|
|
|
export function getNameFromPath (path: string) {
|
|
return kebabCase(basename(path).replace(extname(path), '')).replace(/["']/g, '')
|
|
}
|
|
|
|
export function uniqueBy <T, K extends keyof T> (arr: T[], key: K) {
|
|
const res: T[] = []
|
|
const seen = new Set<T[K]>()
|
|
for (const item of arr) {
|
|
if (seen.has(item[key])) { continue }
|
|
seen.add(item[key])
|
|
res.push(item)
|
|
}
|
|
return res
|
|
}
|
|
|
|
export function hasSuffix (path: string, suffix: string) {
|
|
return basename(path).replace(extname(path), '').endsWith(suffix)
|
|
}
|
|
|
|
export function getImportName (name: string) {
|
|
return pascalCase(name).replace(/[^\w]/g, r => '_' + r.charCodeAt(0))
|
|
}
|