@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/jest.config.js CHANGED
@@ -1,16 +1,16 @@
1
- module.exports = {
2
- verbose: true ,
3
- transform: {
4
- '^.+\\.js$' : 'babel-jest'
5
- },
6
- testMatch: [
7
- '**/tests/unit/**/*.spec.(js|jsx|ts|tsx)|**/__tests__/*.(js|jsx|ts|tsx)'
8
- ],
9
- moduleFileExtensions: [
10
- "js",
11
- "jsx"
12
- ],
13
- moduleDirectories: [
14
- "node_modules"
15
- ]
16
- }
1
+ module.exports = {
2
+ verbose: true ,
3
+ transform: {
4
+ '^.+\\.js$' : 'babel-jest'
5
+ },
6
+ testMatch: [
7
+ '**/tests/unit/**/*.spec.(js|jsx|ts|tsx)|**/__tests__/*.(js|jsx|ts|tsx)'
8
+ ],
9
+ moduleFileExtensions: [
10
+ "js",
11
+ "jsx"
12
+ ],
13
+ moduleDirectories: [
14
+ "node_modules"
15
+ ]
16
+ }
@@ -1,31 +1,31 @@
1
- module.exports = {
2
- preset: 'ts-jest',
3
- testEnvironment: 'node',
4
- verbose: true,
5
- roots: ['<rootDir>/tests/unit'],
6
- testMatch: [
7
- '**/tests/unit/**/*.spec.ts',
8
- '**/tests/unit/**/*.test.ts'
9
- ],
10
- transform: {
11
- '^.+\\.ts$': ['ts-jest', {
12
- tsconfig: 'tsconfig.json'
13
- }]
14
- },
15
- moduleFileExtensions: ['ts', 'js', 'json'],
16
- collectCoverage: false,
17
- collectCoverageFrom: [
18
- 'src/**/*.ts',
19
- '!src/**/*.d.ts'
20
- ],
21
- coverageDirectory: 'coverage',
22
- coverageReporters: ['text', 'lcov', 'html'],
23
- coverageThreshold: {
24
- global: {
25
- branches: 80,
26
- functions: 80,
27
- lines: 80,
28
- statements: 80
29
- }
30
- }
31
- };
1
+ module.exports = {
2
+ preset: 'ts-jest',
3
+ testEnvironment: 'node',
4
+ verbose: true,
5
+ roots: ['<rootDir>/tests/unit'],
6
+ testMatch: [
7
+ '**/tests/unit/**/*.spec.ts',
8
+ '**/tests/unit/**/*.test.ts'
9
+ ],
10
+ transform: {
11
+ '^.+\\.ts$': ['ts-jest', {
12
+ tsconfig: 'tsconfig.json'
13
+ }]
14
+ },
15
+ moduleFileExtensions: ['ts', 'js', 'json'],
16
+ collectCoverage: false,
17
+ collectCoverageFrom: [
18
+ 'src/**/*.ts',
19
+ '!src/**/*.d.ts'
20
+ ],
21
+ coverageDirectory: 'coverage',
22
+ coverageReporters: ['text', 'lcov', 'html'],
23
+ coverageThreshold: {
24
+ global: {
25
+ branches: 80,
26
+ functions: 80,
27
+ lines: 80,
28
+ statements: 80
29
+ }
30
+ }
31
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nojaja/greputil",
3
- "version": "1.0.0",
3
+ "version": "1.0.1",
4
4
  "description": "",
5
5
  "main": "./dist/GrepUtil.bundle.js",
6
6
  "scripts": {
@@ -27,7 +27,7 @@
27
27
  "@typescript-eslint/eslint-plugin": "^6.0.0",
28
28
  "@typescript-eslint/parser": "^6.0.0",
29
29
  "cross-env": "^7.0.3",
30
- "dependency-cruiser": "^13.0.0",
30
+ "dependency-cruiser": "^17.3.5",
31
31
  "eslint": "^8.45.0",
32
32
  "eslint-plugin-jsdoc": "^46.0.0",
33
33
  "eslint-plugin-sonarjs": "^0.19.0",
@@ -1,61 +1,61 @@
1
- /**
2
- * 処理名: バッファパターンマッチャークラス
3
- * 処理概要:
4
- * バイナリデータ(Buffer)に対して複数のパターンマッチングを行うクラス。
5
- * 複数のBufferパターンと比較し、いずれかがマッチするか判定する。
6
- * 実装理由:
7
- * ファイルシグネチャ判定やバイナリデータの識別など、
8
- * バイナリレベルでのパターンマッチングが必要なユースケースに対応するため。
9
- * 正規表現では扱えないバイト列の比較を実現する。
10
- */
11
- export class BufferPatternMatcher {
12
- /**
13
- * 処理名: BufferPatternMatcherコンストラクタ
14
- * 処理概要:
15
- * BufferPatternMatcherのインスタンスを作成する。
16
- * 現在は状態を持たないシンプルな実装。
17
- * 実装理由:
18
- * 将来的な拡張性を考慮してクラスとして実装。
19
- * 状態管理やキャッシュ機能を追加する可能性がある。
20
- * @returns BufferPatternMatcherインスタンス
21
- */
22
- constructor() {
23
- // 現在は状態を持たない
24
- }
25
-
26
- /**
27
- * 処理名: バッファパターン比較
28
- * 処理概要:
29
- * バッファを複数のパターンと比較する。
30
- * いずれかのパターンがマッチすればtrue、マッチしなければfalse、
31
- * patternsがnullの場合はnullを返す。
32
- * 実装理由:
33
- * バイナリファイルの種類判定(PNG、JPEG等のシグネチャチェック)や、
34
- * バイト列パターンの検出に使用するため。
35
- * Buffer.compareを使用して効率的なバイト列比較を実現する。
36
- * @param buffer - 比較対象のバッファ
37
- * @param patterns - マッチング対象のバッファパターンの配列
38
- * @returns マッチした場合true、マッチしない場合false、patternsがnullの場合null
39
- * @throws エラーが発生した場合は例外を投げる
40
- */
41
- compareBuf(buffer: Buffer, patterns: Array<Buffer> | null): boolean | null {
42
- try {
43
- if (!patterns) return null;
44
-
45
- for (const pattern of patterns) {
46
- if (pattern.length <= buffer.length &&
47
- pattern.compare(buffer.slice(0, pattern.length)) === 0) {
48
- return true;
49
- }
50
- }
51
- return false;
52
- } catch (error) {
53
- if (error instanceof Error) {
54
- console.error(`正規表現バッファ比較エラー: ${error.message}`);
55
- }
56
- throw error;
57
- }
58
- }
59
- }
60
-
61
- export default BufferPatternMatcher;
1
+ /**
2
+ * 処理名: バッファパターンマッチャークラス
3
+ * 処理概要:
4
+ * バイナリデータ(Buffer)に対して複数のパターンマッチングを行うクラス。
5
+ * 複数のBufferパターンと比較し、いずれかがマッチするか判定する。
6
+ * 実装理由:
7
+ * ファイルシグネチャ判定やバイナリデータの識別など、
8
+ * バイナリレベルでのパターンマッチングが必要なユースケースに対応するため。
9
+ * 正規表現では扱えないバイト列の比較を実現する。
10
+ */
11
+ export class BufferPatternMatcher {
12
+ /**
13
+ * 処理名: BufferPatternMatcherコンストラクタ
14
+ * 処理概要:
15
+ * BufferPatternMatcherのインスタンスを作成する。
16
+ * 現在は状態を持たないシンプルな実装。
17
+ * 実装理由:
18
+ * 将来的な拡張性を考慮してクラスとして実装。
19
+ * 状態管理やキャッシュ機能を追加する可能性がある。
20
+ * @returns BufferPatternMatcherインスタンス
21
+ */
22
+ constructor() {
23
+ // 現在は状態を持たない
24
+ }
25
+
26
+ /**
27
+ * 処理名: バッファパターン比較
28
+ * 処理概要:
29
+ * バッファを複数のパターンと比較する。
30
+ * いずれかのパターンがマッチすればtrue、マッチしなければfalse、
31
+ * patternsがnullの場合はnullを返す。
32
+ * 実装理由:
33
+ * バイナリファイルの種類判定(PNG、JPEG等のシグネチャチェック)や、
34
+ * バイト列パターンの検出に使用するため。
35
+ * Buffer.compareを使用して効率的なバイト列比較を実現する。
36
+ * @param buffer - 比較対象のバッファ
37
+ * @param patterns - マッチング対象のバッファパターンの配列
38
+ * @returns マッチした場合true、マッチしない場合false、patternsがnullの場合null
39
+ * @throws エラーが発生した場合は例外を投げる
40
+ */
41
+ compareBuf(buffer: Buffer, patterns: Array<Buffer> | null): boolean | null {
42
+ try {
43
+ if (!patterns) return null;
44
+
45
+ for (const pattern of patterns) {
46
+ if (pattern.length <= buffer.length &&
47
+ pattern.compare(buffer.slice(0, pattern.length)) === 0) {
48
+ return true;
49
+ }
50
+ }
51
+ return false;
52
+ } catch (error) {
53
+ if (error instanceof Error) {
54
+ console.error(`正規表現バッファ比較エラー: ${error.message}`);
55
+ }
56
+ throw error;
57
+ }
58
+ }
59
+ }
60
+
61
+ export default BufferPatternMatcher;
@@ -1,209 +1,209 @@
1
- /**
2
- * 処理名: 正規表現配列クラス
3
- *
4
- * 処理概要:
5
- * 複数の正規表現パターンを配列として管理し、文字列に対して順次適用するためのクラス。
6
- * 文字列、RegExpオブジェクト、[パターン, フラグ]配列の混在をサポートする。
7
- *
8
- * 実装理由:
9
- * 標準のJavaScript正規表現APIでは単一パターンのみ扱えるため、
10
- * 複数パターンの一括処理を簡潔に記述できるユーティリティクラスが必要。
11
- * grepのような複数パターンマッチングを効率的に実装するため。
12
- */
13
- export class RegExpArray {
14
- /**
15
- * 正規表現インスタンスのリスト
16
- */
17
- private regExpInstanceList: RegExp[];
18
-
19
- /**
20
- * ソースパターンとフラグのリスト
21
- */
22
- private sourceLiat: Array<[string, string]>;
23
-
24
- /**
25
- * 最後に実行された正規表現
26
- */
27
- public last: RegExp | null;
28
-
29
- /**
30
- * 処理名: RegExpArrayコンストラクタ
31
- *
32
- * 処理概要:
33
- * 複数の正規表現パターンからインスタンスを作成する。
34
- * 文字列、RegExpオブジェクト、[パターン, フラグ]配列の混在可能。
35
- *
36
- * 実装理由:
37
- * 柔軟なパターン指定を可能にし、様々な入力形式に対応するため。
38
- * 配列でない単一パターンも自動的に配列化して統一的に処理する。
39
- * @param patternList - 正規表現パターンのリスト(文字列、RegExp、[パターン, フラグ]の配列)
40
- * @returns RegExpArrayインスタンス
41
- */
42
- constructor(patternList?: RegExp | string | Array<string> | Array<RegExp | string | Array<string>>) {
43
- const _patternList = (!patternList)
44
- ? []
45
- : (!Array.isArray(patternList))
46
- ? [patternList]
47
- : patternList;
48
-
49
- this.regExpInstanceList = _patternList.map((pattern) => {
50
- if (pattern instanceof RegExp) {
51
- return pattern;
52
- } else if (Array.isArray(pattern)) {
53
- return new RegExp(pattern[0], pattern[1]);
54
- } else {
55
- return new RegExp(pattern);
56
- }
57
- });
58
-
59
- this.sourceLiat = this.regExpInstanceList.map((regExp) =>
60
- [regExp.source, regExp.flags]
61
- );
62
- this.last = null;
63
- }
64
-
65
- /**
66
- * 処理名: 順次マッチング実行
67
- *
68
- * 処理概要:
69
- * 各正規表現を順次実行し、すべてのマッチ結果を配列で返す。
70
- * グローバルフラグ使用時はステートフルに動作する。
71
- *
72
- * 実装理由:
73
- * 複数パターンのマッチ結果を一度に取得するため。
74
- * reduceを使用して効率的に結果を集約する。
75
- * @param string - マッチング対象の文字列
76
- * @returns マッチした文字列の配列
77
- */
78
- exec(string: string): string[] {
79
- return this.regExpInstanceList.reduce((previousValue, regexp) => {
80
- this.last = regexp;
81
- const result = regexp.exec(string);
82
- return (result) ? previousValue.concat([...result]) : previousValue;
83
- }, [] as string[]);
84
- }
85
-
86
- /**
87
- * 処理名: 最初のマッチ取得
88
- *
89
- * 処理概要:
90
- * 最初にマッチした正規表現の結果を返す。
91
- * マッチしない場合はnullを返す。
92
- *
93
- * 実装理由:
94
- * 全パターンをテストする必要がなく、最初のマッチで処理を終了できるため効率的。
95
- * testメソッドの内部実装としても使用される。
96
- * @param string - マッチング対象の文字列
97
- * @returns マッチ結果の配列、またはnull
98
- */
99
- firstMatch(string: string): RegExpExecArray | null {
100
- for (const regexp of this.regExpInstanceList) {
101
- this.last = regexp;
102
- const result = regexp.exec(string);
103
- if (result) return result;
104
- }
105
- return null;
106
- }
107
-
108
- /**
109
- * 処理名: マッチテスト
110
- *
111
- * 処理概要:
112
- * いずれかの正規表現がマッチすればtrueを返す。
113
- * グローバルフラグ使用時はステートフルに動作する。
114
- *
115
- * 実装理由:
116
- * 真偽値のみが必要な場合に、マッチ結果の詳細を取得するオーバーヘッドを避けるため。
117
- * firstMatchの結果を利用して効率的に判定する。
118
- * @param string - テスト対象の文字列
119
- * @returns マッチする場合true、しない場合false
120
- */
121
- test(string: string): boolean {
122
- return this.firstMatch(string) !== null;
123
- }
124
-
125
- /**
126
- * 処理名: RegExp配列取得
127
- *
128
- * 処理概要:
129
- * 内部で保持している正規表現オブジェクトの配列を返す。
130
- *
131
- * 実装理由:
132
- * インスタンス内部の正規表現を外部から参照・検査できるようにするため。
133
- * デバッグやテスト時に有用。
134
- * @returns 正規表現オブジェクトの配列
135
- */
136
- toArray(): RegExp[] {
137
- return this.regExpInstanceList;
138
- }
139
-
140
- /**
141
- * 処理名: 全マッチ結果取得(静的メソッド)
142
- *
143
- * 処理概要:
144
- * 複数の正規表現パターンに対するすべてのマッチ結果を二次元配列で返す。
145
- * regexpsがnullの場合はnullを返す。
146
- *
147
- * 実装理由:
148
- * インスタンスを作成せずに一時的なマッチング処理を実行できるようにするため。
149
- * String.prototype.matchAllを活用して効率的にマッチングを行う。
150
- * @param string - マッチング対象の文字列
151
- * @param regexps - 正規表現パターン(単一または配列)、nullの場合はnullを返す
152
- * @returns マッチ結果の二次元配列、またはnull
153
- * @throws エラーが発生した場合は例外を投げる
154
- */
155
- static matchAll(string: string, regexps: RegExp | string | Array<RegExp | string> | null): Array<Array<string>> | null {
156
- if (regexps === null) return null;
157
- const _regexps = (!Array.isArray(regexps)) ? [regexps] : regexps;
158
- return _regexps.reduce((previousValue, regexp) => {
159
- const matches = Array.from(string.matchAll(regexp instanceof RegExp ? regexp : new RegExp(regexp, 'g')));
160
- return previousValue.concat(matches.map(m => Array.from(m)));
161
- }, [] as Array<Array<string>>);
162
- }
163
-
164
- /**
165
- * 処理名: 最初のマッチ取得(静的メソッド)
166
- *
167
- * 処理概要:
168
- * 複数の正規表現パターンから最初にマッチした結果を返す。
169
- * regexpsがnullの場合はnullを返す。
170
- *
171
- * 実装理由:
172
- * インスタンスを作成せずに一時的なマッチング処理を実行できるようにするため。
173
- * 最初のマッチで処理を終了するため効率的。
174
- * @param string - マッチング対象の文字列
175
- * @param regexps - 正規表現パターン(単一または配列)、nullの場合はnullを返す
176
- * @returns マッチ結果の配列、またはnull
177
- * @throws エラーが発生した場合は例外を投げる
178
- */
179
- static firstMatch(string: string, regexps: RegExp | string | Array<RegExp | string> | null): RegExpExecArray | null {
180
- if (regexps === null) return null;
181
- const _regexps = (!Array.isArray(regexps)) ? [regexps] : regexps;
182
- for (const regexp of _regexps) {
183
- const _regexp = regexp instanceof RegExp ? regexp : new RegExp(regexp);
184
- const result = _regexp.exec(string);
185
- if (result) return result;
186
- }
187
- return null;
188
- }
189
-
190
- /**
191
- * 処理名: マッチテスト(静的メソッド)
192
- *
193
- * 処理概要:
194
- * 複数の正規表現パターンのいずれかがマッチするか判定する。
195
- * 内部でfirstMatchを使用して効率的に判定。
196
- *
197
- * 実装理由:
198
- * インスタンスを作成せずに真偽値判定を行えるようにするため。
199
- * firstMatchの結果を利用して簡潔に実装。
200
- * @param string - テスト対象の文字列
201
- * @param regexps - 正規表現パターン(単一または配列)
202
- * @returns マッチする場合true、しない場合false
203
- */
204
- static test(string: string, regexps: RegExp | string | Array<RegExp | string> | null): boolean {
205
- return RegExpArray.firstMatch(string, regexps) !== null;
206
- }
207
- }
208
-
209
- export default RegExpArray;
1
+ /**
2
+ * 処理名: 正規表現配列クラス
3
+ *
4
+ * 処理概要:
5
+ * 複数の正規表現パターンを配列として管理し、文字列に対して順次適用するためのクラス。
6
+ * 文字列、RegExpオブジェクト、[パターン, フラグ]配列の混在をサポートする。
7
+ *
8
+ * 実装理由:
9
+ * 標準のJavaScript正規表現APIでは単一パターンのみ扱えるため、
10
+ * 複数パターンの一括処理を簡潔に記述できるユーティリティクラスが必要。
11
+ * grepのような複数パターンマッチングを効率的に実装するため。
12
+ */
13
+ export class RegExpArray {
14
+ /**
15
+ * 正規表現インスタンスのリスト
16
+ */
17
+ private regExpInstanceList: RegExp[];
18
+
19
+ /**
20
+ * ソースパターンとフラグのリスト
21
+ */
22
+ private sourceLiat: Array<[string, string]>;
23
+
24
+ /**
25
+ * 最後に実行された正規表現
26
+ */
27
+ public last: RegExp | null;
28
+
29
+ /**
30
+ * 処理名: RegExpArrayコンストラクタ
31
+ *
32
+ * 処理概要:
33
+ * 複数の正規表現パターンからインスタンスを作成する。
34
+ * 文字列、RegExpオブジェクト、[パターン, フラグ]配列の混在可能。
35
+ *
36
+ * 実装理由:
37
+ * 柔軟なパターン指定を可能にし、様々な入力形式に対応するため。
38
+ * 配列でない単一パターンも自動的に配列化して統一的に処理する。
39
+ * @param patternList - 正規表現パターンのリスト(文字列、RegExp、[パターン, フラグ]の配列)
40
+ * @returns RegExpArrayインスタンス
41
+ */
42
+ constructor(patternList?: RegExp | string | Array<string> | Array<RegExp | string | Array<string>>) {
43
+ const _patternList = (!patternList)
44
+ ? []
45
+ : (!Array.isArray(patternList))
46
+ ? [patternList]
47
+ : patternList;
48
+
49
+ this.regExpInstanceList = _patternList.map((pattern) => {
50
+ if (pattern instanceof RegExp) {
51
+ return pattern;
52
+ } else if (Array.isArray(pattern)) {
53
+ return new RegExp(pattern[0], pattern[1]);
54
+ } else {
55
+ return new RegExp(pattern);
56
+ }
57
+ });
58
+
59
+ this.sourceLiat = this.regExpInstanceList.map((regExp) =>
60
+ [regExp.source, regExp.flags]
61
+ );
62
+ this.last = null;
63
+ }
64
+
65
+ /**
66
+ * 処理名: 順次マッチング実行
67
+ *
68
+ * 処理概要:
69
+ * 各正規表現を順次実行し、すべてのマッチ結果を配列で返す。
70
+ * グローバルフラグ使用時はステートフルに動作する。
71
+ *
72
+ * 実装理由:
73
+ * 複数パターンのマッチ結果を一度に取得するため。
74
+ * reduceを使用して効率的に結果を集約する。
75
+ * @param string - マッチング対象の文字列
76
+ * @returns マッチした文字列の配列
77
+ */
78
+ exec(string: string): string[] {
79
+ return this.regExpInstanceList.reduce((previousValue, regexp) => {
80
+ this.last = regexp;
81
+ const result = regexp.exec(string);
82
+ return (result) ? previousValue.concat([...result]) : previousValue;
83
+ }, [] as string[]);
84
+ }
85
+
86
+ /**
87
+ * 処理名: 最初のマッチ取得
88
+ *
89
+ * 処理概要:
90
+ * 最初にマッチした正規表現の結果を返す。
91
+ * マッチしない場合はnullを返す。
92
+ *
93
+ * 実装理由:
94
+ * 全パターンをテストする必要がなく、最初のマッチで処理を終了できるため効率的。
95
+ * testメソッドの内部実装としても使用される。
96
+ * @param string - マッチング対象の文字列
97
+ * @returns マッチ結果の配列、またはnull
98
+ */
99
+ firstMatch(string: string): RegExpExecArray | null {
100
+ for (const regexp of this.regExpInstanceList) {
101
+ this.last = regexp;
102
+ const result = regexp.exec(string);
103
+ if (result) return result;
104
+ }
105
+ return null;
106
+ }
107
+
108
+ /**
109
+ * 処理名: マッチテスト
110
+ *
111
+ * 処理概要:
112
+ * いずれかの正規表現がマッチすればtrueを返す。
113
+ * グローバルフラグ使用時はステートフルに動作する。
114
+ *
115
+ * 実装理由:
116
+ * 真偽値のみが必要な場合に、マッチ結果の詳細を取得するオーバーヘッドを避けるため。
117
+ * firstMatchの結果を利用して効率的に判定する。
118
+ * @param string - テスト対象の文字列
119
+ * @returns マッチする場合true、しない場合false
120
+ */
121
+ test(string: string): boolean {
122
+ return this.firstMatch(string) !== null;
123
+ }
124
+
125
+ /**
126
+ * 処理名: RegExp配列取得
127
+ *
128
+ * 処理概要:
129
+ * 内部で保持している正規表現オブジェクトの配列を返す。
130
+ *
131
+ * 実装理由:
132
+ * インスタンス内部の正規表現を外部から参照・検査できるようにするため。
133
+ * デバッグやテスト時に有用。
134
+ * @returns 正規表現オブジェクトの配列
135
+ */
136
+ toArray(): RegExp[] {
137
+ return this.regExpInstanceList;
138
+ }
139
+
140
+ /**
141
+ * 処理名: 全マッチ結果取得(静的メソッド)
142
+ *
143
+ * 処理概要:
144
+ * 複数の正規表現パターンに対するすべてのマッチ結果を二次元配列で返す。
145
+ * regexpsがnullの場合はnullを返す。
146
+ *
147
+ * 実装理由:
148
+ * インスタンスを作成せずに一時的なマッチング処理を実行できるようにするため。
149
+ * String.prototype.matchAllを活用して効率的にマッチングを行う。
150
+ * @param string - マッチング対象の文字列
151
+ * @param regexps - 正規表現パターン(単一または配列)、nullの場合はnullを返す
152
+ * @returns マッチ結果の二次元配列、またはnull
153
+ * @throws エラーが発生した場合は例外を投げる
154
+ */
155
+ static matchAll(string: string, regexps: RegExp | string | Array<RegExp | string> | null): Array<Array<string>> | null {
156
+ if (regexps === null) return null;
157
+ const _regexps = (!Array.isArray(regexps)) ? [regexps] : regexps;
158
+ return _regexps.reduce((previousValue, regexp) => {
159
+ const matches = Array.from(string.matchAll(regexp instanceof RegExp ? regexp : new RegExp(regexp, 'g')));
160
+ return previousValue.concat(matches.map(m => Array.from(m)));
161
+ }, [] as Array<Array<string>>);
162
+ }
163
+
164
+ /**
165
+ * 処理名: 最初のマッチ取得(静的メソッド)
166
+ *
167
+ * 処理概要:
168
+ * 複数の正規表現パターンから最初にマッチした結果を返す。
169
+ * regexpsがnullの場合はnullを返す。
170
+ *
171
+ * 実装理由:
172
+ * インスタンスを作成せずに一時的なマッチング処理を実行できるようにするため。
173
+ * 最初のマッチで処理を終了するため効率的。
174
+ * @param string - マッチング対象の文字列
175
+ * @param regexps - 正規表現パターン(単一または配列)、nullの場合はnullを返す
176
+ * @returns マッチ結果の配列、またはnull
177
+ * @throws エラーが発生した場合は例外を投げる
178
+ */
179
+ static firstMatch(string: string, regexps: RegExp | string | Array<RegExp | string> | null): RegExpExecArray | null {
180
+ if (regexps === null) return null;
181
+ const _regexps = (!Array.isArray(regexps)) ? [regexps] : regexps;
182
+ for (const regexp of _regexps) {
183
+ const _regexp = regexp instanceof RegExp ? regexp : new RegExp(regexp);
184
+ const result = _regexp.exec(string);
185
+ if (result) return result;
186
+ }
187
+ return null;
188
+ }
189
+
190
+ /**
191
+ * 処理名: マッチテスト(静的メソッド)
192
+ *
193
+ * 処理概要:
194
+ * 複数の正規表現パターンのいずれかがマッチするか判定する。
195
+ * 内部でfirstMatchを使用して効率的に判定。
196
+ *
197
+ * 実装理由:
198
+ * インスタンスを作成せずに真偽値判定を行えるようにするため。
199
+ * firstMatchの結果を利用して簡潔に実装。
200
+ * @param string - テスト対象の文字列
201
+ * @param regexps - 正規表現パターン(単一または配列)
202
+ * @returns マッチする場合true、しない場合false
203
+ */
204
+ static test(string: string, regexps: RegExp | string | Array<RegExp | string> | null): boolean {
205
+ return RegExpArray.firstMatch(string, regexps) !== null;
206
+ }
207
+ }
208
+
209
+ export default RegExpArray;