2021-10-26 12:59:05 +00:00
|
|
|
import { createHash } from 'crypto'
|
|
|
|
|
|
|
|
export function uniq<T> (arr: T[]): T[] {
|
|
|
|
return Array.from(new Set(arr))
|
|
|
|
}
|
|
|
|
|
|
|
|
// Copied from vue-bundle-renderer utils
|
|
|
|
const IS_JS_RE = /\.[cm]?js(\?[^.]+)?$/
|
|
|
|
const IS_MODULE_RE = /\.mjs(\?[^.]+)?$/
|
|
|
|
const HAS_EXT_RE = /[^./]+\.[^./]+$/
|
2021-11-08 10:34:39 +00:00
|
|
|
const IS_CSS_RE = /\.(?:css|scss|sass|postcss|less|stylus|styl)(\?[^.]+)?$/
|
2021-10-26 12:59:05 +00:00
|
|
|
|
|
|
|
export function isJS (file: string) {
|
|
|
|
return IS_JS_RE.test(file) || !HAS_EXT_RE.test(file)
|
|
|
|
}
|
|
|
|
|
|
|
|
export function isModule (file: string) {
|
|
|
|
return IS_MODULE_RE.test(file) || !HAS_EXT_RE.test(file)
|
|
|
|
}
|
|
|
|
|
|
|
|
export function isCSS (file: string) {
|
|
|
|
return IS_CSS_RE.test(file)
|
|
|
|
}
|
|
|
|
|
|
|
|
export function hashId (id: string) {
|
|
|
|
return '$id_' + hash(id)
|
|
|
|
}
|
|
|
|
|
|
|
|
export function hash (input: string, length = 8) {
|
|
|
|
return createHash('sha256')
|
|
|
|
.update(input)
|
|
|
|
.digest('hex')
|
|
|
|
.substr(0, length)
|
|
|
|
}
|