node-datachannel 0.2.3 → 0.2.4
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/.github/workflows/build-linux.yml +2 -0
- package/CMakeLists.txt +2 -2
- package/lib/datachannel-stream.js +86 -0
- package/lib/index.d.ts +10 -0
- package/lib/index.js +3 -1
- package/node_modules/decompress-response/index.d.ts +14 -21
- package/node_modules/decompress-response/index.js +34 -16
- package/node_modules/decompress-response/license +1 -1
- package/node_modules/decompress-response/package.json +23 -17
- package/node_modules/decompress-response/readme.md +2 -6
- package/node_modules/detect-libc/README.md +124 -42
- package/node_modules/detect-libc/index.d.ts +11 -0
- package/node_modules/detect-libc/lib/detect-libc.js +166 -80
- package/node_modules/detect-libc/lib/process.js +16 -0
- package/node_modules/detect-libc/package.json +20 -20
- package/node_modules/{semver → lru-cache}/LICENSE +0 -0
- package/node_modules/lru-cache/README.md +166 -0
- package/node_modules/lru-cache/index.js +334 -0
- package/node_modules/lru-cache/node_modules/yallist/LICENSE +15 -0
- package/node_modules/lru-cache/node_modules/yallist/README.md +204 -0
- package/node_modules/lru-cache/node_modules/yallist/iterator.js +8 -0
- package/node_modules/lru-cache/node_modules/yallist/package.json +65 -0
- package/node_modules/lru-cache/node_modules/yallist/yallist.js +426 -0
- package/node_modules/lru-cache/package.json +74 -0
- package/node_modules/mimic-response/index.d.ts +2 -2
- package/node_modules/mimic-response/index.js +41 -2
- package/node_modules/mimic-response/package.json +17 -17
- package/node_modules/mimic-response/readme.md +22 -1
- package/node_modules/node-abi/.circleci/config.yml +63 -0
- package/node_modules/node-abi/.releaserc.json +9 -0
- package/node_modules/node-abi/abi_registry.json +45 -3
- package/node_modules/node-abi/index.js +5 -2
- package/node_modules/node-abi/node_modules/semver/CHANGELOG.md +111 -0
- package/node_modules/node-abi/node_modules/semver/LICENSE +15 -0
- package/node_modules/{semver → node-abi/node_modules/semver}/README.md +180 -26
- package/node_modules/node-abi/node_modules/semver/bin/semver.js +173 -0
- package/node_modules/node-abi/node_modules/semver/classes/comparator.js +135 -0
- package/node_modules/node-abi/node_modules/semver/classes/index.js +5 -0
- package/node_modules/node-abi/node_modules/semver/classes/range.js +510 -0
- package/node_modules/node-abi/node_modules/semver/classes/semver.js +287 -0
- package/node_modules/node-abi/node_modules/semver/functions/clean.js +6 -0
- package/node_modules/node-abi/node_modules/semver/functions/cmp.js +48 -0
- package/node_modules/node-abi/node_modules/semver/functions/coerce.js +51 -0
- package/node_modules/node-abi/node_modules/semver/functions/compare-build.js +7 -0
- package/node_modules/node-abi/node_modules/semver/functions/compare-loose.js +3 -0
- package/node_modules/node-abi/node_modules/semver/functions/compare.js +5 -0
- package/node_modules/node-abi/node_modules/semver/functions/diff.js +23 -0
- package/node_modules/node-abi/node_modules/semver/functions/eq.js +3 -0
- package/node_modules/node-abi/node_modules/semver/functions/gt.js +3 -0
- package/node_modules/node-abi/node_modules/semver/functions/gte.js +3 -0
- package/node_modules/node-abi/node_modules/semver/functions/inc.js +15 -0
- package/node_modules/node-abi/node_modules/semver/functions/lt.js +3 -0
- package/node_modules/node-abi/node_modules/semver/functions/lte.js +3 -0
- package/node_modules/node-abi/node_modules/semver/functions/major.js +3 -0
- package/node_modules/node-abi/node_modules/semver/functions/minor.js +3 -0
- package/node_modules/node-abi/node_modules/semver/functions/neq.js +3 -0
- package/node_modules/node-abi/node_modules/semver/functions/parse.js +33 -0
- package/node_modules/node-abi/node_modules/semver/functions/patch.js +3 -0
- package/node_modules/node-abi/node_modules/semver/functions/prerelease.js +6 -0
- package/node_modules/node-abi/node_modules/semver/functions/rcompare.js +3 -0
- package/node_modules/node-abi/node_modules/semver/functions/rsort.js +3 -0
- package/node_modules/node-abi/node_modules/semver/functions/satisfies.js +10 -0
- package/node_modules/node-abi/node_modules/semver/functions/sort.js +3 -0
- package/node_modules/node-abi/node_modules/semver/functions/valid.js +6 -0
- package/node_modules/node-abi/node_modules/semver/index.js +48 -0
- package/node_modules/node-abi/node_modules/semver/internal/constants.js +17 -0
- package/node_modules/node-abi/node_modules/semver/internal/debug.js +9 -0
- package/node_modules/node-abi/node_modules/semver/internal/identifiers.js +23 -0
- package/node_modules/node-abi/node_modules/semver/internal/parse-options.js +11 -0
- package/node_modules/node-abi/node_modules/semver/internal/re.js +182 -0
- package/node_modules/{semver → node-abi/node_modules/semver}/package.json +32 -23
- package/node_modules/node-abi/node_modules/semver/preload.js +2 -0
- package/node_modules/{semver → node-abi/node_modules/semver}/range.bnf +0 -0
- package/node_modules/node-abi/node_modules/semver/ranges/gtr.js +4 -0
- package/node_modules/node-abi/node_modules/semver/ranges/intersects.js +7 -0
- package/node_modules/node-abi/node_modules/semver/ranges/ltr.js +4 -0
- package/node_modules/node-abi/node_modules/semver/ranges/max-satisfying.js +25 -0
- package/node_modules/node-abi/node_modules/semver/ranges/min-satisfying.js +24 -0
- package/node_modules/node-abi/node_modules/semver/ranges/min-version.js +60 -0
- package/node_modules/node-abi/node_modules/semver/ranges/outside.js +80 -0
- package/node_modules/node-abi/node_modules/semver/ranges/simplify.js +44 -0
- package/node_modules/node-abi/node_modules/semver/ranges/subset.js +222 -0
- package/node_modules/node-abi/node_modules/semver/ranges/to-comparators.js +8 -0
- package/node_modules/node-abi/node_modules/semver/ranges/valid.js +11 -0
- package/node_modules/node-abi/package.json +20 -17
- package/node_modules/node-abi/test/index.js +7 -15
- package/node_modules/prebuild-install/CHANGELOG.md +24 -7
- package/node_modules/prebuild-install/README.md +24 -4
- package/node_modules/prebuild-install/asset.js +10 -10
- package/node_modules/prebuild-install/bin.js +13 -13
- package/node_modules/prebuild-install/download.js +22 -22
- package/node_modules/prebuild-install/log.js +4 -4
- package/node_modules/prebuild-install/package.json +18 -19
- package/node_modules/prebuild-install/proxy.js +10 -10
- package/node_modules/prebuild-install/rc.js +12 -12
- package/node_modules/prebuild-install/util.js +14 -14
- package/node_modules/simple-get/.github/dependabot.yml +15 -0
- package/node_modules/simple-get/.github/workflows/ci.yml +23 -0
- package/node_modules/simple-get/README.md +17 -3
- package/node_modules/simple-get/index.js +9 -0
- package/node_modules/simple-get/package.json +27 -13
- package/package.json +6 -5
- package/test/test.js +45 -0
- package/node_modules/detect-libc/.npmignore +0 -7
- package/node_modules/detect-libc/bin/detect-libc.js +0 -18
- package/node_modules/node-abi/.travis.yml +0 -17
- package/node_modules/semver/CHANGELOG.md +0 -39
- package/node_modules/semver/bin/semver +0 -160
- package/node_modules/semver/semver.js +0 -1483
|
@@ -1,92 +1,178 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
var readdirSync = require('fs').readdirSync;
|
|
3
|
+
const childProcess = require('child_process');
|
|
4
|
+
const { isLinux, getReport } = require('./process');
|
|
6
5
|
|
|
7
|
-
|
|
8
|
-
|
|
6
|
+
const command = 'getconf GNU_LIBC_VERSION 2>&1 || true; ldd --version 2>&1 || true';
|
|
7
|
+
let commandOut = '';
|
|
9
8
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
9
|
+
const safeCommand = () => {
|
|
10
|
+
if (!commandOut) {
|
|
11
|
+
return new Promise((resolve) => {
|
|
12
|
+
childProcess.exec(command, (err, out) => {
|
|
13
|
+
commandOut = err ? ' ' : out;
|
|
14
|
+
resolve(commandOut);
|
|
15
|
+
});
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
return commandOut;
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
const safeCommandSync = () => {
|
|
22
|
+
if (!commandOut) {
|
|
23
|
+
try {
|
|
24
|
+
commandOut = childProcess.execSync(command, { encoding: 'utf8' });
|
|
25
|
+
} catch (_err) {
|
|
26
|
+
commandOut = ' ';
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
return commandOut;
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* A String constant containing the value `glibc`.
|
|
34
|
+
* @type {string}
|
|
35
|
+
* @public
|
|
36
|
+
*/
|
|
37
|
+
const GLIBC = 'glibc';
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* A String constant containing the value `musl`.
|
|
41
|
+
* @type {string}
|
|
42
|
+
* @public
|
|
43
|
+
*/
|
|
44
|
+
const MUSL = 'musl';
|
|
45
|
+
|
|
46
|
+
const isFileMusl = (f) => f.includes('libc.musl-') || f.includes('ld-musl-');
|
|
47
|
+
|
|
48
|
+
const familyFromReport = () => {
|
|
49
|
+
const report = getReport();
|
|
50
|
+
if (report.header && report.header.glibcVersionRuntime) {
|
|
51
|
+
return GLIBC;
|
|
52
|
+
}
|
|
53
|
+
if (Array.isArray(report.sharedObjects)) {
|
|
54
|
+
if (report.sharedObjects.some(isFileMusl)) {
|
|
55
|
+
return MUSL;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
return null;
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
const familyFromCommand = (out) => {
|
|
62
|
+
const [getconf, ldd1] = out.split(/[\r\n]+/);
|
|
63
|
+
if (getconf && getconf.includes(GLIBC)) {
|
|
64
|
+
return GLIBC;
|
|
65
|
+
}
|
|
66
|
+
if (ldd1 && ldd1.includes(MUSL)) {
|
|
67
|
+
return MUSL;
|
|
68
|
+
}
|
|
69
|
+
return null;
|
|
13
70
|
};
|
|
14
71
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
function versionFromMuslLdd (out) {
|
|
28
|
-
return out.split(/[\r\n]+/)[1].trim().split(/\s/)[1];
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
function safeReaddirSync (path) {
|
|
32
|
-
try {
|
|
33
|
-
return readdirSync(path);
|
|
34
|
-
} catch (e) {}
|
|
35
|
-
return [];
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
var family = '';
|
|
39
|
-
var version = '';
|
|
40
|
-
var method = '';
|
|
41
|
-
|
|
42
|
-
if (platform === 'linux') {
|
|
43
|
-
// Try getconf
|
|
44
|
-
var glibc = spawnSync('getconf', ['GNU_LIBC_VERSION'], spawnOptions);
|
|
45
|
-
if (glibc.status === 0) {
|
|
46
|
-
family = GLIBC;
|
|
47
|
-
version = glibc.stdout.trim().split(' ')[1];
|
|
48
|
-
method = 'getconf';
|
|
49
|
-
} else {
|
|
50
|
-
// Try ldd
|
|
51
|
-
var ldd = spawnSync('ldd', ['--version'], spawnOptions);
|
|
52
|
-
if (ldd.status === 0 && ldd.stdout.indexOf(MUSL) !== -1) {
|
|
53
|
-
family = MUSL;
|
|
54
|
-
version = versionFromMuslLdd(ldd.stdout);
|
|
55
|
-
method = 'ldd';
|
|
56
|
-
} else if (ldd.status === 1 && ldd.stderr.indexOf(MUSL) !== -1) {
|
|
57
|
-
family = MUSL;
|
|
58
|
-
version = versionFromMuslLdd(ldd.stderr);
|
|
59
|
-
method = 'ldd';
|
|
60
|
-
} else {
|
|
61
|
-
// Try filesystem (family only)
|
|
62
|
-
var lib = safeReaddirSync('/lib');
|
|
63
|
-
if (lib.some(contains('-linux-gnu'))) {
|
|
64
|
-
family = GLIBC;
|
|
65
|
-
method = 'filesystem';
|
|
66
|
-
} else if (lib.some(contains('libc.musl-'))) {
|
|
67
|
-
family = MUSL;
|
|
68
|
-
method = 'filesystem';
|
|
69
|
-
} else if (lib.some(contains('ld-musl-'))) {
|
|
70
|
-
family = MUSL;
|
|
71
|
-
method = 'filesystem';
|
|
72
|
-
} else {
|
|
73
|
-
var usrSbin = safeReaddirSync('/usr/sbin');
|
|
74
|
-
if (usrSbin.some(contains('glibc'))) {
|
|
75
|
-
family = GLIBC;
|
|
76
|
-
method = 'filesystem';
|
|
77
|
-
}
|
|
78
|
-
}
|
|
72
|
+
/**
|
|
73
|
+
* Resolves with the libc family when it can be determined, `null` otherwise.
|
|
74
|
+
* @returns {Promise<?string>}
|
|
75
|
+
*/
|
|
76
|
+
const family = async () => {
|
|
77
|
+
let family = null;
|
|
78
|
+
if (isLinux()) {
|
|
79
|
+
family = familyFromReport();
|
|
80
|
+
if (!family) {
|
|
81
|
+
const out = await safeCommand();
|
|
82
|
+
family = familyFromCommand(out);
|
|
79
83
|
}
|
|
80
84
|
}
|
|
81
|
-
|
|
85
|
+
return family;
|
|
86
|
+
};
|
|
82
87
|
|
|
83
|
-
|
|
88
|
+
/**
|
|
89
|
+
* Returns the libc family when it can be determined, `null` otherwise.
|
|
90
|
+
* @returns {?string}
|
|
91
|
+
*/
|
|
92
|
+
const familySync = () => {
|
|
93
|
+
let family = null;
|
|
94
|
+
if (isLinux()) {
|
|
95
|
+
family = familyFromReport();
|
|
96
|
+
if (!family) {
|
|
97
|
+
const out = safeCommandSync();
|
|
98
|
+
family = familyFromCommand(out);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
return family;
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* Resolves `true` only when the platform is Linux and the libc family is not `glibc`.
|
|
106
|
+
* @returns {Promise<boolean>}
|
|
107
|
+
*/
|
|
108
|
+
const isNonGlibcLinux = async () => isLinux() && await family() !== GLIBC;
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* Returns `true` only when the platform is Linux and the libc family is not `glibc`.
|
|
112
|
+
* @returns {boolean}
|
|
113
|
+
*/
|
|
114
|
+
const isNonGlibcLinuxSync = () => isLinux() && familySync() !== GLIBC;
|
|
115
|
+
|
|
116
|
+
const versionFromReport = () => {
|
|
117
|
+
const report = getReport();
|
|
118
|
+
if (report.header && report.header.glibcVersionRuntime) {
|
|
119
|
+
return report.header.glibcVersionRuntime;
|
|
120
|
+
}
|
|
121
|
+
return null;
|
|
122
|
+
};
|
|
123
|
+
|
|
124
|
+
const versionSuffix = (s) => s.trim().split(/\s+/)[1];
|
|
125
|
+
|
|
126
|
+
const versionFromCommand = (out) => {
|
|
127
|
+
const [getconf, ldd1, ldd2] = out.split(/[\r\n]+/);
|
|
128
|
+
if (getconf && getconf.includes(GLIBC)) {
|
|
129
|
+
return versionSuffix(getconf);
|
|
130
|
+
}
|
|
131
|
+
if (ldd1 && ldd2 && ldd1.includes(MUSL)) {
|
|
132
|
+
return versionSuffix(ldd2);
|
|
133
|
+
}
|
|
134
|
+
return null;
|
|
135
|
+
};
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* Resolves with the libc version when it can be determined, `null` otherwise.
|
|
139
|
+
* @returns {Promise<?string>}
|
|
140
|
+
*/
|
|
141
|
+
const version = async () => {
|
|
142
|
+
let version = null;
|
|
143
|
+
if (isLinux()) {
|
|
144
|
+
version = versionFromReport();
|
|
145
|
+
if (!version) {
|
|
146
|
+
const out = await safeCommand();
|
|
147
|
+
version = versionFromCommand(out);
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
return version;
|
|
151
|
+
};
|
|
152
|
+
|
|
153
|
+
/**
|
|
154
|
+
* Returns the libc version when it can be determined, `null` otherwise.
|
|
155
|
+
* @returns {?string}
|
|
156
|
+
*/
|
|
157
|
+
const versionSync = () => {
|
|
158
|
+
let version = null;
|
|
159
|
+
if (isLinux()) {
|
|
160
|
+
version = versionFromReport();
|
|
161
|
+
if (!version) {
|
|
162
|
+
const out = safeCommandSync();
|
|
163
|
+
version = versionFromCommand(out);
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
return version;
|
|
167
|
+
};
|
|
84
168
|
|
|
85
169
|
module.exports = {
|
|
86
|
-
GLIBC
|
|
87
|
-
MUSL
|
|
88
|
-
family
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
170
|
+
GLIBC,
|
|
171
|
+
MUSL,
|
|
172
|
+
family,
|
|
173
|
+
familySync,
|
|
174
|
+
isNonGlibcLinux,
|
|
175
|
+
isNonGlibcLinuxSync,
|
|
176
|
+
version,
|
|
177
|
+
versionSync
|
|
92
178
|
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const isLinux = () => process.platform === 'linux';
|
|
4
|
+
|
|
5
|
+
let report = null;
|
|
6
|
+
const getReport = () => {
|
|
7
|
+
if (!report) {
|
|
8
|
+
/* istanbul ignore next */
|
|
9
|
+
report = isLinux() && process.report
|
|
10
|
+
? process.report.getReport()
|
|
11
|
+
: {};
|
|
12
|
+
}
|
|
13
|
+
return report;
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
module.exports = { isLinux, getReport };
|
|
@@ -1,40 +1,36 @@
|
|
|
1
1
|
{
|
|
2
2
|
"_args": [
|
|
3
3
|
[
|
|
4
|
-
"detect-libc@
|
|
4
|
+
"detect-libc@2.0.1",
|
|
5
5
|
"/home/runner/work/node-datachannel/node-datachannel"
|
|
6
6
|
]
|
|
7
7
|
],
|
|
8
|
-
"_from": "detect-libc@
|
|
9
|
-
"_id": "detect-libc@
|
|
8
|
+
"_from": "detect-libc@2.0.1",
|
|
9
|
+
"_id": "detect-libc@2.0.1",
|
|
10
10
|
"_inBundle": false,
|
|
11
|
-
"_integrity": "
|
|
11
|
+
"_integrity": "sha512-463v3ZeIrcWtdgIg6vI6XUncguvr2TnGl4SzDXinkt9mSLpBJKXT3mW6xT3VQdDN11+WVs29pgvivTc4Lp8v+w==",
|
|
12
12
|
"_location": "/detect-libc",
|
|
13
13
|
"_phantomChildren": {},
|
|
14
14
|
"_requested": {
|
|
15
15
|
"type": "version",
|
|
16
16
|
"registry": true,
|
|
17
|
-
"raw": "detect-libc@
|
|
17
|
+
"raw": "detect-libc@2.0.1",
|
|
18
18
|
"name": "detect-libc",
|
|
19
19
|
"escapedName": "detect-libc",
|
|
20
|
-
"rawSpec": "
|
|
20
|
+
"rawSpec": "2.0.1",
|
|
21
21
|
"saveSpec": null,
|
|
22
|
-
"fetchSpec": "
|
|
22
|
+
"fetchSpec": "2.0.1"
|
|
23
23
|
},
|
|
24
24
|
"_requiredBy": [
|
|
25
|
-
"/prebuild",
|
|
26
25
|
"/prebuild-install"
|
|
27
26
|
],
|
|
28
|
-
"_resolved": "https://registry.npmjs.org/detect-libc/-/detect-libc-
|
|
29
|
-
"_spec": "
|
|
27
|
+
"_resolved": "https://registry.npmjs.org/detect-libc/-/detect-libc-2.0.1.tgz",
|
|
28
|
+
"_spec": "2.0.1",
|
|
30
29
|
"_where": "/home/runner/work/node-datachannel/node-datachannel",
|
|
31
30
|
"author": {
|
|
32
31
|
"name": "Lovell Fuller",
|
|
33
32
|
"email": "npm@lovell.info"
|
|
34
33
|
},
|
|
35
|
-
"bin": {
|
|
36
|
-
"detect-libc": "bin/detect-libc.js"
|
|
37
|
-
},
|
|
38
34
|
"bugs": {
|
|
39
35
|
"url": "https://github.com/lovell/detect-libc/issues"
|
|
40
36
|
},
|
|
@@ -46,14 +42,18 @@
|
|
|
46
42
|
],
|
|
47
43
|
"description": "Node.js module to detect the C standard library (libc) implementation family and version",
|
|
48
44
|
"devDependencies": {
|
|
49
|
-
"ava": "^
|
|
50
|
-
"nyc": "^
|
|
51
|
-
"proxyquire": "^1.
|
|
52
|
-
"semistandard": "^
|
|
45
|
+
"ava": "^2.4.0",
|
|
46
|
+
"nyc": "^15.1.0",
|
|
47
|
+
"proxyquire": "^2.1.3",
|
|
48
|
+
"semistandard": "^14.2.3"
|
|
53
49
|
},
|
|
54
50
|
"engines": {
|
|
55
|
-
"node": ">=
|
|
51
|
+
"node": ">=8"
|
|
56
52
|
},
|
|
53
|
+
"files": [
|
|
54
|
+
"lib/",
|
|
55
|
+
"index.d.ts"
|
|
56
|
+
],
|
|
57
57
|
"homepage": "https://github.com/lovell/detect-libc#readme",
|
|
58
58
|
"keywords": [
|
|
59
59
|
"libc",
|
|
@@ -68,7 +68,7 @@
|
|
|
68
68
|
"url": "git://github.com/lovell/detect-libc.git"
|
|
69
69
|
},
|
|
70
70
|
"scripts": {
|
|
71
|
-
"test": "semistandard && nyc --reporter=lcov ava"
|
|
71
|
+
"test": "semistandard && nyc --reporter=lcov --check-coverage --branches=100 ava test/unit.js"
|
|
72
72
|
},
|
|
73
|
-
"version": "
|
|
73
|
+
"version": "2.0.1"
|
|
74
74
|
}
|
|
File without changes
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
# lru cache
|
|
2
|
+
|
|
3
|
+
A cache object that deletes the least-recently-used items.
|
|
4
|
+
|
|
5
|
+
[](https://travis-ci.org/isaacs/node-lru-cache) [](https://coveralls.io/github/isaacs/node-lru-cache)
|
|
6
|
+
|
|
7
|
+
## Installation:
|
|
8
|
+
|
|
9
|
+
```javascript
|
|
10
|
+
npm install lru-cache --save
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Usage:
|
|
14
|
+
|
|
15
|
+
```javascript
|
|
16
|
+
var LRU = require("lru-cache")
|
|
17
|
+
, options = { max: 500
|
|
18
|
+
, length: function (n, key) { return n * 2 + key.length }
|
|
19
|
+
, dispose: function (key, n) { n.close() }
|
|
20
|
+
, maxAge: 1000 * 60 * 60 }
|
|
21
|
+
, cache = new LRU(options)
|
|
22
|
+
, otherCache = new LRU(50) // sets just the max size
|
|
23
|
+
|
|
24
|
+
cache.set("key", "value")
|
|
25
|
+
cache.get("key") // "value"
|
|
26
|
+
|
|
27
|
+
// non-string keys ARE fully supported
|
|
28
|
+
// but note that it must be THE SAME object, not
|
|
29
|
+
// just a JSON-equivalent object.
|
|
30
|
+
var someObject = { a: 1 }
|
|
31
|
+
cache.set(someObject, 'a value')
|
|
32
|
+
// Object keys are not toString()-ed
|
|
33
|
+
cache.set('[object Object]', 'a different value')
|
|
34
|
+
assert.equal(cache.get(someObject), 'a value')
|
|
35
|
+
// A similar object with same keys/values won't work,
|
|
36
|
+
// because it's a different object identity
|
|
37
|
+
assert.equal(cache.get({ a: 1 }), undefined)
|
|
38
|
+
|
|
39
|
+
cache.reset() // empty the cache
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
If you put more stuff in it, then items will fall out.
|
|
43
|
+
|
|
44
|
+
If you try to put an oversized thing in it, then it'll fall out right
|
|
45
|
+
away.
|
|
46
|
+
|
|
47
|
+
## Options
|
|
48
|
+
|
|
49
|
+
* `max` The maximum size of the cache, checked by applying the length
|
|
50
|
+
function to all values in the cache. Not setting this is kind of
|
|
51
|
+
silly, since that's the whole purpose of this lib, but it defaults
|
|
52
|
+
to `Infinity`. Setting it to a non-number or negative number will
|
|
53
|
+
throw a `TypeError`. Setting it to 0 makes it be `Infinity`.
|
|
54
|
+
* `maxAge` Maximum age in ms. Items are not pro-actively pruned out
|
|
55
|
+
as they age, but if you try to get an item that is too old, it'll
|
|
56
|
+
drop it and return undefined instead of giving it to you.
|
|
57
|
+
Setting this to a negative value will make everything seem old!
|
|
58
|
+
Setting it to a non-number will throw a `TypeError`.
|
|
59
|
+
* `length` Function that is used to calculate the length of stored
|
|
60
|
+
items. If you're storing strings or buffers, then you probably want
|
|
61
|
+
to do something like `function(n, key){return n.length}`. The default is
|
|
62
|
+
`function(){return 1}`, which is fine if you want to store `max`
|
|
63
|
+
like-sized things. The item is passed as the first argument, and
|
|
64
|
+
the key is passed as the second argumnet.
|
|
65
|
+
* `dispose` Function that is called on items when they are dropped
|
|
66
|
+
from the cache. This can be handy if you want to close file
|
|
67
|
+
descriptors or do other cleanup tasks when items are no longer
|
|
68
|
+
accessible. Called with `key, value`. It's called *before*
|
|
69
|
+
actually removing the item from the internal cache, so if you want
|
|
70
|
+
to immediately put it back in, you'll have to do that in a
|
|
71
|
+
`nextTick` or `setTimeout` callback or it won't do anything.
|
|
72
|
+
* `stale` By default, if you set a `maxAge`, it'll only actually pull
|
|
73
|
+
stale items out of the cache when you `get(key)`. (That is, it's
|
|
74
|
+
not pre-emptively doing a `setTimeout` or anything.) If you set
|
|
75
|
+
`stale:true`, it'll return the stale value before deleting it. If
|
|
76
|
+
you don't set this, then it'll return `undefined` when you try to
|
|
77
|
+
get a stale entry, as if it had already been deleted.
|
|
78
|
+
* `noDisposeOnSet` By default, if you set a `dispose()` method, then
|
|
79
|
+
it'll be called whenever a `set()` operation overwrites an existing
|
|
80
|
+
key. If you set this option, `dispose()` will only be called when a
|
|
81
|
+
key falls out of the cache, not when it is overwritten.
|
|
82
|
+
* `updateAgeOnGet` When using time-expiring entries with `maxAge`,
|
|
83
|
+
setting this to `true` will make each item's effective time update
|
|
84
|
+
to the current time whenever it is retrieved from cache, causing it
|
|
85
|
+
to not expire. (It can still fall out of cache based on recency of
|
|
86
|
+
use, of course.)
|
|
87
|
+
|
|
88
|
+
## API
|
|
89
|
+
|
|
90
|
+
* `set(key, value, maxAge)`
|
|
91
|
+
* `get(key) => value`
|
|
92
|
+
|
|
93
|
+
Both of these will update the "recently used"-ness of the key.
|
|
94
|
+
They do what you think. `maxAge` is optional and overrides the
|
|
95
|
+
cache `maxAge` option if provided.
|
|
96
|
+
|
|
97
|
+
If the key is not found, `get()` will return `undefined`.
|
|
98
|
+
|
|
99
|
+
The key and val can be any value.
|
|
100
|
+
|
|
101
|
+
* `peek(key)`
|
|
102
|
+
|
|
103
|
+
Returns the key value (or `undefined` if not found) without
|
|
104
|
+
updating the "recently used"-ness of the key.
|
|
105
|
+
|
|
106
|
+
(If you find yourself using this a lot, you *might* be using the
|
|
107
|
+
wrong sort of data structure, but there are some use cases where
|
|
108
|
+
it's handy.)
|
|
109
|
+
|
|
110
|
+
* `del(key)`
|
|
111
|
+
|
|
112
|
+
Deletes a key out of the cache.
|
|
113
|
+
|
|
114
|
+
* `reset()`
|
|
115
|
+
|
|
116
|
+
Clear the cache entirely, throwing away all values.
|
|
117
|
+
|
|
118
|
+
* `has(key)`
|
|
119
|
+
|
|
120
|
+
Check if a key is in the cache, without updating the recent-ness
|
|
121
|
+
or deleting it for being stale.
|
|
122
|
+
|
|
123
|
+
* `forEach(function(value,key,cache), [thisp])`
|
|
124
|
+
|
|
125
|
+
Just like `Array.prototype.forEach`. Iterates over all the keys
|
|
126
|
+
in the cache, in order of recent-ness. (Ie, more recently used
|
|
127
|
+
items are iterated over first.)
|
|
128
|
+
|
|
129
|
+
* `rforEach(function(value,key,cache), [thisp])`
|
|
130
|
+
|
|
131
|
+
The same as `cache.forEach(...)` but items are iterated over in
|
|
132
|
+
reverse order. (ie, less recently used items are iterated over
|
|
133
|
+
first.)
|
|
134
|
+
|
|
135
|
+
* `keys()`
|
|
136
|
+
|
|
137
|
+
Return an array of the keys in the cache.
|
|
138
|
+
|
|
139
|
+
* `values()`
|
|
140
|
+
|
|
141
|
+
Return an array of the values in the cache.
|
|
142
|
+
|
|
143
|
+
* `length`
|
|
144
|
+
|
|
145
|
+
Return total length of objects in cache taking into account
|
|
146
|
+
`length` options function.
|
|
147
|
+
|
|
148
|
+
* `itemCount`
|
|
149
|
+
|
|
150
|
+
Return total quantity of objects currently in cache. Note, that
|
|
151
|
+
`stale` (see options) items are returned as part of this item
|
|
152
|
+
count.
|
|
153
|
+
|
|
154
|
+
* `dump()`
|
|
155
|
+
|
|
156
|
+
Return an array of the cache entries ready for serialization and usage
|
|
157
|
+
with 'destinationCache.load(arr)`.
|
|
158
|
+
|
|
159
|
+
* `load(cacheEntriesArray)`
|
|
160
|
+
|
|
161
|
+
Loads another cache entries array, obtained with `sourceCache.dump()`,
|
|
162
|
+
into the cache. The destination cache is reset before loading new entries
|
|
163
|
+
|
|
164
|
+
* `prune()`
|
|
165
|
+
|
|
166
|
+
Manually iterates over the entire cache proactively pruning old entries
|