-
-
Notifications
You must be signed in to change notification settings - Fork 72
Expand file tree
/
Copy pathutils.ts
More file actions
18 lines (15 loc) · 542 Bytes
/
utils.ts
File metadata and controls
18 lines (15 loc) · 542 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
import { createHash } from 'node:crypto'
import type { ImageConfig } from 'imagetools-core'
export const createBasePath = (base?: string) => {
return (base?.replace(/\/$/, '') || '') + '/@imagetools/'
}
export function generateImageID(config: ImageConfig, imageHash: string) {
return hash([JSON.stringify(config), imageHash])
}
export function hash(keyParts: Array<string | NodeJS.ArrayBufferView>) {
let hash = createHash('sha1')
for (const keyPart of keyParts) {
hash = hash.update(keyPart)
}
return hash.digest('hex')
}