Skip to content

Commit

Permalink
Remove regex
Browse files Browse the repository at this point in the history
  • Loading branch information
Sparticuz committed Aug 6, 2021
1 parent 5ee9d85 commit 61d133d
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 12 deletions.
8 changes: 2 additions & 6 deletions src/generate-fdf-template.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,10 @@ import generateFieldJson from "./generate-field-json";
/**
* Generates an object with key/value pairs
* @param sourceFile
* @param nameRegex
* @returns A json object
*/
export default async (
sourceFile: string,
nameRegex: never
): Promise<Record<string, string>> => {
const formFields = await generateFieldJson(sourceFile, nameRegex);
export default async (sourceFile: string): Promise<Record<string, string>> => {
const formFields = await generateFieldJson(sourceFile);
const json: Record<string, string> = {};
for (const row of formFields) {
json[row.title] = row.fieldValue as string;
Expand Down
5 changes: 0 additions & 5 deletions src/generate-field-json.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,14 @@ export interface FormField {
/**
* Extracts the Form Fields from a PDF Form
* @param sourceFile
* @param nameRegex
* @returns A FormField object
*/
export default (sourceFile: string, nameRegex: never): Promise<FormField[]> => {
let regName = /FieldName: ([^\n]*)/;
const regType = /FieldType: ([\t .A-Za-z]+)/;
const regFlags = /FieldFlags: ([\d\t .]+)/;
const regMaxLength = /FieldMaxLength: ([\d\t .]+)/;
const fieldArray: FormField[] = [];

if (nameRegex !== null && typeof nameRegex === "object")
regName = nameRegex;

return new Promise((resolve, reject) => {
const childProcess = spawn("pdftk", [
sourceFile,
Expand Down
1 change: 0 additions & 1 deletion test/generate-field-json.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,4 +125,3 @@ test("should generate a large form field JSON with no errors", async (t) => {
t.deepEqual(fdf, formFields);
});

test.todo("should make sure nameRegex works correctly");

0 comments on commit 61d133d

Please sign in to comment.