keyv-dir-store 1.0.0 → 1.0.1
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.
- package/README.md +2 -2
- package/dist/index.js +1 -1
- package/index.spec.ts +2 -2
- package/index.ts +4 -4
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -133,8 +133,8 @@ Creates a new KeyvDirStore instance.
|
|
|
133
133
|
- `options` (object, optional):
|
|
134
134
|
- `cache` (Map, optional): Custom cache Map to use
|
|
135
135
|
- `filename` (function, optional): Custom filename generator function
|
|
136
|
-
- `prefix` (string, optional): Path prefix prepended to every key (e.g. `'data/'`)
|
|
137
|
-
- `suffix` (string, optional): Path suffix appended to every key (
|
|
136
|
+
- `prefix` (string, optional): Path prefix prepended to every key (e.g. `'data/'`). Defaults to `''`
|
|
137
|
+
- `suffix` (string, optional): Path suffix appended to every key (e.g. `'.json'`). Defaults to `''`
|
|
138
138
|
|
|
139
139
|
#### Example with Custom Options
|
|
140
140
|
|
package/dist/index.js
CHANGED
|
@@ -359,7 +359,7 @@ class KeyvDirStore {
|
|
|
359
359
|
this.#dir = dir;
|
|
360
360
|
this.#filename = filename ?? this.#defaultFilename;
|
|
361
361
|
this.prefix = prefix ?? "";
|
|
362
|
-
this.suffix = suffix ?? "
|
|
362
|
+
this.suffix = suffix ?? "";
|
|
363
363
|
}
|
|
364
364
|
#defaultFilename(key) {
|
|
365
365
|
const readableName = import_sanitize_filename.default(key).slice(0, 16);
|
package/index.spec.ts
CHANGED
|
@@ -6,7 +6,7 @@ import { KeyvDirStoreAsJSON } from "./KeyvDirStoreAsJSON";
|
|
|
6
6
|
it("KeyvDirStore works", async () => {
|
|
7
7
|
// store test
|
|
8
8
|
const kv = new Keyv<number | string | { obj: boolean }>({
|
|
9
|
-
store: new KeyvDirStore(".cache/test1", { filename: (x) => x }),
|
|
9
|
+
store: new KeyvDirStore(".cache/test1", { filename: (x) => x, suffix: ".json" }),
|
|
10
10
|
namespace: "",
|
|
11
11
|
deserialize: KeyvDirStore.deserialize,
|
|
12
12
|
serialize: KeyvDirStore.serialize,
|
|
@@ -30,7 +30,7 @@ it("KeyvDirStore works", async () => {
|
|
|
30
30
|
|
|
31
31
|
// new instance with no cache Obj, to test file cache
|
|
32
32
|
const kv2 = new Keyv<number | string | { obj: boolean }>({
|
|
33
|
-
store: new KeyvDirStore(".cache/test1", { filename: (x) => x }),
|
|
33
|
+
store: new KeyvDirStore(".cache/test1", { filename: (x) => x, suffix: ".json" }),
|
|
34
34
|
namespace: "",
|
|
35
35
|
...KeyvDirStoreAsJSON,
|
|
36
36
|
});
|
package/index.ts
CHANGED
|
@@ -45,7 +45,7 @@ export class KeyvDirStore<Value extends string> implements KeyvStoreAdapter {
|
|
|
45
45
|
namespace?: string;
|
|
46
46
|
/** Path prefix prepended to every key (e.g. 'data/'). Defaults to ''. */
|
|
47
47
|
readonly prefix: string;
|
|
48
|
-
/** Path suffix appended to every key (e.g. '.json'). Defaults to '
|
|
48
|
+
/** Path suffix appended to every key (e.g. '.json'). Defaults to ''. */
|
|
49
49
|
readonly suffix: string;
|
|
50
50
|
constructor(
|
|
51
51
|
/** dir to cache store
|
|
@@ -61,9 +61,9 @@ export class KeyvDirStore<Value extends string> implements KeyvStoreAdapter {
|
|
|
61
61
|
}: {
|
|
62
62
|
cache?: CacheMap<Value>;
|
|
63
63
|
filename?: (key: string) => string;
|
|
64
|
-
/** Path prefix prepended to every key (e.g. 'data/').
|
|
64
|
+
/** Path prefix prepended to every key (e.g. 'data/'). Defaults to ''. */
|
|
65
65
|
prefix?: string;
|
|
66
|
-
/** Path suffix appended to every key (e.g. '.json'). Defaults to '
|
|
66
|
+
/** Path suffix appended to every key (e.g. '.json'). Defaults to ''. */
|
|
67
67
|
suffix?: string;
|
|
68
68
|
} = {},
|
|
69
69
|
) {
|
|
@@ -72,7 +72,7 @@ export class KeyvDirStore<Value extends string> implements KeyvStoreAdapter {
|
|
|
72
72
|
this.#dir = dir;
|
|
73
73
|
this.#filename = filename ?? this.#defaultFilename;
|
|
74
74
|
this.prefix = prefix ?? "";
|
|
75
|
-
this.suffix = suffix ?? "
|
|
75
|
+
this.suffix = suffix ?? "";
|
|
76
76
|
}
|
|
77
77
|
#defaultFilename(key: string) {
|
|
78
78
|
// use dir as hash salt to avoid collisions
|
package/package.json
CHANGED