@nojaja/greputil 1.0.0 → 1.0.2
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/LICENSE +21 -21
- package/README.md +335 -335
- package/{src/BufferPatternMatcher.ts → dist/BufferPatternMatcher.d.ts} +43 -61
- package/dist/BufferPatternMatcher.d.ts.map +1 -0
- package/dist/GrepUtil.bundle.js +2 -0
- package/dist/GrepUtil.bundle.js.map +1 -0
- package/{src/RegExpArray.ts → dist/RegExpArray.d.ts} +143 -209
- package/dist/RegExpArray.d.ts.map +1 -0
- package/{src/index.ts → dist/index.d.ts} +15 -15
- package/dist/index.d.ts.map +1 -0
- package/package.json +18 -3
- package/.babelrc +0 -7
- package/.dependency-cruiser.js +0 -89
- package/.eslintignore +0 -6
- package/.eslintrc.cjs +0 -48
- package/.github/skills/completion-mandatory-quality-gates.md +0 -26
- package/.github/skills/nodejs-project-quality-guardrails.md +0 -417
- package/.github/workflows/release.yml +0 -44
- package/.github/workflows/webpack.yml +0 -28
- package/MIGRATION_REPORT.md +0 -77
- package/jest.config.js +0 -16
- package/jest.unit.config.js +0 -31
- package/tests/unit/RegExpArray.spec.ts +0 -205
- package/tsconfig.json +0 -22
- package/typedoc.js +0 -16
- package/webpack.config.js +0 -32
|
@@ -1,205 +0,0 @@
|
|
|
1
|
-
import { RegExpArray } from '../../src/RegExpArray';
|
|
2
|
-
import { BufferPatternMatcher } from '../../src/BufferPatternMatcher';
|
|
3
|
-
|
|
4
|
-
describe('RegExpArray', () => {
|
|
5
|
-
describe('constructor', () => {
|
|
6
|
-
it('文字列配列から正規表現を生成できること', () => {
|
|
7
|
-
const regExpArray = new RegExpArray(['test.']);
|
|
8
|
-
expect(regExpArray.toArray()[0].source).toBe('test.');
|
|
9
|
-
expect(regExpArray.toArray()[0].flags).toBe('');
|
|
10
|
-
});
|
|
11
|
-
|
|
12
|
-
it('RegExpオブジェクト配列から正規表現を生成できること', () => {
|
|
13
|
-
const regExpArray = new RegExpArray([/t(e)(st(\d?))/g]);
|
|
14
|
-
expect(regExpArray.toArray()[0].source).toBe('t(e)(st(\\d?))');
|
|
15
|
-
expect(regExpArray.toArray()[0].flags).toBe('g');
|
|
16
|
-
});
|
|
17
|
-
|
|
18
|
-
it('文字列から正規表現を生成できること', () => {
|
|
19
|
-
const regExpArray = new RegExpArray(['t(e)(st(\\d?))']);
|
|
20
|
-
expect(regExpArray.toArray()[0].source).toBe('t(e)(st(\\d?))');
|
|
21
|
-
expect(regExpArray.toArray()[0].flags).toBe('');
|
|
22
|
-
});
|
|
23
|
-
|
|
24
|
-
it('[パターン, フラグ]配列から正規表現を生成できること', () => {
|
|
25
|
-
const regExpArray = new RegExpArray([['t(e)(st(\\d?))', 'g']]);
|
|
26
|
-
expect(regExpArray.toArray()[0].source).toBe('t(e)(st(\\d?))');
|
|
27
|
-
expect(regExpArray.toArray()[0].flags).toBe('g');
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
it('空の配列でインスタンス化できること', () => {
|
|
31
|
-
const regExpArray = new RegExpArray([]);
|
|
32
|
-
expect(regExpArray.toArray()).toEqual([]);
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
it('パターンなしでインスタンス化できること', () => {
|
|
36
|
-
const regExpArray = new RegExpArray();
|
|
37
|
-
expect(regExpArray.toArray()).toEqual([]);
|
|
38
|
-
});
|
|
39
|
-
});
|
|
40
|
-
|
|
41
|
-
describe('exec', () => {
|
|
42
|
-
it('グローバルフラグ付き正規表現で順次マッチできること', () => {
|
|
43
|
-
const regExpArray = new RegExpArray([/t(e)(st(\d?))/g]);
|
|
44
|
-
expect(regExpArray.exec('test1test2')).toEqual(['test1', 'e', 'st1', '1']);
|
|
45
|
-
expect(regExpArray.exec('test1test2')).toEqual(['test2', 'e', 'st2', '2']);
|
|
46
|
-
expect(regExpArray.exec('test1test2')).toEqual([]);
|
|
47
|
-
});
|
|
48
|
-
|
|
49
|
-
it('複数パターンのマッチ結果を返すこと', () => {
|
|
50
|
-
const regExpArray = new RegExpArray([/hello/, /world/]);
|
|
51
|
-
const result = regExpArray.exec('hello world');
|
|
52
|
-
expect(result).toContain('hello');
|
|
53
|
-
expect(result).toContain('world');
|
|
54
|
-
});
|
|
55
|
-
|
|
56
|
-
it('マッチしない場合は空配列を返すこと', () => {
|
|
57
|
-
const regExpArray = new RegExpArray([/xyz/]);
|
|
58
|
-
expect(regExpArray.exec('abc')).toEqual([]);
|
|
59
|
-
});
|
|
60
|
-
});
|
|
61
|
-
|
|
62
|
-
describe('firstMatch', () => {
|
|
63
|
-
it('最初のマッチ結果を返すこと', () => {
|
|
64
|
-
const regExpArray = new RegExpArray([/test\d/, /hello/]);
|
|
65
|
-
const result = regExpArray.firstMatch('test1 hello');
|
|
66
|
-
expect(result).not.toBeNull();
|
|
67
|
-
expect(result![0]).toBe('test1');
|
|
68
|
-
});
|
|
69
|
-
|
|
70
|
-
it('マッチしない場合はnullを返すこと', () => {
|
|
71
|
-
const regExpArray = new RegExpArray([/xyz/]);
|
|
72
|
-
expect(regExpArray.firstMatch('abc')).toBeNull();
|
|
73
|
-
});
|
|
74
|
-
});
|
|
75
|
-
|
|
76
|
-
describe('test', () => {
|
|
77
|
-
it('グローバルフラグ付き正規表現でマッチ判定できること', () => {
|
|
78
|
-
const regExpArray = new RegExpArray([/t(e)(st(\d?))/g]);
|
|
79
|
-
expect(regExpArray.test('test1test2')).toBe(true);
|
|
80
|
-
expect(regExpArray.test('test1test2')).toBe(true);
|
|
81
|
-
expect(regExpArray.test('test1test2')).toBe(false);
|
|
82
|
-
});
|
|
83
|
-
|
|
84
|
-
it('マッチする場合trueを返すこと', () => {
|
|
85
|
-
const regExpArray = new RegExpArray([/hello/]);
|
|
86
|
-
expect(regExpArray.test('hello world')).toBe(true);
|
|
87
|
-
});
|
|
88
|
-
|
|
89
|
-
it('マッチしない場合falseを返すこと', () => {
|
|
90
|
-
const regExpArray = new RegExpArray([/xyz/]);
|
|
91
|
-
expect(regExpArray.test('abc')).toBe(false);
|
|
92
|
-
});
|
|
93
|
-
});
|
|
94
|
-
|
|
95
|
-
describe('toArray', () => {
|
|
96
|
-
it('RegExpオブジェクトの配列を返すこと', () => {
|
|
97
|
-
const regExpArray = new RegExpArray([/test/, /hello/]);
|
|
98
|
-
const result = regExpArray.toArray();
|
|
99
|
-
expect(result).toHaveLength(2);
|
|
100
|
-
expect(result[0]).toBeInstanceOf(RegExp);
|
|
101
|
-
expect(result[1]).toBeInstanceOf(RegExp);
|
|
102
|
-
});
|
|
103
|
-
});
|
|
104
|
-
|
|
105
|
-
describe('matchAll (static)', () => {
|
|
106
|
-
it('すべてのマッチ結果を二次元配列で返すこと', () => {
|
|
107
|
-
const result = RegExpArray.matchAll('test1test2', [/t(e)(st(\d?))/g]);
|
|
108
|
-
expect(result).toEqual([['test1', 'e', 'st1', '1'], ['test2', 'e', 'st2', '2']]);
|
|
109
|
-
});
|
|
110
|
-
|
|
111
|
-
it('文字列パターンでマッチできること', () => {
|
|
112
|
-
const result = RegExpArray.matchAll('test1test2', 'test.');
|
|
113
|
-
expect(result).toHaveLength(2);
|
|
114
|
-
expect(result![0][0]).toMatch(/test\d/);
|
|
115
|
-
});
|
|
116
|
-
|
|
117
|
-
it('マッチしない場合は空配列を返すこと', () => {
|
|
118
|
-
const result = RegExpArray.matchAll('test1test2', 'string');
|
|
119
|
-
expect(result).toEqual([]);
|
|
120
|
-
});
|
|
121
|
-
|
|
122
|
-
it('nullを渡した場合はnullを返すこと', () => {
|
|
123
|
-
const result = RegExpArray.matchAll('test', null);
|
|
124
|
-
expect(result).toBeNull();
|
|
125
|
-
});
|
|
126
|
-
});
|
|
127
|
-
|
|
128
|
-
describe('firstMatch (static)', () => {
|
|
129
|
-
it('最初のマッチ結果を返すこと', () => {
|
|
130
|
-
const result = RegExpArray.firstMatch('test1 hello', [/test\d/, /hello/]);
|
|
131
|
-
expect(result).not.toBeNull();
|
|
132
|
-
expect(result![0]).toBe('test1');
|
|
133
|
-
});
|
|
134
|
-
|
|
135
|
-
it('マッチしない場合はnullを返すこと', () => {
|
|
136
|
-
const result = RegExpArray.firstMatch('abc', [/xyz/]);
|
|
137
|
-
expect(result).toBeNull();
|
|
138
|
-
});
|
|
139
|
-
|
|
140
|
-
it('nullを渡した場合はnullを返すこと', () => {
|
|
141
|
-
const result = RegExpArray.firstMatch('test', null);
|
|
142
|
-
expect(result).toBeNull();
|
|
143
|
-
});
|
|
144
|
-
});
|
|
145
|
-
|
|
146
|
-
describe('test (static)', () => {
|
|
147
|
-
it('マッチする場合trueを返すこと', () => {
|
|
148
|
-
expect(RegExpArray.test('hello world', [/hello/])).toBe(true);
|
|
149
|
-
});
|
|
150
|
-
|
|
151
|
-
it('マッチしない場合falseを返すこと', () => {
|
|
152
|
-
expect(RegExpArray.test('abc', [/xyz/])).toBe(false);
|
|
153
|
-
});
|
|
154
|
-
|
|
155
|
-
it('nullを渡した場合falseを返すこと', () => {
|
|
156
|
-
expect(RegExpArray.test('test', null)).toBe(false);
|
|
157
|
-
});
|
|
158
|
-
});
|
|
159
|
-
});
|
|
160
|
-
|
|
161
|
-
describe('BufferPatternMatcher', () => {
|
|
162
|
-
describe('compareBuf', () => {
|
|
163
|
-
it('パターンにマッチする場合trueを返すこと', () => {
|
|
164
|
-
const matcher = new BufferPatternMatcher();
|
|
165
|
-
const buffer = Buffer.from([0x89, 0x50, 0x4E, 0x47, 0x0D, 0x0A]);
|
|
166
|
-
const patterns = [Buffer.from([0x89, 0x50, 0x4E, 0x47])]; // PNGシグネチャ
|
|
167
|
-
|
|
168
|
-
expect(matcher.compareBuf(buffer, patterns)).toBe(true);
|
|
169
|
-
});
|
|
170
|
-
|
|
171
|
-
it('パターンにマッチしない場合falseを返すこと', () => {
|
|
172
|
-
const matcher = new BufferPatternMatcher();
|
|
173
|
-
const buffer = Buffer.from([0xFF, 0xD8, 0xFF, 0xE0]);
|
|
174
|
-
const patterns = [Buffer.from([0x89, 0x50, 0x4E, 0x47])]; // PNGシグネチャ
|
|
175
|
-
|
|
176
|
-
expect(matcher.compareBuf(buffer, patterns)).toBe(false);
|
|
177
|
-
});
|
|
178
|
-
|
|
179
|
-
it('複数パターンの1つにマッチする場合trueを返すこと', () => {
|
|
180
|
-
const matcher = new BufferPatternMatcher();
|
|
181
|
-
const buffer = Buffer.from([0xFF, 0xD8, 0xFF, 0xE0]);
|
|
182
|
-
const patterns = [
|
|
183
|
-
Buffer.from([0x89, 0x50, 0x4E, 0x47]), // PNGシグネチャ
|
|
184
|
-
Buffer.from([0xFF, 0xD8, 0xFF]) // JPEGシグネチャ
|
|
185
|
-
];
|
|
186
|
-
|
|
187
|
-
expect(matcher.compareBuf(buffer, patterns)).toBe(true);
|
|
188
|
-
});
|
|
189
|
-
|
|
190
|
-
it('patternsがnullの場合nullを返すこと', () => {
|
|
191
|
-
const matcher = new BufferPatternMatcher();
|
|
192
|
-
const buffer = Buffer.from([0x89, 0x50, 0x4E, 0x47]);
|
|
193
|
-
|
|
194
|
-
expect(matcher.compareBuf(buffer, null)).toBeNull();
|
|
195
|
-
});
|
|
196
|
-
|
|
197
|
-
it('バッファがパターンより短い場合falseを返すこと', () => {
|
|
198
|
-
const matcher = new BufferPatternMatcher();
|
|
199
|
-
const buffer = Buffer.from([0x89, 0x50]);
|
|
200
|
-
const patterns = [Buffer.from([0x89, 0x50, 0x4E, 0x47])];
|
|
201
|
-
|
|
202
|
-
expect(matcher.compareBuf(buffer, patterns)).toBe(false);
|
|
203
|
-
});
|
|
204
|
-
});
|
|
205
|
-
});
|
package/tsconfig.json
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"compilerOptions": {
|
|
3
|
-
"target": "ES2022",
|
|
4
|
-
"module": "ES2022",
|
|
5
|
-
"moduleResolution": "node",
|
|
6
|
-
"lib": ["ES2022"],
|
|
7
|
-
"outDir": "./dist",
|
|
8
|
-
"rootDir": "./src",
|
|
9
|
-
"strict": true,
|
|
10
|
-
"esModuleInterop": true,
|
|
11
|
-
"skipLibCheck": true,
|
|
12
|
-
"forceConsistentCasingInFileNames": true,
|
|
13
|
-
"declaration": true,
|
|
14
|
-
"declarationMap": true,
|
|
15
|
-
"sourceMap": true,
|
|
16
|
-
"types": ["node", "jest"],
|
|
17
|
-
"resolveJsonModule": true,
|
|
18
|
-
"allowSyntheticDefaultImports": true
|
|
19
|
-
},
|
|
20
|
-
"include": ["src/**/*.ts"],
|
|
21
|
-
"exclude": ["node_modules", "dist", "tests"]
|
|
22
|
-
}
|
package/typedoc.js
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
module.exports = {
|
|
2
|
-
entryPoints: ['./src/index.ts'],
|
|
3
|
-
entryPointStrategy: 'expand',
|
|
4
|
-
out: './docs/typedoc-md',
|
|
5
|
-
plugin: ['typedoc-plugin-markdown'],
|
|
6
|
-
tsconfig: './tsconfig.json',
|
|
7
|
-
exclude: ['**/node_modules/**', '**/tests/**', '**/dist/**'],
|
|
8
|
-
excludePrivate: false,
|
|
9
|
-
excludeProtected: false,
|
|
10
|
-
includeVersion: true,
|
|
11
|
-
readme: 'none',
|
|
12
|
-
disableSources: false,
|
|
13
|
-
categorizeByGroup: true,
|
|
14
|
-
categoryOrder: ['Classes', 'Functions', 'Variables', '*'],
|
|
15
|
-
sort: ['source-order']
|
|
16
|
-
};
|
package/webpack.config.js
DELETED
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
const path = require('path');
|
|
2
|
-
|
|
3
|
-
module.exports = {
|
|
4
|
-
mode: 'production',
|
|
5
|
-
devtool: 'source-map',
|
|
6
|
-
target: 'node',
|
|
7
|
-
entry: './src/index.ts',
|
|
8
|
-
output: {
|
|
9
|
-
filename: 'GrepUtil.bundle.js',
|
|
10
|
-
path: path.resolve(__dirname, 'dist'),
|
|
11
|
-
publicPath: '',
|
|
12
|
-
library: {
|
|
13
|
-
name: 'GrepUtil',
|
|
14
|
-
type: 'umd',
|
|
15
|
-
export: 'default'
|
|
16
|
-
},
|
|
17
|
-
globalObject: 'this'
|
|
18
|
-
},
|
|
19
|
-
module: {
|
|
20
|
-
rules: [
|
|
21
|
-
{
|
|
22
|
-
test: /\.ts$/,
|
|
23
|
-
use: 'ts-loader',
|
|
24
|
-
exclude: /node_modules/
|
|
25
|
-
}
|
|
26
|
-
]
|
|
27
|
-
},
|
|
28
|
-
resolve: {
|
|
29
|
-
extensions: ['.ts', '.js'],
|
|
30
|
-
modules: ['node_modules']
|
|
31
|
-
}
|
|
32
|
-
};
|