form-payload 0.0.8 → 1.0.3
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/LICENSE +21 -0
- package/package.json +68 -56
- package/readme.md +62 -96
- package/src/index.d.ts +5 -0
- package/src/index.d.ts.map +1 -0
- package/src/index.js +4 -0
- package/src/libs/constants/banned-control-types.constant.d.ts +2 -0
- package/src/libs/constants/banned-control-types.constant.d.ts.map +1 -0
- package/src/libs/constants/banned-control-types.constant.js +10 -0
- package/src/libs/constants/constants.d.ts +2 -0
- package/src/libs/constants/constants.d.ts.map +1 -0
- package/src/libs/constants/constants.js +1 -0
- package/src/libs/enums/control-type.enum.d.ts +30 -0
- package/src/libs/enums/control-type.enum.d.ts.map +1 -0
- package/src/libs/enums/control-type.enum.js +40 -0
- package/src/libs/enums/enums.d.ts +2 -0
- package/src/libs/enums/enums.d.ts.map +1 -0
- package/src/libs/enums/enums.js +1 -0
- package/src/libs/exceptions/exceptions.d.ts +2 -0
- package/src/libs/exceptions/exceptions.d.ts.map +1 -0
- package/src/libs/exceptions/exceptions.js +1 -0
- package/src/libs/exceptions/form-payload-error.exception.d.ts +11 -0
- package/src/libs/exceptions/form-payload-error.exception.d.ts.map +1 -0
- package/src/libs/exceptions/form-payload-error.exception.js +14 -0
- package/src/libs/maps/element-name-to-element-instance.map.d.ts +11 -0
- package/src/libs/maps/element-name-to-element-instance.map.d.ts.map +1 -0
- package/src/libs/maps/element-name-to-element-instance.map.js +6 -0
- package/src/libs/maps/maps.d.ts +2 -0
- package/src/libs/maps/maps.d.ts.map +1 -0
- package/src/libs/maps/maps.js +1 -0
- package/src/libs/types/html-form-control-element.type.d.ts +4 -0
- package/src/libs/types/html-form-control-element.type.d.ts.map +1 -0
- package/src/libs/types/html-form-control-element.type.js +9 -0
- package/src/libs/types/html-form-non-operational-control-element.type.d.ts +2 -0
- package/src/libs/types/html-form-non-operational-control-element.type.d.ts.map +1 -0
- package/src/libs/types/html-form-non-operational-control-element.type.js +3 -0
- package/src/libs/types/html-form-operational-control-element.type.d.ts +2 -0
- package/src/libs/types/html-form-operational-control-element.type.d.ts.map +1 -0
- package/src/libs/types/html-form-operational-control-element.type.js +9 -0
- package/src/libs/types/types.d.ts +4 -0
- package/src/libs/types/types.d.ts.map +1 -0
- package/src/libs/types/types.js +5 -0
- package/src/packages/get-form-control-payload/get-form-control-payload.d.ts +17 -0
- package/src/packages/get-form-control-payload/get-form-control-payload.d.ts.map +1 -0
- package/src/packages/get-form-control-payload/get-form-control-payload.js +120 -0
- package/src/packages/get-form-control-payload/helpers/check-is-refer-to-another-node/check-is-refer-to-another-node.helper.d.ts +10 -0
- package/src/packages/get-form-control-payload/helpers/check-is-refer-to-another-node/check-is-refer-to-another-node.helper.d.ts.map +1 -0
- package/src/packages/get-form-control-payload/helpers/check-is-refer-to-another-node/check-is-refer-to-another-node.helper.js +24 -0
- package/src/packages/get-form-control-payload/helpers/get-allowed-elements/get-allowed-elements.helper.d.ts +8 -0
- package/src/packages/get-form-control-payload/helpers/get-allowed-elements/get-allowed-elements.helper.d.ts.map +1 -0
- package/src/packages/get-form-control-payload/helpers/get-allowed-elements/get-allowed-elements.helper.js +61 -0
- package/src/packages/get-form-control-payload/helpers/get-checkbox-value/get-checkbox-value.helper.d.ts +6 -0
- package/src/packages/get-form-control-payload/helpers/get-checkbox-value/get-checkbox-value.helper.d.ts.map +1 -0
- package/src/packages/get-form-control-payload/helpers/get-checkbox-value/get-checkbox-value.helper.js +9 -0
- package/src/packages/get-form-control-payload/helpers/get-control-value/get-control-value.helper.d.ts +9 -0
- package/src/packages/get-form-control-payload/helpers/get-control-value/get-control-value.helper.d.ts.map +1 -0
- package/src/packages/get-form-control-payload/helpers/get-control-value/get-control-value.helper.js +12 -0
- package/src/packages/get-form-control-payload/helpers/get-input-date-value/get-input-date-value.helper.d.ts +6 -0
- package/src/packages/get-form-control-payload/helpers/get-input-date-value/get-input-date-value.helper.d.ts.map +1 -0
- package/src/packages/get-form-control-payload/helpers/get-input-date-value/get-input-date-value.helper.js +9 -0
- package/src/packages/get-form-control-payload/helpers/get-input-file-value/get-input-file-value.helper.d.ts +6 -0
- package/src/packages/get-form-control-payload/helpers/get-input-file-value/get-input-file-value.helper.d.ts.map +1 -0
- package/src/packages/get-form-control-payload/helpers/get-input-file-value/get-input-file-value.helper.js +16 -0
- package/src/packages/get-form-control-payload/helpers/get-input-numeric-value/get-input-numeric-value.helper.d.ts +6 -0
- package/src/packages/get-form-control-payload/helpers/get-input-numeric-value/get-input-numeric-value.helper.d.ts.map +1 -0
- package/src/packages/get-form-control-payload/helpers/get-input-numeric-value/get-input-numeric-value.helper.js +9 -0
- package/src/packages/get-form-control-payload/helpers/get-multi-select-values/get-multi-select-values.helper.d.ts +6 -0
- package/src/packages/get-form-control-payload/helpers/get-multi-select-values/get-multi-select-values.helper.d.ts.map +1 -0
- package/src/packages/get-form-control-payload/helpers/get-multi-select-values/get-multi-select-values.helper.js +9 -0
- package/src/packages/get-form-control-payload/helpers/helpers.d.ts +9 -0
- package/src/packages/get-form-control-payload/helpers/helpers.d.ts.map +1 -0
- package/src/packages/get-form-control-payload/helpers/helpers.js +8 -0
- package/src/packages/get-form-payload/get-form-payload.d.ts +9 -0
- package/src/packages/get-form-payload/get-form-payload.d.ts.map +1 -0
- package/src/packages/get-form-payload/get-form-payload.js +18 -0
- package/common/constants/banned-control-types.constant.d.ts +0 -2
- package/common/constants/banned-control-types.constant.js +0 -11
- package/common/constants/index.d.ts +0 -1
- package/common/constants/index.js +0 -13
- package/common/enums/dom/element-name.enum.d.ts +0 -9
- package/common/enums/dom/element-name.enum.js +0 -12
- package/common/enums/dom/index.d.ts +0 -1
- package/common/enums/dom/index.js +0 -13
- package/common/enums/exception/custom-exception-name.enum.d.ts +0 -4
- package/common/enums/exception/custom-exception-name.enum.js +0 -7
- package/common/enums/exception/error-message.enum.d.ts +0 -5
- package/common/enums/exception/error-message.enum.js +0 -8
- package/common/enums/exception/index.d.ts +0 -2
- package/common/enums/exception/index.js +0 -14
- package/common/enums/form/control-type.enum.d.ts +0 -30
- package/common/enums/form/control-type.enum.js +0 -33
- package/common/enums/form/index.d.ts +0 -1
- package/common/enums/form/index.js +0 -13
- package/common/enums/index.d.ts +0 -3
- package/common/enums/index.js +0 -15
- package/common/types/dom/child-element.type.d.ts +0 -2
- package/common/types/dom/child-element.type.js +0 -2
- package/common/types/dom/control-collection.type.d.ts +0 -2
- package/common/types/dom/control-collection.type.js +0 -2
- package/common/types/dom/control-element.type.d.ts +0 -2
- package/common/types/dom/control-element.type.js +0 -2
- package/common/types/dom/index.d.ts +0 -3
- package/common/types/dom/index.js +0 -15
- package/common/types/index.d.ts +0 -2
- package/common/types/index.js +0 -14
- package/common/types/object/custom-object.type.d.ts +0 -2
- package/common/types/object/custom-object.type.js +0 -2
- package/common/types/object/index.d.ts +0 -1
- package/common/types/object/index.js +0 -13
- package/exceptions/form-payload-error/form-payload-error.exception.d.ts +0 -7
- package/exceptions/form-payload-error/form-payload-error.exception.js +0 -12
- package/exceptions/index.d.ts +0 -1
- package/exceptions/index.js +0 -13
- package/helpers/get-control-value/get-control-value.helper.d.ts +0 -4
- package/helpers/get-control-value/get-control-value.helper.js +0 -70
- package/helpers/get-control-value/helpers/check-is-refer-to-another-node/check-is-refer-to-another-node.helper.d.ts +0 -3
- package/helpers/get-control-value/helpers/check-is-refer-to-another-node/check-is-refer-to-another-node.helper.js +0 -10
- package/helpers/get-control-value/helpers/get-allowed-elements/get-allowed-elements.helper.d.ts +0 -3
- package/helpers/get-control-value/helpers/get-allowed-elements/get-allowed-elements.helper.js +0 -23
- package/helpers/get-control-value/helpers/get-input-file-value/get-input-file-value.helper.d.ts +0 -2
- package/helpers/get-control-value/helpers/get-input-file-value/get-input-file-value.helper.js +0 -11
- package/helpers/get-control-value/helpers/get-multi-select-values/get-multi-select-values.helper.d.ts +0 -2
- package/helpers/get-control-value/helpers/get-multi-select-values/get-multi-select-values.helper.js +0 -7
- package/helpers/get-control-value/helpers/index.d.ts +0 -4
- package/helpers/get-control-value/helpers/index.js +0 -16
- package/helpers/index.d.ts +0 -1
- package/helpers/index.js +0 -13
- package/index.d.ts +0 -7
- package/index.js +0 -15
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2021 Vladyslav Zubko
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/package.json
CHANGED
|
@@ -1,58 +1,70 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
2
|
+
"name": "form-payload",
|
|
3
|
+
"version": "1.0.3",
|
|
4
|
+
"description": "Gets form-payload via form.elements",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"form",
|
|
7
|
+
"form-data",
|
|
8
|
+
"form-values",
|
|
9
|
+
"form-payload",
|
|
10
|
+
"input-data",
|
|
11
|
+
"input-value",
|
|
12
|
+
"input-payload"
|
|
13
|
+
],
|
|
14
|
+
"author": "Vladyslav Zubko <hello@whatislove.dev> (https://whatislove.dev/)",
|
|
15
|
+
"homepage": "https://github.com/what1s1ove/form-payload",
|
|
16
|
+
"repository": {
|
|
17
|
+
"type": "git",
|
|
18
|
+
"url": "git+https://github.com/what1s1ove/form-payload.git"
|
|
19
|
+
},
|
|
20
|
+
"license": "MIT",
|
|
21
|
+
"type": "module",
|
|
22
|
+
"main": "./src/index.js",
|
|
23
|
+
"engines": {
|
|
24
|
+
"node": ">=10"
|
|
25
|
+
},
|
|
26
|
+
"scripts": {
|
|
27
|
+
"postinstall": "npx simple-git-hooks",
|
|
28
|
+
"ci:format": "prettier --write \"**/*.{json,md,yml,js}\"",
|
|
29
|
+
"ci:lint:fs": "ls-lint",
|
|
30
|
+
"ci:lint:editor": "editorconfig-checker",
|
|
31
|
+
"ci:lint:format": "prettier --check \"**/*.{json,md,yml,js}\"",
|
|
32
|
+
"ci:lint:js": "eslint \"**/*.js\"",
|
|
33
|
+
"ci:lint:type": "tsc --noEmit",
|
|
34
|
+
"ci:lint": "npm run ci:lint:fs && npm run ci:lint:editor && npm run ci:lint:format && npm run ci:lint:js && npm run ci:lint:type",
|
|
35
|
+
"ci:test": "node --import jsdom-global/register.js --test",
|
|
36
|
+
"build:clean": "rm -rf dist",
|
|
37
|
+
"build:dist": "tsc -p tsconfig.build.json",
|
|
38
|
+
"build:cp": "cp -r src readme.md package.json LICENSE dist",
|
|
39
|
+
"build:pkg": "cd dist && npm pkg set types=./src/index.d.ts",
|
|
40
|
+
"build": "npm run build:clean && npm run build:dist && npm run build:pkg && npm run build:cp"
|
|
41
|
+
},
|
|
42
|
+
"devDependencies": {
|
|
43
|
+
"@commitlint/cli": "18.4.3",
|
|
44
|
+
"@commitlint/config-conventional": "18.4.3",
|
|
45
|
+
"@ls-lint/ls-lint": "2.2.2",
|
|
46
|
+
"@testing-library/dom": "9.3.3",
|
|
47
|
+
"@types/eslint": "8.44.8",
|
|
48
|
+
"@types/lint-staged": "13.2.2",
|
|
49
|
+
"editorconfig-checker": "5.1.2",
|
|
50
|
+
"eslint": "8.55.0",
|
|
51
|
+
"eslint-plugin-import": "2.29.0",
|
|
52
|
+
"eslint-plugin-jsdoc": "46.9.0",
|
|
53
|
+
"eslint-plugin-perfectionist": "2.5.0",
|
|
54
|
+
"eslint-plugin-simple-import-sort": "10.0.0",
|
|
55
|
+
"eslint-plugin-sonarjs": "0.23.0",
|
|
56
|
+
"eslint-plugin-unicorn": "49.0.0",
|
|
57
|
+
"jsdom": "23.0.1",
|
|
58
|
+
"jsdom-global": "3.0.2",
|
|
59
|
+
"lint-staged": "15.2.0",
|
|
60
|
+
"prettier": "3.1.0",
|
|
61
|
+
"prettier-plugin-jsdoc": "1.1.1",
|
|
62
|
+
"simple-git-hooks": "2.9.0",
|
|
63
|
+
"typescript": "5.3.2"
|
|
64
|
+
},
|
|
65
|
+
"simple-git-hooks": {
|
|
66
|
+
"pre-commit": "npx lint-staged",
|
|
67
|
+
"commit-msg": "npx commitlint --edit $1"
|
|
68
|
+
},
|
|
69
|
+
"types": "./src/index.d.ts"
|
|
58
70
|
}
|
package/readme.md
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
# form-payload
|
|
2
2
|
|
|
3
|
-
[](https://github.com/What1s1ove/form-payload/actions?query=workflow%3APublish)
|
|
3
|
+
[](https://github.com/what1s1ove/whatislove.dev/actions/workflows/ci.yml)
|
|
4
|
+
[](https://github.com/what1s1ove/whatislove.dev/actions/workflows/cd.yml)
|
|
6
5
|
|
|
7
|
-
Gets form
|
|
6
|
+
Gets _proper_ form payload – via `form.elements`.
|
|
8
7
|
|
|
9
8
|
## Install
|
|
10
9
|
|
|
@@ -12,120 +11,87 @@ Gets form-payload (or payload for a named form field) - via `form.elements`.
|
|
|
12
11
|
npm install form-payload
|
|
13
12
|
```
|
|
14
13
|
|
|
14
|
+
## Demo
|
|
15
|
+
|
|
16
|
+
- [Basic (JavaScript)](https://stackblitz.com/edit/form-payload-basic?file=index.js)
|
|
17
|
+
- [Advanced (TypeScript + Validation)](https://stackblitz.com/edit/form-payload-advanced?file=index.ts,get-form-payload.ts)
|
|
18
|
+
- [Framework (React + TypeScript)](https://stackblitz.com/edit/form-payload-framework?file=src%2FApp.tsx)
|
|
19
|
+
|
|
20
|
+
PS. _The library works perfectly with any framework. Just use a valid [HTMLFormElement](https://developer.mozilla.org/en-US/docs/Web/API/HTMLFormElement). The same applies to validations and any other libraries. Just create your own wrappers on top of the functions exported by **form-payload** library._
|
|
21
|
+
|
|
15
22
|
## Usage
|
|
16
23
|
|
|
17
24
|
```html
|
|
18
|
-
<!-- index.html -->
|
|
19
25
|
<form name="general">
|
|
20
26
|
<label>
|
|
21
27
|
Name
|
|
22
|
-
<input type="text" name="name" value="
|
|
28
|
+
<input type="text" name="name" value="John" />
|
|
23
29
|
</label>
|
|
24
30
|
<label>
|
|
25
31
|
Birthday
|
|
26
|
-
<input type="date" name="birthday" value="2021-03-27"
|
|
27
|
-
</label>
|
|
28
|
-
<label>
|
|
29
|
-
Friends Count
|
|
30
|
-
<input type="number" name="friendsCount" value="1">
|
|
32
|
+
<input type="date" name="birthday" value="2021-03-27" />
|
|
31
33
|
</label>
|
|
32
|
-
<fieldset name="friend">
|
|
33
|
-
<legend>Friend</legend>
|
|
34
|
-
<label>
|
|
35
|
-
Friend Name
|
|
36
|
-
<input type="test" name="friendName" value="Kate">
|
|
37
|
-
</label>
|
|
38
|
-
</fieldset>
|
|
39
34
|
<button type="submit">Submit</button>
|
|
40
35
|
</form>
|
|
41
36
|
|
|
42
|
-
...
|
|
43
|
-
|
|
44
37
|
<form name="mailing">
|
|
45
38
|
<label>
|
|
46
39
|
Mailing
|
|
47
|
-
<input type="email" name="mail"
|
|
40
|
+
<input type="email" name="mail" value="example@mail.com" />
|
|
48
41
|
</label>
|
|
49
42
|
</form>
|
|
50
|
-
```
|
|
51
|
-
|
|
52
|
-
```js
|
|
53
|
-
// index.js
|
|
54
|
-
import { getFormValues, getControlValue } from 'form-payload';
|
|
55
|
-
|
|
56
|
-
const { general: generalFormNode, mailing: mailingFormNode } = document.forms;
|
|
57
43
|
|
|
58
|
-
|
|
59
|
-
|
|
44
|
+
<script>
|
|
45
|
+
import { getFormPayload, getFormControlPayload } from 'form-payload';
|
|
60
46
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
// name: 'Jon',
|
|
64
|
-
// birthday: Sat Mar 27 2021 18:06:42 GMT+0200 (Eastern European Standard Time),
|
|
65
|
-
// friendsCount: 1,
|
|
66
|
-
// friend: {
|
|
67
|
-
// friendName: 'Kate',
|
|
68
|
-
// },
|
|
69
|
-
// }
|
|
70
|
-
});
|
|
47
|
+
const generalFormNode = document.querySelector('form[name="general"]');
|
|
48
|
+
const mailingFormNode = document.querySelector('form[name="mailing"]');
|
|
71
49
|
|
|
72
|
-
|
|
73
|
-
console.log(getControlValue(evt.target));
|
|
74
|
-
// 'example@mail.com'
|
|
75
|
-
});
|
|
76
|
-
|
|
77
|
-
```
|
|
78
|
-
|
|
79
|
-
## With Frameworks
|
|
80
|
-
|
|
81
|
-
*It doesn't matter which framework you use, you just need to pass the valid [HTMLFormElement](https://developer.mozilla.org/en-US/docs/Web/API/HTMLFormElement).*
|
|
82
|
-
|
|
83
|
-
### React
|
|
84
|
-
|
|
85
|
-
```jsx
|
|
86
|
-
import { getFormValues, getControlValue, ControlType } from 'form-payload';
|
|
87
|
-
|
|
88
|
-
const SimpleForm = () => {
|
|
89
|
-
const handleSubmit = (evt: React.FormEvent<HTMLFormElement>) => {
|
|
50
|
+
generalFormNode.addEventListener('submit', (evt) => {
|
|
90
51
|
evt.preventDefault();
|
|
91
52
|
|
|
92
|
-
|
|
93
|
-
// {
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
// 'example@mail.com'
|
|
102
|
-
};
|
|
103
|
-
|
|
104
|
-
return (
|
|
105
|
-
<>
|
|
106
|
-
<form onSubmit={handleSubmit}>
|
|
107
|
-
<label>
|
|
108
|
-
Name
|
|
109
|
-
<input name="name" type={ControlType.TEXT} defaultValue="Jon" />
|
|
110
|
-
</label>
|
|
111
|
-
<label>
|
|
112
|
-
Date
|
|
113
|
-
<input name="birthday" type={ControlType.DATE} defaultValue="2021-03-27" />
|
|
114
|
-
</label>
|
|
115
|
-
<button type="submit">Submit</button>
|
|
116
|
-
</form>
|
|
117
|
-
|
|
118
|
-
...
|
|
119
|
-
|
|
120
|
-
<form>
|
|
121
|
-
<label>
|
|
122
|
-
Mailing
|
|
123
|
-
<input name="mail" type={ControlType.EMAIL} onChange={handleChange} />
|
|
124
|
-
</label>
|
|
125
|
-
</form>
|
|
126
|
-
</>
|
|
127
|
-
);
|
|
128
|
-
};
|
|
53
|
+
const formPayload = getFormPayload(generalFormNode);
|
|
54
|
+
// => { name: 'John', birthday: 'Sat Mar 27 2021 02:00:00 GMT+0200' }
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
mailingFormNode.addEventListener('input', (evt) => {
|
|
58
|
+
const formControlPayload = getFormControlPayload(evt.target);
|
|
59
|
+
// => 'example@mail.com'
|
|
60
|
+
});
|
|
61
|
+
</script>
|
|
129
62
|
```
|
|
130
63
|
|
|
131
|
-
##
|
|
64
|
+
## Value Correspondence Table
|
|
65
|
+
|
|
66
|
+
| HTMLElement | Attributes | Included | Value |
|
|
67
|
+
| ------------------------------------------------------------------------------------------- | ---------------------------- | -------- | ----------------------------------------------------------------------------------------------- |
|
|
68
|
+
| [HTMLInputElement](https://developer.mozilla.org/en-US/docs/Web/API/HTMLInputElement) | `type="text"` | ✅ | `string` |
|
|
69
|
+
| [HTMLInputElement](https://developer.mozilla.org/en-US/docs/Web/API/HTMLInputElement) | `type="password"` | ✅ | `string` |
|
|
70
|
+
| [HTMLInputElement](https://developer.mozilla.org/en-US/docs/Web/API/HTMLInputElement) | `type="email"` | ✅ | `string` |
|
|
71
|
+
| [HTMLInputElement](https://developer.mozilla.org/en-US/docs/Web/API/HTMLInputElement) | `type="search"` | ✅ | `string` |
|
|
72
|
+
| [HTMLInputElement](https://developer.mozilla.org/en-US/docs/Web/API/HTMLInputElement) | `type="url"` | ✅ | `string` |
|
|
73
|
+
| [HTMLInputElement](https://developer.mozilla.org/en-US/docs/Web/API/HTMLInputElement) | `type="tel"` | ✅ | `string` |
|
|
74
|
+
| [HTMLInputElement](https://developer.mozilla.org/en-US/docs/Web/API/HTMLInputElement) | `type="color"` | ✅ | `string` |
|
|
75
|
+
| [HTMLInputElement](https://developer.mozilla.org/en-US/docs/Web/API/HTMLInputElement) | `type="datetime-local"` | ✅ | `string` |
|
|
76
|
+
| [HTMLInputElement](https://developer.mozilla.org/en-US/docs/Web/API/HTMLInputElement) | `type="radio"` | ✅ | `string` |
|
|
77
|
+
| [HTMLInputElement](https://developer.mozilla.org/en-US/docs/Web/API/HTMLInputElement) | `type="hidden"` | ✅ | `string` |
|
|
78
|
+
| [HTMLInputElement](https://developer.mozilla.org/en-US/docs/Web/API/HTMLInputElement) | `type="number"` | ✅ | `number` |
|
|
79
|
+
| [HTMLInputElement](https://developer.mozilla.org/en-US/docs/Web/API/HTMLInputElement) | `type="range"` | ✅ | `number` |
|
|
80
|
+
| [HTMLInputElement](https://developer.mozilla.org/en-US/docs/Web/API/HTMLInputElement) | `type="checkbox"` | ✅ | `boolean` |
|
|
81
|
+
| [HTMLInputElement](https://developer.mozilla.org/en-US/docs/Web/API/HTMLInputElement) | `type="date"` | ✅ | [`Date`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date) |
|
|
82
|
+
| [HTMLInputElement](https://developer.mozilla.org/en-US/docs/Web/API/HTMLInputElement) | `type="time"` | ✅ | [`Date`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date) |
|
|
83
|
+
| [HTMLInputElement](https://developer.mozilla.org/en-US/docs/Web/API/HTMLInputElement) | `type="month"` | ✅ | [`Date`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date) |
|
|
84
|
+
| [HTMLInputElement](https://developer.mozilla.org/en-US/docs/Web/API/HTMLInputElement) | `type="week"` | ✅ | [`Date`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date) |
|
|
85
|
+
| [HTMLInputElement](https://developer.mozilla.org/en-US/docs/Web/API/HTMLInputElement) | `type="file"` | ✅ | [`File`](https://developer.mozilla.org/en-US/docs/Web/API/File) or `null` |
|
|
86
|
+
| [HTMLInputElement](https://developer.mozilla.org/en-US/docs/Web/API/HTMLInputElement) | `type="file"` and `multiple` | ✅ | <code>Array<[File](https://developer.mozilla.org/en-US/docs/Web/API/File)></code> |
|
|
87
|
+
| [HTMLInputElement](https://developer.mozilla.org/en-US/docs/Web/API/HTMLInputElement) | `type="button"` | ❌ | – |
|
|
88
|
+
| [HTMLInputElement](https://developer.mozilla.org/en-US/docs/Web/API/HTMLInputElement) | `type="submit"` | ❌ | – |
|
|
89
|
+
| [HTMLInputElement](https://developer.mozilla.org/en-US/docs/Web/API/HTMLInputElement) | `type="reset"` | ❌ | – |
|
|
90
|
+
| [HTMLInputElement](https://developer.mozilla.org/en-US/docs/Web/API/HTMLInputElement) | `type="image"` | ❌ | – |
|
|
91
|
+
| [HTMLTextAreaElement](https://developer.mozilla.org/en-US/docs/Web/API/HTMLTextareaElement) | – | ✅ | `string` |
|
|
92
|
+
| [HTMLSelectElement](https://developer.mozilla.org/en-US/docs/Web/API/HTMLSelectElement) | – | ✅ | `string` |
|
|
93
|
+
| [HTMLSelectElement](https://developer.mozilla.org/en-US/docs/Web/API/HTMLSelectElement) | `multiple` | ✅ | `Array<string>` |
|
|
94
|
+
| [HTMLOutputElement](https://developer.mozilla.org/en-US/docs/Web/API/HTMLOutputElement) | – | ✅ | `string` |
|
|
95
|
+
| [HTMLFieldsetElement](https://developer.mozilla.org/en-US/docs/Web/API/HTMLFieldsetElement) | – | ✅ | `Object<name: string, value: unknown>` (recursive values of nested elements) |
|
|
96
|
+
| [HTMLButtonElement](https://developer.mozilla.org/en-US/docs/Web/API/HTMLButtonElement) | – | ❌ | – |
|
|
97
|
+
| [HTMLObjectElement](https://developer.mozilla.org/en-US/docs/Web/API/HTMLObjectElement) | – | ❌ | – |
|
package/src/index.d.ts
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { ControlType } from "./libs/enums/enums.js";
|
|
2
|
+
export { FormPayloadError } from "./libs/exceptions/exceptions.js";
|
|
3
|
+
export { getFormControlPayload } from "./packages/get-form-control-payload/get-form-control-payload.js";
|
|
4
|
+
export { getFormPayload } from "./packages/get-form-payload/get-form-payload.js";
|
|
5
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.js"],"names":[],"mappings":""}
|
package/src/index.js
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export { ControlType } from './libs/enums/enums.js';
|
|
2
|
+
export { FormPayloadError } from './libs/exceptions/exceptions.js';
|
|
3
|
+
export { getFormControlPayload } from './packages/get-form-control-payload/get-form-control-payload.js';
|
|
4
|
+
export { getFormPayload } from './packages/get-form-payload/get-form-payload.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"banned-control-types.constant.d.ts","sourceRoot":"","sources":["../../../../src/libs/constants/banned-control-types.constant.js"],"names":[],"mappings":"AAEA,mFAKG"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../../../src/libs/constants/constants.js"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { BANNED_CONTROL_TYPES } from './banned-control-types.constant.js';
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
export namespace ControlType {
|
|
2
|
+
let TEXT: "text";
|
|
3
|
+
let PASSWORD: "password";
|
|
4
|
+
let EMAIL: "email";
|
|
5
|
+
let SEARCH: "search";
|
|
6
|
+
let URL: "url";
|
|
7
|
+
let TEL: "tel";
|
|
8
|
+
let COLOR: "color";
|
|
9
|
+
let DATETIME_LOCAL: "datetime-local";
|
|
10
|
+
let RADIO: "radio";
|
|
11
|
+
let HIDDEN: "hidden";
|
|
12
|
+
let NUMBER: "number";
|
|
13
|
+
let RANGE: "range";
|
|
14
|
+
let CHECKBOX: "checkbox";
|
|
15
|
+
let DATE: "date";
|
|
16
|
+
let TIME: "time";
|
|
17
|
+
let MONTH: "month";
|
|
18
|
+
let WEEK: "week";
|
|
19
|
+
let FILE: "file";
|
|
20
|
+
let BUTTON: "button";
|
|
21
|
+
let SUBMIT: "submit";
|
|
22
|
+
let RESET: "reset";
|
|
23
|
+
let IMAGE: "image";
|
|
24
|
+
let TEXTAREA: "textarea";
|
|
25
|
+
let SELECT_MULTIPLE: "select-multiple";
|
|
26
|
+
let SELECT_ONE: "select-one";
|
|
27
|
+
let OUTPUT: "output";
|
|
28
|
+
let FIELDSET: "fieldset";
|
|
29
|
+
}
|
|
30
|
+
//# sourceMappingURL=control-type.enum.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"control-type.enum.d.ts","sourceRoot":"","sources":["../../../../src/libs/enums/control-type.enum.js"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
const ControlType = /** @type {const} */ ({
|
|
2
|
+
TEXT: 'text',
|
|
3
|
+
PASSWORD: 'password',
|
|
4
|
+
EMAIL: 'email',
|
|
5
|
+
SEARCH: 'search',
|
|
6
|
+
URL: 'url',
|
|
7
|
+
TEL: 'tel',
|
|
8
|
+
COLOR: 'color',
|
|
9
|
+
DATETIME_LOCAL: 'datetime-local',
|
|
10
|
+
RADIO: 'radio',
|
|
11
|
+
HIDDEN: 'hidden',
|
|
12
|
+
|
|
13
|
+
NUMBER: 'number',
|
|
14
|
+
RANGE: 'range',
|
|
15
|
+
|
|
16
|
+
CHECKBOX: 'checkbox',
|
|
17
|
+
|
|
18
|
+
DATE: 'date',
|
|
19
|
+
TIME: 'time',
|
|
20
|
+
MONTH: 'month',
|
|
21
|
+
WEEK: 'week',
|
|
22
|
+
|
|
23
|
+
FILE: 'file',
|
|
24
|
+
|
|
25
|
+
BUTTON: 'button',
|
|
26
|
+
SUBMIT: 'submit',
|
|
27
|
+
RESET: 'reset',
|
|
28
|
+
IMAGE: 'image',
|
|
29
|
+
|
|
30
|
+
TEXTAREA: 'textarea',
|
|
31
|
+
|
|
32
|
+
SELECT_MULTIPLE: 'select-multiple',
|
|
33
|
+
SELECT_ONE: 'select-one',
|
|
34
|
+
|
|
35
|
+
OUTPUT: 'output',
|
|
36
|
+
|
|
37
|
+
FIELDSET: 'fieldset',
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
export { ControlType };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"enums.d.ts","sourceRoot":"","sources":["../../../../src/libs/enums/enums.js"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { ControlType } from './control-type.enum.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"exceptions.d.ts","sourceRoot":"","sources":["../../../../src/libs/exceptions/exceptions.js"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { FormPayloadError } from './form-payload-error.exception.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"form-payload-error.exception.d.ts","sourceRoot":"","sources":["../../../../src/libs/exceptions/form-payload-error.exception.js"],"names":[],"mappings":"AAAA;IACC;;;;OAIG;IACH,yBAJW;QACV,OAAU,EAAE,MAAM,CAAC;KAChB,EAMH;CACD"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export namespace bannedElementNameToElementInstance {
|
|
2
|
+
let button: {
|
|
3
|
+
new (): HTMLButtonElement;
|
|
4
|
+
prototype: HTMLButtonElement;
|
|
5
|
+
};
|
|
6
|
+
let object: {
|
|
7
|
+
new (): HTMLObjectElement;
|
|
8
|
+
prototype: HTMLObjectElement;
|
|
9
|
+
};
|
|
10
|
+
}
|
|
11
|
+
//# sourceMappingURL=element-name-to-element-instance.map.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"element-name-to-element-instance.map.d.ts","sourceRoot":"","sources":["../../../../src/libs/maps/element-name-to-element-instance.map.js"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"maps.d.ts","sourceRoot":"","sources":["../../../../src/libs/maps/maps.js"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { bannedElementNameToElementInstance } from './element-name-to-element-instance.map.js';
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export type HTMLFormNonOperationalControlElement = import('./html-form-non-operational-control-element.type.js').HTMLFormNonOperationalControlElement;
|
|
2
|
+
export type HTMLFormOperationalControlElement = import('./html-form-operational-control-element.type.js').HTMLFormOperationalControlElement;
|
|
3
|
+
export type HTMLFormControlElement = HTMLFormNonOperationalControlElement | HTMLFormOperationalControlElement;
|
|
4
|
+
//# sourceMappingURL=html-form-control-element.type.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"html-form-control-element.type.d.ts","sourceRoot":"","sources":["../../../../src/libs/types/html-form-control-element.type.js"],"names":[],"mappings":"mDAAc,OAAO,qDAAqD,EAAE,oCAAoC;gDAClG,OAAO,iDAAiD,EAAE,iCAAiC;qCAG5F,oCAAoC,GAC3C,iCAAiC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/** @typedef {import('./html-form-non-operational-control-element.type.js').HTMLFormNonOperationalControlElement} HTMLFormNonOperationalControlElement */
|
|
2
|
+
/** @typedef {import('./html-form-operational-control-element.type.js').HTMLFormOperationalControlElement} HTMLFormOperationalControlElement */
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* @typedef {HTMLFormNonOperationalControlElement
|
|
6
|
+
* | HTMLFormOperationalControlElement} HTMLFormControlElement
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"html-form-non-operational-control-element.type.d.ts","sourceRoot":"","sources":["../../../../src/libs/types/html-form-non-operational-control-element.type.js"],"names":[],"mappings":"mDAAc,iBAAiB,GAAG,iBAAiB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"html-form-operational-control-element.type.d.ts","sourceRoot":"","sources":["../../../../src/libs/types/html-form-operational-control-element.type.js"],"names":[],"mappings":"gDACa,gBAAgB,GACvB,iBAAiB,GACjB,iBAAiB,GACjB,mBAAmB,GACnB,mBAAmB"}
|