cannibalizr 5.0.5 → 5.0.6
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/package.json +11 -17
- package/eslint.config.js +0 -30
- package/lib/index.js +0 -108
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cannibalizr",
|
|
3
|
-
"version": "5.0.
|
|
3
|
+
"version": "5.0.6",
|
|
4
4
|
"description": "Turns an old pile of rusty files into a new json data source",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -10,9 +10,10 @@
|
|
|
10
10
|
"default": "./dist/index.js"
|
|
11
11
|
},
|
|
12
12
|
"scripts": {
|
|
13
|
-
"
|
|
14
|
-
"
|
|
15
|
-
"
|
|
13
|
+
"_prep": "node -e 'require(\"fs\").rmSync(\"./dist\",{recursive:true,force:true})'",
|
|
14
|
+
"prepublishOnly": "npm run _prep && babel ./lib/index.js -o ./dist/index.cjs && node -e 'require(\"fs\").copyFileSync(\"./lib/index.js\", \"./dist/index.js\");'",
|
|
15
|
+
"pretest": "node -e 'require(\"fs\").rmSync(\"./coverage\",{recursive:true,force:true});require(\"fs\").mkdirSync(\"./coverage\",{recursive:true})'",
|
|
16
|
+
"test": "node --test --experimental-test-coverage --test-reporter=spec --test-reporter-destination=stdout --test-reporter=lcov --test-reporter-destination=coverage/lcov.info ./tests/unit/**",
|
|
16
17
|
"lint": "eslint ."
|
|
17
18
|
},
|
|
18
19
|
"repository": {
|
|
@@ -28,6 +29,9 @@
|
|
|
28
29
|
"files",
|
|
29
30
|
"json"
|
|
30
31
|
],
|
|
32
|
+
"files": [
|
|
33
|
+
"dist/"
|
|
34
|
+
],
|
|
31
35
|
"author": "Alex Grant (@localnerve)",
|
|
32
36
|
"license": "MIT",
|
|
33
37
|
"bugs": {
|
|
@@ -40,20 +44,10 @@
|
|
|
40
44
|
"devDependencies": {
|
|
41
45
|
"@babel/cli": "^7.28.6",
|
|
42
46
|
"@babel/core": "^7.29.0",
|
|
43
|
-
"@babel/preset-env": "^7.29.
|
|
47
|
+
"@babel/preset-env": "^7.29.5",
|
|
44
48
|
"@eslint/js": "^10.0.1",
|
|
45
|
-
"
|
|
46
|
-
"
|
|
47
|
-
"eslint": "^10.1.0",
|
|
48
|
-
"globals": "^17.4.0",
|
|
49
|
-
"mocha": "^11.7.5",
|
|
50
|
-
"rimraf": "^6.1.3"
|
|
51
|
-
},
|
|
52
|
-
"overrides": {
|
|
53
|
-
"diff": "^8.0.4",
|
|
54
|
-
"serialize-javascript": "^7.0.5",
|
|
55
|
-
"glob": "^13.0.6",
|
|
56
|
-
"brace-expansion": "^5.0.5"
|
|
49
|
+
"eslint": "^10.3.0",
|
|
50
|
+
"globals": "^17.6.0"
|
|
57
51
|
},
|
|
58
52
|
"pre-commit": [
|
|
59
53
|
"lint",
|
package/eslint.config.js
DELETED
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import js from '@eslint/js';
|
|
2
|
-
import globals from 'globals';
|
|
3
|
-
|
|
4
|
-
export default [{
|
|
5
|
-
ignores: [
|
|
6
|
-
'tmp/**',
|
|
7
|
-
'dist/**',
|
|
8
|
-
'node_modules/**',
|
|
9
|
-
'reports/**',
|
|
10
|
-
'tests/fixtures/**'
|
|
11
|
-
]
|
|
12
|
-
}, {
|
|
13
|
-
name: 'node',
|
|
14
|
-
...js.configs.recommended,
|
|
15
|
-
languageOptions: {
|
|
16
|
-
globals: {
|
|
17
|
-
...globals.node
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
}, {
|
|
21
|
-
name: 'tests',
|
|
22
|
-
files: [
|
|
23
|
-
'tests/**'
|
|
24
|
-
],
|
|
25
|
-
languageOptions: {
|
|
26
|
-
globals: {
|
|
27
|
-
...globals.mocha
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
}]
|
package/lib/index.js
DELETED
|
@@ -1,108 +0,0 @@
|
|
|
1
|
-
/***
|
|
2
|
-
* Copyright (c) 2016 - 2025 Alex Grant (@localnerve), LocalNerve LLC
|
|
3
|
-
* Copyrights licensed under the MIT License. See the accompanying LICENSE file
|
|
4
|
-
* for terms.
|
|
5
|
-
*/
|
|
6
|
-
import fs from 'node:fs';
|
|
7
|
-
export default cannibalizr;
|
|
8
|
-
/**
|
|
9
|
-
* Pull strings from multiple input files, write to structured json.
|
|
10
|
-
*
|
|
11
|
-
* json output file structure:
|
|
12
|
-
* {
|
|
13
|
-
* manifest: {
|
|
14
|
-
* // any output manifest data supplied in options
|
|
15
|
-
* },
|
|
16
|
-
* anyname: [
|
|
17
|
-
* 'some captured string',
|
|
18
|
-
* 'another captured string'
|
|
19
|
-
* ]
|
|
20
|
-
* }
|
|
21
|
-
*
|
|
22
|
-
* @param {Object} options - Cannibalizr options.
|
|
23
|
-
* @param {Object} options.input - input options.
|
|
24
|
-
* @param {Object} options.input.anyname - At least one input is required,
|
|
25
|
-
* use a name that makes sense for what is being captured.
|
|
26
|
-
* @param {String} options.input.anyname.file - The path of the input file.
|
|
27
|
-
* @param {Array} options.input.anyname.captures - The captures to run against
|
|
28
|
-
* the input file.
|
|
29
|
-
* @param {Boolean} options.input.anyname.captures.n.global - true if the regex
|
|
30
|
-
* is global, false otherwise.
|
|
31
|
-
* @param {Number} options.input.anyname.captures.n.matchIndex - The match index
|
|
32
|
-
* to use to capture data for the regex.
|
|
33
|
-
* @param {Regex} options.input.anyname.captures.n.re - The capturing regex to
|
|
34
|
-
* use to get data.
|
|
35
|
-
* @param {Object} options.output - output options.
|
|
36
|
-
* @param {String} options.output.file - The path of the json output file.
|
|
37
|
-
* @param {Object} [options.output.manifest] - An arbitrary manifest to write
|
|
38
|
-
* to the json output file.
|
|
39
|
-
* @param {Function} [options.logger] - A logger to use.
|
|
40
|
-
* @returns {Undefined} Nothing.
|
|
41
|
-
*/
|
|
42
|
-
export function cannibalizr (options) {
|
|
43
|
-
const output = {};
|
|
44
|
-
|
|
45
|
-
// used to trim "|' from the beginning and end of a captured result.
|
|
46
|
-
const reClean = /^(?:\s+|"|')|(?:\s+|"|')$/g;
|
|
47
|
-
|
|
48
|
-
// basic input check
|
|
49
|
-
const inputOk = options.input && Object.keys(options.input).length &&
|
|
50
|
-
options.output && options.output.file;
|
|
51
|
-
|
|
52
|
-
if (!inputOk) {
|
|
53
|
-
throw new Error(
|
|
54
|
-
'Cannibalizr received invalid options. Please review readme'
|
|
55
|
-
);
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
if (options.output.manifest) {
|
|
59
|
-
output.manifest = options.output.manifest;
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
/**
|
|
63
|
-
* Report output results
|
|
64
|
-
*
|
|
65
|
-
* @param {Object} items - An array of output values.
|
|
66
|
-
* @param {String} name - The name assocaited with the output.
|
|
67
|
-
* @returns {Undefined} Nothing.
|
|
68
|
-
*/
|
|
69
|
-
const report = function (items, name) {
|
|
70
|
-
if (options.logger) {
|
|
71
|
-
if (items && items.length) {
|
|
72
|
-
items.forEach(str => {
|
|
73
|
-
options.logger(`"${name}": ${str}`);
|
|
74
|
-
});
|
|
75
|
-
} else {
|
|
76
|
-
options.logger(`nothing found for "${name}"`);
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
};
|
|
80
|
-
|
|
81
|
-
Object.keys(options.input).forEach(item => {
|
|
82
|
-
options.input[item].forEach(input => {
|
|
83
|
-
const contents = fs.readFileSync(input.file, { encoding: 'utf8' });
|
|
84
|
-
|
|
85
|
-
input.captures.forEach(capSpec => {
|
|
86
|
-
let m;
|
|
87
|
-
|
|
88
|
-
output[item] || (output[item] = []);
|
|
89
|
-
|
|
90
|
-
if (capSpec.global) {
|
|
91
|
-
while ((m = capSpec.re.exec(contents)) !== null) {
|
|
92
|
-
output[item].push(m[capSpec.matchIndex].replace(reClean, ''));
|
|
93
|
-
}
|
|
94
|
-
} else {
|
|
95
|
-
m = capSpec.re.exec(contents);
|
|
96
|
-
if (m) {
|
|
97
|
-
output[item].push(m[capSpec.matchIndex].replace(reClean, ''));
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
});
|
|
101
|
-
});
|
|
102
|
-
report(output[item], item);
|
|
103
|
-
});
|
|
104
|
-
|
|
105
|
-
fs.writeFileSync(options.output.file, JSON.stringify(
|
|
106
|
-
output
|
|
107
|
-
));
|
|
108
|
-
}
|