From fdcdf1ddf38fdbcf32f52660e0621d9737348688 Mon Sep 17 00:00:00 2001 From: TheoryOfNekomata Date: Sat, 11 Mar 2023 14:20:36 +0800 Subject: [PATCH] Refactor code Make error messages more user-friendly. Also remove magic constants within functions. --- README.md | 2 +- cypress/integration/misc.test.ts | 7 +- cypress/integration/text.test.ts | 2 + package.json | 2 +- src/index.ts | 326 +++++++++++++++++++++++-------- 5 files changed, 249 insertions(+), 90 deletions(-) diff --git a/README.md b/README.md index e691b21..9d220f1 100644 --- a/README.md +++ b/README.md @@ -121,4 +121,4 @@ form.addEventListener('submit', async e => { ## Tests -The library has been tested on the static DOM using JSDOM and Jest, and the real dynamic DOM using Cypress. +The library has been tested on the static DOM using JSDOM, and the real dynamic DOM using Cypress. diff --git a/cypress/integration/misc.test.ts b/cypress/integration/misc.test.ts index cecb2ba..ffe243d 100644 --- a/cypress/integration/misc.test.ts +++ b/cypress/integration/misc.test.ts @@ -251,6 +251,7 @@ describe('misc', () => { .toString(); const after = utils.makeSearchParams(search) .toString(); + expect(before) .toEqual(after); }, @@ -280,5 +281,7 @@ Another line`, expectedStaticValue: 'first_name=John&middle_name=Marcelo&last_name=Dela+Cruz&gender=m&birthday=1989-06-04&civil_status=married&new_registration=on&last_appointment_datetime=2001-09-11T06%3A09&new_appointment_week=2001-W51&start_month=2002-03&nationality=filipino&gross=131072&dependent=Jun¬es=Test+content%0D%0A%0D%0ANew+line%0D%0A%0D%0AAnother+line&qos=9.5&submit=Hi', }); }); - }) -}) + }); + + // TODO implement tests for multiple values +}); diff --git a/cypress/integration/text.test.ts b/cypress/integration/text.test.ts index 166ea93..84e5df4 100644 --- a/cypress/integration/text.test.ts +++ b/cypress/integration/text.test.ts @@ -198,4 +198,6 @@ describe('text', () => { }); }); }); + + // TODO implement textarea tests }) diff --git a/package.json b/package.json index 17fecab..6eb20f5 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@theoryofnekomata/formxtra", - "version": "1.0.0", + "version": "1.0.1", "files": [ "dist", "src" diff --git a/src/index.ts b/src/index.ts index ec96f46..4cb9c1d 100644 --- a/src/index.ts +++ b/src/index.ts @@ -16,23 +16,53 @@ export enum LineEnding { CRLF = '\r\n', } +/** + * Type for a placeholder object value. + */ type PlaceholderObject = Record /** - * Checks if an element can hold a field value. + * Tag name for the `` element. + */ +const TAG_NAME_INPUT = 'INPUT' as const; + +/** + * Tag name for the `