1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | exports.kebab = exports.snake = exports.pascal = exports.constant = exports.camel = void 0;
|
4 | const Case = require("case");
|
5 | const withCache = (func) => (text) => Cache.fetch(text, func);
|
6 | exports.camel = withCache(Case.camel);
|
7 | exports.constant = withCache(Case.constant);
|
8 | exports.pascal = withCache(Case.pascal);
|
9 | exports.snake = withCache(Case.snake);
|
10 | exports.kebab = withCache(Case.kebab);
|
11 | class Cache {
|
12 | static fetch(text, func) {
|
13 |
|
14 | const cacheKey = CacheKey.for(func);
|
15 | let cache = this.CACHES.get(cacheKey);
|
16 | if (cache == null) {
|
17 |
|
18 | cache = new Map();
|
19 | this.CACHES.set(cacheKey, cache);
|
20 | }
|
21 |
|
22 | const cached = cache.get(text);
|
23 | if (cached != null) {
|
24 | return cached;
|
25 | }
|
26 |
|
27 | const result = func(text);
|
28 | cache.set(text, result);
|
29 | return result;
|
30 | }
|
31 | constructor() { }
|
32 | }
|
33 |
|
34 | Cache.CACHES = new WeakMap();
|
35 | class CacheKey {
|
36 | static for(data) {
|
37 | const entry = this.STORE.get(data)?.deref();
|
38 | if (entry != null) {
|
39 | return entry;
|
40 | }
|
41 | const newKey = new CacheKey();
|
42 | this.STORE.set(data, new WeakRef(newKey));
|
43 | return newKey;
|
44 | }
|
45 | constructor() { }
|
46 | }
|
47 |
|
48 | CacheKey.STORE = new Map();
|
49 |
|
\ | No newline at end of file |