@brillout/docpress 0.15.10-commit-ef0b9a0 → 0.15.10-commit-b6b1605

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,34 @@
1
+ import { createHash } from 'node:crypto'
2
+
3
+ export type ContentMap = {
4
+ /**
5
+ * @returns key
6
+ */
7
+ add(title: string, sourceLength: number, content: string): string
8
+ get(key: string): string | undefined
9
+ }
10
+
11
+ export const createContentMap = (): ContentMap => {
12
+ const map = new Map<string, string>()
13
+
14
+ return {
15
+ add(title, length, content) {
16
+ const key = generateKey(`${title}_${length}`)
17
+ if (!map.has(key)) {
18
+ map.set(key, content)
19
+ }
20
+ return key
21
+ },
22
+ get(key) {
23
+ const val = map.get(key)
24
+ return val
25
+ },
26
+ }
27
+ }
28
+
29
+ const generateKey = (value: string) => {
30
+ const hash = createHash('md5').update(value).digest('hex')
31
+ return `#_#_${hash}_#_#`
32
+ }
33
+
34
+ export const contentMapKeyRE = /#_#_[0-9a-fA-F]{32}_#_#/g