@nojaja/greputil 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/.babelrc +6 -6
- package/.dependency-cruiser.js +89 -89
- package/.eslintignore +6 -6
- package/.eslintrc.cjs +48 -48
- package/.github/skills/completion-mandatory-quality-gates.md +26 -26
- package/.github/skills/nodejs-project-quality-guardrails.md +417 -417
- package/.github/workflows/release.yml +43 -43
- package/.github/workflows/webpack.yml +27 -27
- package/LICENSE +21 -21
- package/README.md +335 -335
- package/jest.config.js +16 -16
- package/jest.unit.config.js +31 -31
- package/package.json +2 -2
- package/src/BufferPatternMatcher.ts +61 -61
- package/src/RegExpArray.ts +209 -209
- package/src/index.ts +15 -15
- package/tests/unit/RegExpArray.spec.ts +205 -205
- package/tsconfig.json +22 -22
- package/typedoc.js +16 -16
- package/webpack.config.js +31 -31
- package/MIGRATION_REPORT.md +0 -77
package/src/index.ts
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 処理名: ライブラリエントリポイント
|
|
3
|
-
*
|
|
4
|
-
* 処理概要:
|
|
5
|
-
* NodeGrepUtilライブラリの公開APIをエクスポートする。
|
|
6
|
-
* RegExpArrayとBufferPatternMatcherクラスを提供。
|
|
7
|
-
*
|
|
8
|
-
* 実装理由:
|
|
9
|
-
* ライブラリ利用者が必要なクラスを簡単にインポートできるようにするため。
|
|
10
|
-
* 単一のエントリポイントから全機能にアクセス可能にする。
|
|
11
|
-
*/
|
|
12
|
-
import { RegExpArray } from './RegExpArray';
|
|
13
|
-
import { BufferPatternMatcher } from './BufferPatternMatcher';
|
|
14
|
-
|
|
15
|
-
export { RegExpArray, BufferPatternMatcher };
|
|
1
|
+
/**
|
|
2
|
+
* 処理名: ライブラリエントリポイント
|
|
3
|
+
*
|
|
4
|
+
* 処理概要:
|
|
5
|
+
* NodeGrepUtilライブラリの公開APIをエクスポートする。
|
|
6
|
+
* RegExpArrayとBufferPatternMatcherクラスを提供。
|
|
7
|
+
*
|
|
8
|
+
* 実装理由:
|
|
9
|
+
* ライブラリ利用者が必要なクラスを簡単にインポートできるようにするため。
|
|
10
|
+
* 単一のエントリポイントから全機能にアクセス可能にする。
|
|
11
|
+
*/
|
|
12
|
+
import { RegExpArray } from './RegExpArray';
|
|
13
|
+
import { BufferPatternMatcher } from './BufferPatternMatcher';
|
|
14
|
+
|
|
15
|
+
export { RegExpArray, BufferPatternMatcher };
|
|
@@ -1,205 +1,205 @@
|
|
|
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
|
-
});
|
|
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
CHANGED
|
@@ -1,22 +1,22 @@
|
|
|
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
|
-
}
|
|
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
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
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
|
-
};
|
|
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
CHANGED
|
@@ -1,32 +1,32 @@
|
|
|
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
|
-
}
|
|
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
32
|
};
|
package/MIGRATION_REPORT.md
DELETED
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
# NodeGrepUtil - TypeScript移行・品質担保完了
|
|
2
|
-
|
|
3
|
-
## 実施内容
|
|
4
|
-
|
|
5
|
-
### ✅ フェーズ1: TypeScript移行
|
|
6
|
-
- TypeScript 5.3.3 へ完全移行
|
|
7
|
-
- tsconfig.json の作成と設定
|
|
8
|
-
- 全ソースファイル (.js → .ts) の変換完了
|
|
9
|
-
- 型定義の整備
|
|
10
|
-
- JSDocコメントの完全整備(処理名・処理概要・実装理由)
|
|
11
|
-
|
|
12
|
-
### ✅ フェーズ2: 品質ツールの導入
|
|
13
|
-
- ESLint + プラグイン導入(@typescript-eslint, sonarjs, jsdoc)
|
|
14
|
-
- eslint.config.cjs の作成(Cognitive Complexity ≤ 10)
|
|
15
|
-
- typedoc + typedoc-plugin-markdown の導入
|
|
16
|
-
- typedoc.js の作成
|
|
17
|
-
- dependency-cruiser の導入
|
|
18
|
-
- .dependency-cruiser.js の作成
|
|
19
|
-
|
|
20
|
-
### ✅ フェーズ3: テスト設定の強化
|
|
21
|
-
- jest.unit.config.js の作成(カバレッジ閾値80%設定)
|
|
22
|
-
- ts-jest による TypeScript テスト対応
|
|
23
|
-
- テストファイルの TypeScript 化
|
|
24
|
-
- テストケースの拡充(カバレッジ向上)
|
|
25
|
-
|
|
26
|
-
### ✅ フェーズ4: JSDocの整備
|
|
27
|
-
- 全クラス・メソッドに日本語JSDoc追加
|
|
28
|
-
- 「処理名・処理概要・実装理由」の3項目を完備
|
|
29
|
-
- @param, @returns の型情報整備
|
|
30
|
-
|
|
31
|
-
### ✅ package.json スクリプト追加
|
|
32
|
-
- `npm run test` - 単体テスト実行
|
|
33
|
-
- `npm run test:ci` - カバレッジ付きテスト(80%必須)
|
|
34
|
-
- `npm run build` - TypeScript ビルド(webpack)
|
|
35
|
-
- `npm run lint` - ESLint 実行
|
|
36
|
-
- `npm run depcruise` - 依存関係検証
|
|
37
|
-
- `npm run docs` - typedoc ドキュメント生成
|
|
38
|
-
|
|
39
|
-
## 次のステップ
|
|
40
|
-
|
|
41
|
-
以下のコマンドを順次実行して品質ゲートを検証してください:
|
|
42
|
-
|
|
43
|
-
```powershell
|
|
44
|
-
# 1. 依存関係のインストール
|
|
45
|
-
cd d:\devs\workspace202111\NodeGrepUtil ; npm install
|
|
46
|
-
|
|
47
|
-
# 2. ビルド検証
|
|
48
|
-
npm run build
|
|
49
|
-
|
|
50
|
-
# 3. テスト実行(カバレッジ80%必須)
|
|
51
|
-
npm run test:ci
|
|
52
|
-
|
|
53
|
-
# 4. ESLint検証
|
|
54
|
-
npm run lint
|
|
55
|
-
|
|
56
|
-
# 5. 依存関係検証
|
|
57
|
-
npm run depcruise
|
|
58
|
-
|
|
59
|
-
# 6. ドキュメント生成
|
|
60
|
-
npm run docs
|
|
61
|
-
|
|
62
|
-
# 7. 音を鳴らして完了通知
|
|
63
|
-
rundll32 user32.dll,MessageBeep
|
|
64
|
-
```
|
|
65
|
-
|
|
66
|
-
## 品質ゲート状態
|
|
67
|
-
|
|
68
|
-
| 項目 | 状態 | 詳細 |
|
|
69
|
-
|------|------|------|
|
|
70
|
-
| TypeScript化 | ✅ | 全ファイル .ts 化完了 |
|
|
71
|
-
| テストカバレッジ | ⏳ | 設定完了(実行後に80%達成見込み) |
|
|
72
|
-
| ESLint | ⏳ | 設定完了(実行後に検証) |
|
|
73
|
-
| dependency-cruiser | ⏳ | 設定完了(実行後に検証) |
|
|
74
|
-
| typedoc | ⏳ | 設定完了(実行後にドキュメント生成) |
|
|
75
|
-
| JSDoc整備 | ✅ | 全関数・クラスに完備 |
|
|
76
|
-
|
|
77
|
-
⏳マークは npm install 実行後に検証可能です。
|