From 74b1adc2b07a28d9b64485a69cf72d8d4b3de53d Mon Sep 17 00:00:00 2001 From: electrovir Date: Sun, 24 Oct 2021 18:33:48 -0600 Subject: [PATCH] remove most augment functions into augment-vir Use augment-vir package in place of having all these one-off augments. --- README.md | 2 - package-lock.json | 19 +- package.json | 9 +- src/augments/array.test.ts | 43 ---- src/augments/array.ts | 9 - src/augments/date.test.ts | 103 -------- src/augments/date.ts | 101 ++------ src/augments/object.ts | 13 - src/augments/regexp.test.ts | 39 --- src/augments/regexp.ts | 17 -- src/augments/string.test.ts | 240 ------------------ src/augments/string.ts | 142 ----------- src/augments/type.ts | 21 -- src/augments/type.type.test.ts | 9 - src/package-contents.test.ts | 2 +- src/parser/all-parsers.ts | 2 +- .../chase-prime-visa-credit-card-parser.ts | 11 +- .../citi-costco-visa-credit-card-parser.ts | 20 +- .../implemented-parsers/example-parser.ts | 8 +- .../implemented-parsers/paypal-parser.ts | 27 +- .../usaa-bank-account-parser.ts | 18 +- .../usaa-visa-credit-card-parser.ts | 9 +- src/parser/parser-state-machine.ts | 2 +- src/parser/statement-parser.ts | 2 +- src/pdf/read-pdf.test.ts | 2 +- src/readme-version.test.ts | 63 ----- src/sanitizer/sanitize-for-test-file-cli.ts | 2 +- src/sanitizer/sanitized-test.test.ts | 2 +- src/sanitizer/sanitized-test.ts | 4 +- src/sanitizer/sanitizer.test.ts | 8 +- src/sanitizer/sanitizer.ts | 10 +- 31 files changed, 107 insertions(+), 852 deletions(-) delete mode 100644 src/augments/array.test.ts delete mode 100644 src/augments/array.ts delete mode 100644 src/augments/date.test.ts delete mode 100644 src/augments/object.ts delete mode 100644 src/augments/regexp.test.ts delete mode 100644 src/augments/regexp.ts delete mode 100644 src/augments/string.test.ts delete mode 100644 src/augments/string.ts delete mode 100644 src/augments/type.ts delete mode 100644 src/augments/type.type.test.ts delete mode 100644 src/readme-version.test.ts diff --git a/README.md b/README.md index 1341462..ad0ec4a 100644 --- a/README.md +++ b/README.md @@ -260,5 +260,3 @@ If you find that your statement PDF is coming from a bank or credit card that th 3. Add new `runTest` calls for the tests you want to add. See other test files for examples, such as [`array.test.ts`](https://github.com/electrovir/statement-parser/tree/master/src/augments/array.test.ts). - -> v2.0.0 diff --git a/package-lock.json b/package-lock.json index 4b691fd..4bebc36 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,13 +1,14 @@ { "name": "statement-parser", - "version": "2.0.0", + "version": "2.0.1", "lockfileVersion": 2, "requires": true, "packages": { "": { - "version": "2.0.0", + "version": "2.0.1", "license": "MIT", "dependencies": { + "augment-vir": "^1.3.0", "fs-extra": "^10.0.0", "fsm-vir": "^1.0.1", "pdf-text-reader": "^3.0.0", @@ -874,10 +875,9 @@ } }, "node_modules/augment-vir": { - "version": "1.2.1", - "resolved": "https://registry.npmjs.org/augment-vir/-/augment-vir-1.2.1.tgz", - "integrity": "sha512-EELP3loYadA3PyPfxnEpj9aFHpVSGzKyRY+2/0amlTvbV8OWD5ur1NUx9JcHy6UnUi5sqCs7V05K+AKtMJd2eg==", - "dev": true, + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/augment-vir/-/augment-vir-1.3.0.tgz", + "integrity": "sha512-pZl3wtZYq5VNJSllFcJvEIkdWvCfO5k5T03TnObWZwpOdvqjRG9lXZ3m0TdmqOtYLzDyxA/2wtGsgwKdO+kn3Q==", "dependencies": { "fs-extra": "^10.0.0" } @@ -5172,10 +5172,9 @@ "dev": true }, "augment-vir": { - "version": "1.2.1", - "resolved": "https://registry.npmjs.org/augment-vir/-/augment-vir-1.2.1.tgz", - "integrity": "sha512-EELP3loYadA3PyPfxnEpj9aFHpVSGzKyRY+2/0amlTvbV8OWD5ur1NUx9JcHy6UnUi5sqCs7V05K+AKtMJd2eg==", - "dev": true, + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/augment-vir/-/augment-vir-1.3.0.tgz", + "integrity": "sha512-pZl3wtZYq5VNJSllFcJvEIkdWvCfO5k5T03TnObWZwpOdvqjRG9lXZ3m0TdmqOtYLzDyxA/2wtGsgwKdO+kn3Q==", "requires": { "fs-extra": "^10.0.0" } diff --git a/package.json b/package.json index e31232e..5c84af2 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "statement-parser", - "version": "2.0.0", + "version": "2.0.1", "description": "Parse bank and credit card statements.", "keywords": [ "pdf", @@ -36,18 +36,19 @@ "main": "dist/src/index.js", "typings": "dist/src/index.d.ts", "scripts": { - "format": "virmator format write", + "format": "virmator format", "prepublishOnly": "npm run test:full", "sanitize": "virmator compile && node dist/sanitizer/sanitize-for-test-file-cli.js", "sanitize:all": "./bulk-sanitize.sh files/downloads", "sanitize:no-compile": "node dist/sanitizer/sanitize-for-test-file-cli.js", "spellcheck": "virmator spellcheck", - "update-docs": "virmator code-in-markdown README.md", "test": "virmator test", "test:file": "./test-specific-file.sh", - "test:full": "npm run test && npm run spellcheck && npm run format check" + "test:full": "npm run test && npm run spellcheck && npm run format check && npm run update-docs -- --check", + "update-docs": "virmator code-in-markdown README.md" }, "dependencies": { + "augment-vir": "^1.3.0", "fs-extra": "^10.0.0", "fsm-vir": "^1.0.1", "pdf-text-reader": "^3.0.0", diff --git a/src/augments/array.test.ts b/src/augments/array.test.ts deleted file mode 100644 index 7172d82..0000000 --- a/src/augments/array.test.ts +++ /dev/null @@ -1,43 +0,0 @@ -import {testGroup} from 'test-vir'; -import {flatten2dArray, trimArray} from './array'; - -testGroup({ - description: trimArray.name, - tests: (runTest) => { - runTest({ - description: 'white space is removed', - expect: ['who is this', 'what do you want', 'hello there'], - test: () => { - return trimArray( - ` - who is this - what do you want - hello there - - - `.split('\n'), - ); - }, - }); - }, -}); - -testGroup({ - description: flatten2dArray.name, - tests: (runTest) => { - runTest({ - description: 'array ordering is preserved and collapsed', - expect: [1, 2, 3, 4, 5, 6, 0, 7, 8, 9, 10, 11, 12, 21, 22, 22, 1, 0, -1], - test: () => { - return flatten2dArray([ - [1, 2, 3], - [4, 5, 6, 0], - [7, 8, 9], - [10], - [11, 12], - [21, 22, 22, 1, 0, -1], - ]); - }, - }); - }, -}); diff --git a/src/augments/array.ts b/src/augments/array.ts deleted file mode 100644 index f7e527f..0000000 --- a/src/augments/array.ts +++ /dev/null @@ -1,9 +0,0 @@ -export function flatten2dArray(pages: T[][]): T[] { - const flattened: T[] = pages.reduce((accum: T[], row) => accum.concat(row), []); - - return flattened; -} - -export function trimArray(input: string[]): string[] { - return input.map((line) => line.trim()).filter((line) => line !== ''); -} diff --git a/src/augments/date.test.ts b/src/augments/date.test.ts deleted file mode 100644 index 26daa7e..0000000 --- a/src/augments/date.test.ts +++ /dev/null @@ -1,103 +0,0 @@ -import {testGroup} from 'test-vir'; -import { - createUtcDate, - dateFromNamedCommaFormat, - dateFromSlashFormat, - InvalidDateError, -} from './date'; - -testGroup({ - description: dateFromSlashFormat.name, - tests: (runTest) => { - runTest({ - description: 'creates date from valid slash formatted input', - expect: '2000-01-01T00:00:00.000Z', - test: () => dateFromSlashFormat('01/01/2000').toISOString(), - }); - runTest({ - description: 'handles lack of year', - expect: '0000-01-01T00:00:00.000Z', - test: () => dateFromSlashFormat('01/01').toISOString(), - }); - runTest({ - description: 'handles lack of year with short year prefix', - expect: '0200-01-01T00:00:00.000Z', - test: () => dateFromSlashFormat('01/01', 2).toISOString(), - }); - runTest({ - description: 'handles lack of year with full year prefix', - expect: '2000-01-01T00:00:00.000Z', - test: () => dateFromSlashFormat('01/01', 20).toISOString(), - }); - runTest({ - description: 'handles year with full prefix', - expect: '2020-01-01T00:00:00.000Z', - test: () => dateFromSlashFormat('01/01/20', 20).toISOString(), - }); - runTest({ - description: 'handles year with partial prefix', - expect: '0220-01-01T00:00:00.000Z', - test: () => dateFromSlashFormat('01/01/20', 2).toISOString(), - }); - runTest({ - description: 'handles year with no prefix', - expect: '0020-01-01T00:00:00.000Z', - test: () => dateFromSlashFormat('01/01/20').toISOString(), - }); - }, -}); - -testGroup({ - description: createUtcDate.name, - tests: (runTest) => { - runTest({ - description: 'creates date from valid iso formatted string', - expect: '2020-02-20T00:00:00.000Z', - test: () => createUtcDate('2020-02-20').toISOString(), - }); - runTest({ - description: 'errors on invalid string input', - expectError: { - errorClass: InvalidDateError, - }, - test: () => createUtcDate('nothing to see here').toISOString(), - }); - }, -}); - -testGroup({ - description: dateFromNamedCommaFormat.name, - tests: (runTest) => { - runTest({ - description: 'errors on invalid string format', - expectError: { - errorClass: InvalidDateError, - }, - test: () => dateFromNamedCommaFormat('2020-02-20').toISOString(), - }); - - runTest({ - description: 'works on validly formatted inputs', - expect: '2019-08-17T00:00:00.000Z', - test: () => dateFromNamedCommaFormat('Aug 17, 2019').toISOString(), - }); - - runTest({ - description: 'works on the beginning of the year', - expect: '2017-01-01T00:00:00.000Z', - test: () => dateFromNamedCommaFormat('Jan 1, 2017').toISOString(), - }); - - runTest({ - description: 'works on the end of the year', - expect: '2017-12-31T00:00:00.000Z', - test: () => dateFromNamedCommaFormat('Dec 31, 2017').toISOString(), - }); - - runTest({ - description: 'works with lowercase month', - expect: '2017-12-31T00:00:00.000Z', - test: () => dateFromNamedCommaFormat('dec 31, 2017').toISOString(), - }); - }, -}); diff --git a/src/augments/date.ts b/src/augments/date.ts index f63293c..8af1dc3 100644 --- a/src/augments/date.ts +++ b/src/augments/date.ts @@ -1,79 +1,18 @@ +import {createDateFromUtcIsoFormat} from 'augment-vir'; import {isSanitizerMode} from '../global'; -const longMonthNames = [ - 'january', - 'february', - 'march', - 'april', - 'may', - 'june', - 'july', - 'august', - 'september', - 'october', - 'november', - 'december', -]; - -const shortMonthNames = longMonthNames.map((longMonthName) => longMonthName.slice(0, 3)); - -export class InvalidDateError extends Error { - public override readonly name = 'InvalidDateError'; -} - -export function dateFromSlashFormat(input: string, yearPrefix: number | string = '') { - const [month, day, rawYearEnding = ''] = input.split('/'); - - if (!month || !day) { - throw new Error(`Unable to extract month or day from "${input}"`); - } - - const yearEnding = - rawYearEnding.length < 4 ? `${yearPrefix}${rawYearEnding.padStart(2, '0')}` : rawYearEnding; - - const returnDate = createUtcDate( - `${yearEnding.padStart(4, '0')}-${month.padStart(2, '0')}-${day.padStart(2, '0')}`, - ); - return returnDate; -} - -export function dateFromNamedCommaFormat(input: string) { - const [monthName, dayNumber, fullYear] = input.replace(',', '').split(' '); - if (!monthName || !dayNumber || !fullYear) { - throw new InvalidDateError(`Invalid ${dateFromNamedCommaFormat.name} input: ${input}`); - } - - const longMonthIndex = longMonthNames.indexOf(monthName.toLowerCase()); - const shortMonthIndex = shortMonthNames.indexOf(monthName.toLowerCase()); - - let monthIndex = longMonthIndex === -1 ? shortMonthIndex : longMonthIndex; - - if (monthIndex === -1) { - if (isSanitizerMode()) { - monthIndex = 4; - } else { - throw new InvalidDateError(`Month name ${monthName} was not found.`); - } - } - - const returnDate = createUtcDate( - `${fullYear.padStart(4, '0')}-${String(monthIndex + 1).padStart( - 2, - '0', - )}-${dayNumber.padStart(2, '0')}`, - ); - - return returnDate; -} - -export function createUtcDate(isoFormatString: string) { - const utcDate = new Date(isoFormatString + 'T00:00:00.000Z'); - - if (isNaN(Number(utcDate))) { - throw new InvalidDateError(`Invalid utc date formed from input "${isoFormatString}"`); - } - return utcDate; -} +/** + * Creates a date object that's between the two dates given. If a valid date cannot be created with + * the given inputs, a date is created that is at least earlier than the given endDate. + * + * @param startDate Optional. The earlier (date wise) bounds for creating the new Date object. If + * this is not provided, a date is created that is as close to, but earlier than, the given endDate. + * @param endDate Required. The later bounds for creating the new Date object. + * @param monthNumber Month number for the new Date object. This is 1 indexed. So a `1` here + * corresponds to January. + * @param dayNumber Number for the month for the new Date object. This is 1 indexed; the first day + * of the mont is `1`. + */ export function dateWithinRange( startDate: Date | undefined, endDate: Date, @@ -90,18 +29,22 @@ export function dateWithinRange( const day = dayNumber < 10 ? `0${dayNumber}` : String(dayNumber); if (!startDate || startDate.getUTCFullYear() === endDate.getUTCFullYear()) { - const newDate = createUtcDate(`${endDate.getUTCFullYear()}-${month}-${day}`); + const newDate = createDateFromUtcIsoFormat(`${endDate.getUTCFullYear()}-${month}-${day}`); if (newDate <= endDate) { return newDate; } else { - return createUtcDate(`${endDate.getUTCFullYear() - 1}-${month}-${day}`); + return createDateFromUtcIsoFormat(`${endDate.getUTCFullYear() - 1}-${month}-${day}`); } } else if (startDate) { - const dateFromStartYear = createUtcDate(`${startDate.getUTCFullYear()}-${month}-${day}`); - const dateFromStartYearPlus = createUtcDate( + const dateFromStartYear = createDateFromUtcIsoFormat( + `${startDate.getUTCFullYear()}-${month}-${day}`, + ); + const dateFromStartYearPlus = createDateFromUtcIsoFormat( `${startDate.getUTCFullYear() + 1}-${month}-${day}`, ); - const dateFromEndYear = createUtcDate(`${endDate.getUTCFullYear()}-${month}-${day}`); + const dateFromEndYear = createDateFromUtcIsoFormat( + `${endDate.getUTCFullYear()}-${month}-${day}`, + ); if (dateFromStartYear <= endDate && startDate <= dateFromStartYear) { return dateFromStartYear; } else if (dateFromEndYear <= endDate && startDate <= dateFromEndYear) { diff --git a/src/augments/object.ts b/src/augments/object.ts deleted file mode 100644 index fd71a0f..0000000 --- a/src/augments/object.ts +++ /dev/null @@ -1,13 +0,0 @@ -export function getEnumTypedKeys(input: T): (keyof T)[] { - // keys are always strings - return getObjectTypedKeys(input).filter((key) => isNaN(Number(key))) as (keyof T)[]; -} - -export function getEnumTypedValues(input: T): T[keyof T][] { - const keys = getEnumTypedKeys(input); - return keys.map((key) => input[key]); -} - -export function getObjectTypedKeys(input: T): (keyof T)[] { - return Object.keys(input) as (keyof T)[]; -} diff --git a/src/augments/regexp.test.ts b/src/augments/regexp.test.ts deleted file mode 100644 index 0f70a6c..0000000 --- a/src/augments/regexp.test.ts +++ /dev/null @@ -1,39 +0,0 @@ -import {testGroup} from 'test-vir'; -import {addRegExpFlags, deDupeRegExFlags} from './regexp'; - -testGroup({ - description: deDupeRegExFlags.name, - tests: (runTest) => { - runTest({ - description: 'deDupes consecutive flags', - expect: 'ig', - test: () => deDupeRegExFlags('iIiIgGgG'), - }); - runTest({ - description: 'deDupes nonconsecutive flags', - expect: 'ig', - test: () => deDupeRegExFlags('igIgI'), - }); - }, -}); - -testGroup({ - description: addRegExpFlags.name, - tests: (runTest) => { - runTest({ - description: 'adds flags to a RegExp', - expect: 'i', - test: () => addRegExpFlags(/nothing to see here/, 'i').flags, - }); - runTest({ - description: 'does not duplicate flags', - expect: 'i', - test: () => addRegExpFlags(/nothing to see here/i, 'i').flags, - }); - runTest({ - description: 'preserves original flags', - expect: 'gi', - test: () => addRegExpFlags(/nothing to see here/g, 'i').flags, - }); - }, -}); diff --git a/src/augments/regexp.ts b/src/augments/regexp.ts deleted file mode 100644 index 1c272d5..0000000 --- a/src/augments/regexp.ts +++ /dev/null @@ -1,17 +0,0 @@ -export function deDupeRegExFlags(flags: string): string { - const deDuped = new Set(Array.from(flags.toLowerCase())); - - return Array.from(deDuped).join(''); -} - -export function addRegExpFlags(originalRegExp: RegExp, flags: string): RegExp { - return new RegExp( - originalRegExp.source, - deDupeRegExFlags([originalRegExp.flags, flags].join('')), - ); -} - -export function safeMatch(input: string, regExp: RegExp): string[] { - const match = input.match(regExp); - return match ?? []; -} diff --git a/src/augments/string.test.ts b/src/augments/string.test.ts deleted file mode 100644 index bbeb1d4..0000000 --- a/src/augments/string.test.ts +++ /dev/null @@ -1,240 +0,0 @@ -import {testGroup} from 'test-vir'; -import {allIndexesOf, escapeForRegExp, replaceStringAtIndex, splitIncludeSplit} from './string'; - -testGroup({ - description: allIndexesOf.name, - tests: (runTest) => { - runTest({ - description: 'should find all substring instances in a string', - expect: [2, 5, 11, 18, 24, 31], - test: () => { - return allIndexesOf('who would hocked your thought now?', 'o', false); - }, - }); - - runTest({ - description: 'should find all regex instances in a string', - expect: [2, 5, 11, 18, 24, 31], - test: () => { - return allIndexesOf('who would hocked your thought now?', /o/, false); - }, - }); - - runTest({ - description: 'should find all RegExp matches with a capture group', - expect: [2, 5, 11, 18, 24, 31], - test: () => { - return allIndexesOf('who would hocked your thought now?', /(o)/, false); - }, - }); - - runTest({ - description: 'should handle substring at the beginning of the string correctly', - expect: [0, 3], - test: () => { - return allIndexesOf('a fan is here', 'a', false); - }, - }); - - runTest({ - description: 'should handle the substring at the end of the string only', - expect: [10], - test: () => { - return allIndexesOf('boiled eggs', 's', false); - }, - }); - - runTest({ - description: 'should handle the substring at the end and beginning of the string', - expect: [0, 8], - test: () => { - return allIndexesOf('some eggs', 's', false); - }, - }); - - runTest({ - description: 'should handle longer words', - expect: [5, 15, 29, 41, 50], - test: () => { - return allIndexesOf( - 'when you go to you to have a you because you like you', - 'you', - true, - ); - }, - }); - - runTest({ - description: 'should match multiple in a row', - expect: [0, 3, 6, 9, 12, 15], - test: () => { - return allIndexesOf('YouYouYouYouYouYou', 'You', false); - }, - }); - - runTest({ - description: 'should not match case mismatch', - expect: [0, 20], - test: () => { - return allIndexesOf('You are not you but You', 'You', true); - }, - }); - - runTest({ - description: 'should honor case insensitive set to true', - expect: [0, 12, 20], - test: () => { - return allIndexesOf('You are not you but You', 'You', false); - }, - }); - - runTest({ - description: 'includes correct lengths for simple strings', - expect: [ - {index: 0, length: 3}, - {index: 12, length: 3}, - {index: 20, length: 3}, - ], - test: () => { - return allIndexesOf('You are not you but You', 'You', false, true); - }, - }); - - runTest({ - description: 'includes correct lengths for variable RegExp matches', - expect: [ - {index: 0, length: 10}, - {index: 19, length: 4}, - {index: 28, length: 3}, - ], - test: () => { - return allIndexesOf('YoAaAaAaAu are not yoAu but You', /Yo.*?u/i, false, true); - }, - }); - - runTest({ - description: 'includes correct lengths for more RegExp matches', - expect: [ - {index: 6, length: 8}, - {index: 18, length: 3}, - {index: 41, length: 6}, - ], - test: () => { - return allIndexesOf( - 'hello YoAaAaAu do you have some time for yoZzZu?', - /yo.*?u/i, - false, - true, - ); - }, - }); - }, -}); - -testGroup({ - description: replaceStringAtIndex.name, - tests: (runTest) => { - runTest({ - description: 'should insert a string at the desire index without edge cases', - expect: 'eat his waffles', - test: () => { - return replaceStringAtIndex('eat the waffles', 4, 'his'); - }, - }); - - runTest({ - description: 'should insert the string at the beginning', - expect: 'cut the waffles', - test: () => { - return replaceStringAtIndex('eat the waffles', 0, 'cut'); - }, - }); - - runTest({ - description: 'should replace the string at the end', - expect: 'race the racy car!', - test: () => { - const originalString = 'race the race'; - return replaceStringAtIndex(originalString, originalString.length - 1, 'y car!'); - }, - }); - - runTest({ - description: 'should replace longer text with shorter text', - expect: 'eat my waffles', - test: () => { - return replaceStringAtIndex('eat the waffles', 4, 'my', 3); - }, - }); - - runTest({ - description: 'should insert text is length is 0', - expect: 'eat the blueberry waffles', - test: () => { - return replaceStringAtIndex('eat the waffles', 8, 'blueberry ', 0); - }, - }); - - runTest({ - description: 'should work with length when start index is 0 and replacement is shorter', - expect: ' of', - test: () => { - return replaceStringAtIndex(' a b c', 0, ' of', 6); - }, - }); - - runTest({ - description: 'should work with length when start index is 0 and replacement is longer', - expect: ' super duper thing', - test: () => { - return replaceStringAtIndex(' a b c', 0, ' super duper thing', 6); - }, - }); - }, -}); - -testGroup({ - description: escapeForRegExp.name, - tests: (runTest) => { - runTest({ - expect: '\\[\\*\\.\\*\\]', - description: 'should escape regexp characters', - test: () => { - return escapeForRegExp('[*.*]'); - }, - }); - - runTest({ - expect: ['[*.*]'], - description: 'escaped text works as a RegExp', - test: () => { - return '[*.*]'.match(new RegExp(escapeForRegExp('[*.*]'))); - }, - }); - }, -}); - -testGroup({ - description: splitIncludeSplit.name, - tests: (runTest) => { - runTest({ - expect: ['hello ', 'YoAaAaAu', ' do ', 'you', ' have some time for ', 'yoZzZu', '?'], - description: 'splits by variable length RegExp matches', - test: () => { - return splitIncludeSplit( - 'hello YoAaAaAu do you have some time for yoZzZu?', - /yo.*?u/i, - false, - ); - }, - }); - - runTest({ - expect: ['hello ', 'You', ' do ', 'you', ' have some time for ', 'you', '?'], - description: 'splits by a simple string', - test: () => { - return splitIncludeSplit('hello You do you have some time for you?', 'you', false); - }, - }); - }, -}); diff --git a/src/augments/string.ts b/src/augments/string.ts deleted file mode 100644 index 7136a67..0000000 --- a/src/augments/string.ts +++ /dev/null @@ -1,142 +0,0 @@ -import {deDupeRegExFlags} from './regexp'; -export function collapseSpaces(input: string): string { - return input.trim().replace(/\s{2,}/g, ' '); -} - -export function sanitizeNumberString(input: string): string { - return input.replace(/,/g, ''); -} - -function makeCaseInsensitiveString(searchForInput: string | RegExp, caseSensitive: boolean) { - const regExpFlags: string = `g${ - !caseSensitive && typeof searchForInput === 'string' ? 'i' : '' - }`; - const searchFor: RegExp = - searchForInput instanceof RegExp - ? new RegExp( - searchForInput.source, - deDupeRegExFlags(`${searchForInput.flags}${regExpFlags}`), - ) - : new RegExp(escapeForRegExp(searchForInput), regExpFlags); - - return searchFor; -} - -export function allIndexesOf( - searchIn: string, - searchForInput: string | RegExp, - caseSensitive: boolean, - includeLength: true, -): {index: number; length: number}[]; -export function allIndexesOf( - searchIn: string, - searchForInput: string | RegExp, - caseSensitive: boolean, - includeLength?: false | undefined, -): number[]; -export function allIndexesOf( - searchIn: string, - searchForInput: string | RegExp, - /** - * CaseSensitive only applies when the input is a string. Otherwise, the RegExp's "i" flag is - * used to determine case sensitivity. - */ - caseSensitive: boolean, - includeLength = false, -): number[] | {index: number; length: number}[] { - const searchFor: RegExp = makeCaseInsensitiveString(searchForInput, caseSensitive); - - const indexes: number[] = []; - const indexesAndLengths: {index: number; length: number}[] = []; - - searchIn.replace(searchFor, (...matchResults: (string | number)[]): string => { - /** - * Grabbing the second to last entry in the array (rather than the second) takes capture - * groups into account. - */ - const matchIndex: string | number | undefined = matchResults[matchResults.length - 2]; - - if (typeof matchIndex !== 'number') { - throw new Error( - `Match index "${matchIndex}" is not a number. Searching for "${searchForInput}" in "${searchIn}".`, - ); - } - - const regExpMatch: string | number | undefined = matchResults[0]; - - if (typeof regExpMatch !== 'string') { - throw new Error(`regExpMatch should've been a string but was ${typeof regExpMatch}!`); - } - - indexesAndLengths.push({index: matchIndex, length: regExpMatch.length}); - indexes.push(matchIndex); - - const originalMatch = matchResults[0]; - - if (typeof originalMatch !== 'string') { - throw new Error( - `Original match when searching for "${searchForInput}" in "${searchIn}" at index ${matchIndex} is not a string.`, - ); - } - /** - * Don't actually change any text. What we do here doesn't matter because we're not using - * the output of the .replace method, we're just producing side effects. - */ - return originalMatch; - }); - - if (includeLength) { - return indexesAndLengths; - } else { - return indexes; - } -} - -export function replaceStringAtIndex( - originalString: string, - start: number, - newString: string, - length = newString.length, -): string { - const before = originalString.substring(0, start); - const after = originalString.substring(start + length); - - return `${before}${newString}${after}`; -} - -/** Same as String.prototype.split but includes the delimiter to split by in the output array. */ -export function splitIncludeSplit( - original: string, - splitterInput: string | RegExp, - caseSensitive: boolean, -) { - const indexLengths = allIndexesOf(original, splitterInput, caseSensitive, true); - - const splitter = makeCaseInsensitiveString(splitterInput, caseSensitive); - - const splits = original.split(splitter); - - const splitterIncluded = splits.reduce((accum: string[], current, index) => { - // this will be undefined on the last index - const splitterLength: {index: number; length: number} | undefined = indexLengths[index]; - - const includeCurrent = accum.concat(current); - - if (splitterLength) { - const splitterMatch = original.slice( - splitterLength.index, - splitterLength.index + splitterLength.length, - ); - - return includeCurrent.concat(splitterMatch); - } else { - return includeCurrent; - } - }, []); - - return splitterIncluded; -} - -export function escapeForRegExp(input: string): string { - return input.replace(/[\^$\\.*+?()[\]{}|]/g, '\\$&'); -} diff --git a/src/augments/type.ts b/src/augments/type.ts deleted file mode 100644 index 2809958..0000000 --- a/src/augments/type.ts +++ /dev/null @@ -1,21 +0,0 @@ -type Property = string | number | symbol; - -type Diff = ({[P in T]: P} & {[P in U]: never} & { - [x in string | number]: never; -})[T]; - -export type Overwrite = {[P in Diff]: T[P]} & U; - -export type IfEquals = (() => G extends T ? 1 : 2) extends < - G, ->() => G extends U ? 1 : 2 - ? Y - : N; - -export type RequiredBy = Omit & Required>; -export type RequiredAndDefinedBy = Omit & - RequiredAndDefined>; - -export type RequiredAndDefined = { - [GenericKey in keyof InputObjectGeneric]-?: NonNullable; -}; diff --git a/src/augments/type.type.test.ts b/src/augments/type.type.test.ts deleted file mode 100644 index 529c44a..0000000 --- a/src/augments/type.type.test.ts +++ /dev/null @@ -1,9 +0,0 @@ -import {RequiredAndDefined} from './type'; -type Options = { - a?: string | undefined; - b?: string | undefined; - c?: string | undefined; -}; - -// @ts-expect-error -const thingie: RequiredAndDefined = {a: undefined, b: undefined, c: undefined}; diff --git a/src/package-contents.test.ts b/src/package-contents.test.ts index d0646e3..3d8b46d 100644 --- a/src/package-contents.test.ts +++ b/src/package-contents.test.ts @@ -1,5 +1,5 @@ +import {safeMatch} from 'augment-vir'; import {testGroup} from 'test-vir'; -import {safeMatch} from './augments/regexp'; import {runBashCommand} from './bash-scripting'; const packCommand = `npm pack --dry-run`; diff --git a/src/parser/all-parsers.ts b/src/parser/all-parsers.ts index 997a8e5..1747d73 100644 --- a/src/parser/all-parsers.ts +++ b/src/parser/all-parsers.ts @@ -1,4 +1,4 @@ -import {getEnumTypedValues} from '../augments/object'; +import {getEnumTypedValues} from 'augment-vir'; import { ChaseCreditCardParsingOptions, chasePrimeVisaCreditCardParser, diff --git a/src/parser/implemented-parsers/chase-prime-visa-credit-card-parser.ts b/src/parser/implemented-parsers/chase-prime-visa-credit-card-parser.ts index 88e5e79..8a5a5e5 100644 --- a/src/parser/implemented-parsers/chase-prime-visa-credit-card-parser.ts +++ b/src/parser/implemented-parsers/chase-prime-visa-credit-card-parser.ts @@ -1,6 +1,5 @@ -import {dateFromSlashFormat, dateWithinRange} from '../../augments/date'; -import {safeMatch} from '../../augments/regexp'; -import {sanitizeNumberString} from '../../augments/string'; +import {createDateFromSlashFormat, safeMatch, stripCommasFromNumberString} from 'augment-vir'; +import {dateWithinRange} from '../../augments/date'; import {ParsedOutput, ParsedTransaction} from '../parsed-output'; import {CombineWithBaseParserOptions} from '../parser-options'; import {createStatementParser} from '../statement-parser'; @@ -63,7 +62,7 @@ function processTransactionLine( if (date && description && amount) { const [month, day] = date.split('/'); return { - amount: Number(sanitizeNumberString(amount)), + amount: Number(stripCommasFromNumberString(amount)), description, date: dateWithinRange(startDate, endDate, Number(month), Number(day)), originalText: [line], @@ -84,8 +83,8 @@ function performStateAction( const [, accountNumber] = safeMatch(line, accountNumberRegExp); if (startDateString && endDateString) { - const startDate = dateFromSlashFormat(startDateString, parserOptions.yearPrefix); - const endDate = dateFromSlashFormat(endDateString, parserOptions.yearPrefix); + const startDate = createDateFromSlashFormat(startDateString, parserOptions.yearPrefix); + const endDate = createDateFromSlashFormat(endDateString, parserOptions.yearPrefix); // Chase statements sometimes include transactions a few days outside of the statement range. startDate.setDate(startDate.getDate() - 3); endDate.setDate(endDate.getDate() + 3); diff --git a/src/parser/implemented-parsers/citi-costco-visa-credit-card-parser.ts b/src/parser/implemented-parsers/citi-costco-visa-credit-card-parser.ts index 4caa427..500cf83 100644 --- a/src/parser/implemented-parsers/citi-costco-visa-credit-card-parser.ts +++ b/src/parser/implemented-parsers/citi-costco-visa-credit-card-parser.ts @@ -1,10 +1,14 @@ +import { + collapseSpaces, + createDateFromSlashFormat, + getEnumTypedValues, + Overwrite, + safeMatch, + stripCommasFromNumberString, +} from 'augment-vir'; import {parsePageItems} from 'pdf-text-reader'; import {TextItem} from 'pdfjs-dist/types/src/display/api'; -import {dateFromSlashFormat, dateWithinRange} from '../../augments/date'; -import {getEnumTypedValues} from '../../augments/object'; -import {safeMatch} from '../../augments/regexp'; -import {collapseSpaces, sanitizeNumberString} from '../../augments/string'; -import {Overwrite} from '../../augments/type'; +import {dateWithinRange} from '../../augments/date'; import {getPdfDocument} from '../../pdf/read-pdf'; import {ParsedOutput, ParsedTransaction} from '../parsed-output'; import {CombineWithBaseParserOptions} from '../parser-options'; @@ -108,7 +112,7 @@ function parseAmount(input: string, negate: boolean): number { const [, amountMatch] = safeMatch(input, amountRegExp); if (amountMatch) { - const amount = Number(sanitizeNumberString(amountMatch)); + const amount = Number(stripCommasFromNumberString(amountMatch)); let multiplier = negate ? -1 : 1; if (input[0] === '-') { @@ -174,8 +178,8 @@ function performStateAction( const [, startDateString, endDateString] = safeMatch(line, billingPeriodRegExp); const [, accountSuffixString] = safeMatch(line, accountNumberRegExp); if (startDateString && endDateString) { - output.startDate = dateFromSlashFormat(startDateString, parserOptions.yearPrefix); - output.endDate = dateFromSlashFormat(endDateString, parserOptions.yearPrefix); + output.startDate = createDateFromSlashFormat(startDateString, parserOptions.yearPrefix); + output.endDate = createDateFromSlashFormat(endDateString, parserOptions.yearPrefix); } else if (accountSuffixString) { output.accountSuffix = accountSuffixString; } diff --git a/src/parser/implemented-parsers/example-parser.ts b/src/parser/implemented-parsers/example-parser.ts index 41f1acc..8db075d 100644 --- a/src/parser/implemented-parsers/example-parser.ts +++ b/src/parser/implemented-parsers/example-parser.ts @@ -1,6 +1,4 @@ -import {createUtcDate} from '../../augments/date'; -import {safeMatch} from '../../augments/regexp'; -import {sanitizeNumberString} from '../../augments/string'; +import {createDateFromUtcIsoFormat, safeMatch, stripCommasFromNumberString} from 'augment-vir'; import {ParsedOutput, ParsedTransaction} from '../parsed-output'; import {createStatementParser} from '../statement-parser'; @@ -25,9 +23,9 @@ function readPayment(line: string): ParsedTransaction | undefined { if (dateString && descriptionString && amountString) { return { - amount: Number(sanitizeNumberString(amountString)), + amount: Number(stripCommasFromNumberString(amountString)), description: descriptionString, - date: createUtcDate(dateString), + date: createDateFromUtcIsoFormat(dateString), originalText: [line], }; } else { diff --git a/src/parser/implemented-parsers/paypal-parser.ts b/src/parser/implemented-parsers/paypal-parser.ts index 4e5a98d..b2322cb 100644 --- a/src/parser/implemented-parsers/paypal-parser.ts +++ b/src/parser/implemented-parsers/paypal-parser.ts @@ -1,7 +1,12 @@ -import {dateFromNamedCommaFormat, dateFromSlashFormat} from '../../augments/date'; -import {getEnumTypedValues} from '../../augments/object'; -import {safeMatch} from '../../augments/regexp'; -import {collapseSpaces, sanitizeNumberString} from '../../augments/string'; +import { + collapseSpaces, + createDateFromNamedCommaFormat, + createDateFromSlashFormat, + getEnumTypedValues, + safeMatch, + stripCommasFromNumberString, +} from 'augment-vir'; +import {isSanitizerMode} from '../../global'; import {ParsedOutput, ParsedTransaction} from '../parsed-output'; import {createStatementParser} from '../statement-parser'; @@ -52,8 +57,8 @@ function performStateAction(currentState: State, line: string, output: PaypalOut if (currentState === State.HeaderData && !output.startDate) { const [, startDate, endDate, accountId] = safeMatch(line, headerDataLineRegExp); if (startDate && endDate && accountId) { - output.startDate = dateFromNamedCommaFormat(startDate); - output.endDate = dateFromNamedCommaFormat(endDate); + output.startDate = createDateFromNamedCommaFormat(startDate, isSanitizerMode()); + output.endDate = createDateFromNamedCommaFormat(endDate, isSanitizerMode()); output.accountSuffix = accountId; } } else if (currentState === State.Activity) { @@ -62,13 +67,13 @@ function performStateAction(currentState: State, line: string, output: PaypalOut transactionStartRegExp, ); if (date && description && amountString && fees && total) { - const amount = Number(sanitizeNumberString(amountString)); + const amount = Number(stripCommasFromNumberString(amountString)); const newTransaction: PaypalTransaction = { - date: dateFromSlashFormat(date), + date: createDateFromSlashFormat(date), description: collapseSpaces(description), // this assumption that we can always use absolute value here may be wrong - amount: Math.abs(Number(sanitizeNumberString(total))), - fees: Math.abs(Number(sanitizeNumberString(fees))), + amount: Math.abs(Number(stripCommasFromNumberString(total))), + fees: Math.abs(Number(stripCommasFromNumberString(fees))), baseAmount: Math.abs(amount), originalText: [line], }; @@ -122,7 +127,7 @@ function nextState(currentState: State, line: string): State { case State.Activity: const amountMatch = safeMatch(line, transactionStartRegExp)[5]; if (amountMatch) { - if (Number(sanitizeNumberString(amountMatch)) < 0) { + if (Number(stripCommasFromNumberString(amountMatch)) < 0) { return State.ExpenseInside; } else { return State.IncomeInside; diff --git a/src/parser/implemented-parsers/usaa-bank-account-parser.ts b/src/parser/implemented-parsers/usaa-bank-account-parser.ts index b99b66f..218f0f9 100644 --- a/src/parser/implemented-parsers/usaa-bank-account-parser.ts +++ b/src/parser/implemented-parsers/usaa-bank-account-parser.ts @@ -1,7 +1,11 @@ -import {dateFromSlashFormat, dateWithinRange} from '../../augments/date'; -import {getEnumTypedValues} from '../../augments/object'; -import {safeMatch} from '../../augments/regexp'; -import {collapseSpaces, sanitizeNumberString} from '../../augments/string'; +import { + collapseSpaces, + createDateFromSlashFormat, + getEnumTypedValues, + safeMatch, + stripCommasFromNumberString, +} from 'augment-vir'; +import {dateWithinRange} from '../../augments/date'; import {ParsedOutput, ParsedTransaction} from '../parsed-output'; import {CombineWithBaseParserOptions} from '../parser-options'; import {createStatementParser} from '../statement-parser'; @@ -66,8 +70,8 @@ function performStateAction( if (!output.accountSuffix.match(/\d+/)) { throw new Error(`Invalid account suffix: "${output.accountSuffix}"`); } - output.startDate = dateFromSlashFormat(startDateString, parserOptions.yearPrefix); - output.endDate = dateFromSlashFormat(endDateString, parserOptions.yearPrefix); + output.startDate = createDateFromSlashFormat(startDateString, parserOptions.yearPrefix); + output.endDate = createDateFromSlashFormat(endDateString, parserOptions.yearPrefix); } else { throw new Error( `Start and end date were not found in line for "${State.StatementPeriod}" state: "${line}"`, @@ -103,7 +107,7 @@ function performStateAction( ); array.push({ date: date, - amount: Number(sanitizeNumberString(amountString)), + amount: Number(stripCommasFromNumberString(amountString)), description: collapseSpaces(descriptionString).trim(), from: undefined, originalText: [line], diff --git a/src/parser/implemented-parsers/usaa-visa-credit-card-parser.ts b/src/parser/implemented-parsers/usaa-visa-credit-card-parser.ts index 88f2586..f5e0a26 100644 --- a/src/parser/implemented-parsers/usaa-visa-credit-card-parser.ts +++ b/src/parser/implemented-parsers/usaa-visa-credit-card-parser.ts @@ -1,6 +1,5 @@ -import {dateFromSlashFormat, dateWithinRange} from '../../augments/date'; -import {safeMatch} from '../../augments/regexp'; -import {sanitizeNumberString} from '../../augments/string'; +import {createDateFromSlashFormat, safeMatch, stripCommasFromNumberString} from 'augment-vir'; +import {dateWithinRange} from '../../augments/date'; import {ParsedOutput, ParsedTransaction} from '../parsed-output'; import {CombineWithBaseParserOptions} from '../parser-options'; import {createStatementParser} from '../statement-parser'; @@ -84,7 +83,7 @@ function processTransactionLine( Number(transactionDay), ), postDate: dateWithinRange(undefined, endDate, Number(postMonth), Number(postDay)), - amount: Number(sanitizeNumberString(amount)), + amount: Number(stripCommasFromNumberString(amount)), description, referenceNumber, originalText: [line], @@ -128,7 +127,7 @@ function performStateAction( const [, closingDateString] = safeMatch(line, closingDateRegExp); const [, accountNumberString] = safeMatch(line, extractAccountNumberRegExp); if (closingDateString) { - output.endDate = dateFromSlashFormat(closingDateString, parserOptions.yearPrefix); + output.endDate = createDateFromSlashFormat(closingDateString, parserOptions.yearPrefix); } else if (accountNumberString && !output.accountSuffix) { output.accountSuffix = accountNumberString; } diff --git a/src/parser/parser-state-machine.ts b/src/parser/parser-state-machine.ts index a1811a5..941839a 100644 --- a/src/parser/parser-state-machine.ts +++ b/src/parser/parser-state-machine.ts @@ -1,10 +1,10 @@ +import {IfEquals} from 'augment-vir'; import { createStateMachine, handleErrorFunction, nextStateFunction, performStateActionFunction, } from 'fsm-vir'; -import {IfEquals} from '../augments/type'; import {InitOutput, ParsedOutput} from './parsed-output'; import {SharedParserFunctionInputs} from './parser-function'; import { diff --git a/src/parser/statement-parser.ts b/src/parser/statement-parser.ts index 604f1c4..d4734b0 100644 --- a/src/parser/statement-parser.ts +++ b/src/parser/statement-parser.ts @@ -1,4 +1,4 @@ -import {flatten2dArray} from '../augments/array'; +import {flatten2dArray} from 'augment-vir'; import {readPdf} from '../pdf/read-pdf'; import {ParsedOutput} from './parsed-output'; import { diff --git a/src/pdf/read-pdf.test.ts b/src/pdf/read-pdf.test.ts index d7bd30b..71f6d8c 100644 --- a/src/pdf/read-pdf.test.ts +++ b/src/pdf/read-pdf.test.ts @@ -1,6 +1,6 @@ +import {collapseSpaces} from 'augment-vir'; import {join} from 'path'; import {testGroup} from 'test-vir'; -import {collapseSpaces} from '../augments/string'; import {sampleFilesDir} from '../repo-paths'; import {readPdf} from './read-pdf'; diff --git a/src/readme-version.test.ts b/src/readme-version.test.ts deleted file mode 100644 index 1bc8380..0000000 --- a/src/readme-version.test.ts +++ /dev/null @@ -1,63 +0,0 @@ -import {readFile} from 'fs-extra'; -import {join} from 'path'; -import {testGroup} from 'test-vir'; -import {getPackageVersion} from './package-version'; -import {repoRootDir} from './repo-paths'; - -testGroup({ - description: `readme tests`, - tests: (runTest) => { - async function readVersionLineOfReadme() { - const readmePath = join(repoRootDir, 'README.md'); - - const allReadmeText: string[] = (await readFile(readmePath)).toString().split('\n'); - - if (!allReadmeText.length) { - throw new Error(`${readmePath} file is empty.`); - } - - const versionLine = allReadmeText[allReadmeText.length - 2]; - - if (!versionLine) { - throw new Error(`version line of README is empty.`); - } - - return versionLine; - } - - runTest({ - expect: true, - description: 'check that package version can be read', - test: () => { - return !!getPackageVersion().length; - }, - }); - - runTest({ - description: 'verify that version line of README is read', - expect: true, - test: async () => { - const firstLine = await readVersionLineOfReadme(); - - return firstLine.match(/v\d+\.\d+\.\d+/) !== null; - }, - }); - - runTest({ - /** - * If this fails it indicates that we need to update the README.md file. This will - * likely require updating the documentation itself (to match the new version's - * changes), not just incrementing the number. - */ - description: 'check that README version number is up to date', - expect: getPackageVersion(), - test: async () => { - const firstLine = await readVersionLineOfReadme(); - - const readmeVersion = firstLine.trim().replace(/^.*v/i, ''); - - return readmeVersion; - }, - }); - }, -}); diff --git a/src/sanitizer/sanitize-for-test-file-cli.ts b/src/sanitizer/sanitize-for-test-file-cli.ts index 8d0e547..0b30770 100644 --- a/src/sanitizer/sanitize-for-test-file-cli.ts +++ b/src/sanitizer/sanitize-for-test-file-cli.ts @@ -1,5 +1,5 @@ +import {getEnumTypedValues} from 'augment-vir'; import {extname, relative} from 'path'; -import {getEnumTypedValues} from '../augments/object'; import {isParserType, ParserType} from '../parser/all-parsers'; import {StatementPdf} from '../parser/parse-api'; import {checkThatPdfExists} from '../pdf/read-pdf'; diff --git a/src/sanitizer/sanitized-test.test.ts b/src/sanitizer/sanitized-test.test.ts index 04a6067..39c2a4f 100644 --- a/src/sanitizer/sanitized-test.test.ts +++ b/src/sanitizer/sanitized-test.test.ts @@ -1,7 +1,7 @@ +import {getEnumTypedValues} from 'augment-vir'; import {unlinkSync} from 'fs-extra'; import {join} from 'path'; import {testGroup} from 'test-vir'; -import {getEnumTypedValues} from '../augments/object'; import {ParserType} from '../parser/all-parsers'; import {sampleFilesDir} from '../repo-paths'; import {writeSanitizedTestFile} from './sanitized-test'; diff --git a/src/sanitizer/sanitized-test.ts b/src/sanitizer/sanitized-test.ts index f7243e8..021bea8 100644 --- a/src/sanitizer/sanitized-test.ts +++ b/src/sanitizer/sanitized-test.ts @@ -1,8 +1,8 @@ +import {Overwrite, RequiredAndNotNullBy} from 'augment-vir'; import {ensureDir, existsSync, readFileSync, writeFile} from 'fs-extra'; import {dirname, join, relative} from 'path'; import {format, resolveConfig} from 'prettier'; import {TestInputObject} from 'test-vir'; -import {Overwrite, RequiredAndDefinedBy} from '../augments/type'; import {setSanitizerMode, unsetSanitizerMode} from '../global'; import {getPackageVersion} from '../package-version'; import {AllParserOptions, parsers, ParserType} from '../parser/all-parsers'; @@ -31,7 +31,7 @@ export type SanitizedTestFile = { type SanitizingStatementPdf = Overwrite< StatementPdf, - {parserInput: RequiredAndDefinedBy} + {parserInput: RequiredAndNotNullBy} >; async function validateSanitizedParsing( diff --git a/src/sanitizer/sanitizer.test.ts b/src/sanitizer/sanitizer.test.ts index 1bffb90..e75d5fe 100644 --- a/src/sanitizer/sanitizer.test.ts +++ b/src/sanitizer/sanitizer.test.ts @@ -1,5 +1,5 @@ +import {trimArrayStrings} from 'augment-vir'; import {testGroup, TestInputObject} from 'test-vir'; -import {trimArray} from '../augments/array'; import {ParserKeyword} from '../parser/parser-options'; import {collapseAroundKeyword, sanitizeStatementText} from './sanitizer'; @@ -57,7 +57,7 @@ testGroup({ }); } { - const unSanitized = trimArray( + const unSanitized = trimArrayStrings( ` secret account number: 123-456-789 $30 super secret purchase don't tell anyone about it @@ -106,7 +106,7 @@ testGroup({ sanitizerTest( unSanitized, - trimArray( + trimArrayStrings( ` a account number 1-2-3 $4 k @@ -119,7 +119,7 @@ testGroup({ sanitizerTest( unSanitized, - trimArray( + trimArrayStrings( ` a account number 1-2-3 $4 super secret purchase k diff --git a/src/sanitizer/sanitizer.ts b/src/sanitizer/sanitizer.ts index 016f3e2..30089bf 100644 --- a/src/sanitizer/sanitizer.ts +++ b/src/sanitizer/sanitizer.ts @@ -1,6 +1,10 @@ +import { + addRegExpFlags, + getAllIndexesOf, + replaceStringAtIndex, + splitIncludeSplit, +} from 'augment-vir'; import {writeFile} from 'fs-extra'; -import {addRegExpFlags} from '../augments/regexp'; -import {allIndexesOf, replaceStringAtIndex, splitIncludeSplit} from '../augments/string'; import {parsers, ParserType} from '../parser/all-parsers'; import {ParserKeyword} from '../parser/parser-options'; import {temp_sanitizerRawTestFilePath, temp_sanitizerSanitizedTextFilePath} from '../repo-paths'; @@ -132,7 +136,7 @@ export function sanitizeStatementText( return text.map((line) => { const keywordIndexes: number[][] = phrasesToPreserve.map((keyword) => { - return allIndexesOf(line, keyword, false); + return getAllIndexesOf(line, keyword, false); }); const containsKeywords = keywordIndexes.some((phraseIndexes) => phraseIndexes.length > 0);