@jalik/form-parser
Advanced tools
Comparing version 2.0.10 to 2.0.11
# Changelog | ||
## v2.0.11 | ||
- Upgraded dependencies | ||
## v2.0.10 | ||
- Upgraded dependencies | ||
## v2.0.9 | ||
- Upgraded dependencies | ||
## v2.0.8 | ||
- Fixed parsing of input names containing dashes (and probably other previously special characters) | ||
## v2.0.7 | ||
- Renamed form-parser.js to index.js | ||
@@ -17,2 +25,3 @@ - Upgraded dependencies | ||
## v2.0.6 | ||
- Fixed `cleanFunction` calling on password fields, which must never happen | ||
@@ -23,23 +32,31 @@ - Added support to define number as object attribute if surrounded by double quotes or single quotes | ||
## v2.0.5 | ||
- Upgraded dependencies | ||
## v2.0.4 | ||
- Upgraded dependencies | ||
## v2.0.3 | ||
- Upgraded dependencies | ||
## v2.0.2 | ||
- Upgraded dependencies | ||
## v2.0.1 | ||
- Upgraded dependencies | ||
## v2.0.0 | ||
- Upgraded dependencies | ||
**BREAKING CHANGES:** | ||
- Export functions using named export instead of default export syntax | ||
## v1.3.0 | ||
- Lib available in ES6+ syntax (see `src` folder) to enable auto-completion in IDEs | ||
@@ -49,24 +66,29 @@ - Upgraded dependencies | ||
## v1.2.2 | ||
- Upgraded dependencies | ||
## v1.2.1 | ||
- Upgraded dependencies | ||
## v1.2.0 | ||
- Upgraded dependencies | ||
- Removed unused devDependencies | ||
- Added support for more patterns in method `buildObject()`: | ||
- `buildObject('customField', value, context)` | ||
- `buildObject('customField[attr]', value, context)` | ||
- `buildObject('customFields[0]', value, context)` | ||
- `buildObject('customField', value, context)` | ||
- `buildObject('customField[attr]', value, context)` | ||
- `buildObject('customFields[0]', value, context)` | ||
- Changes behavior of method `buildObject()` to remove `undefined` fields: | ||
- Array index with value `undefined` is removed from the result | ||
- (ex: calling `buildObject('items[0]', undefined, {items:[1,2]})` returns `{items:[2]}`) | ||
- Object attribute with value `undefined` is removed from the result | ||
- (ex: calling `buildObject('obj[a]', undefined, {obj:{a:1,b:2}})` returns `{obj:{b:2}}`) | ||
- Array index with value `undefined` is removed from the result | ||
- (ex: calling `buildObject('items[0]', undefined, {items:[1,2]})` returns `{items:[2]}`) | ||
- Object attribute with value `undefined` is removed from the result | ||
- (ex: calling `buildObject('obj[a]', undefined, {obj:{a:1,b:2}})` returns `{obj:{b:2}}`) | ||
## v1.1.1 | ||
- Upgraded dependencies | ||
## v1.1.0 | ||
- Added method `nullify(value)` | ||
@@ -77,11 +99,16 @@ - Added method `parseField(field, options)` | ||
## v1.0.8 | ||
- Does not filter field names anymore | ||
## v1.0.6 | ||
- Fixed method `parseForm()` not returning fields with a name that contains dashes (ex: `x-custom-field`) | ||
- Fixed method `parseForm()` not returning fields with a name that contains dashes ( | ||
ex: `x-custom-field`) | ||
## v1.0.5 | ||
- Fixed method `parseForm()` not returning fields with a name that is one character long | ||
## v1.0.4 | ||
- Renames option `parseValues` to `dynamicTyping` in `parseForm()` method | ||
@@ -92,2 +119,3 @@ - Renames option `smartParsing` to `smartTyping` in `parseForm()` method | ||
## v1.0.3 | ||
- Fixed error with unchecked fields being parsed | ||
@@ -98,2 +126,3 @@ - Changes signature of method `cleanFunction(value, field)` called by `parseForm()` | ||
## v1.0.2 | ||
- Updates README.md | ||
@@ -103,2 +132,3 @@ - Removed dependency to `underscore` | ||
## v1.0.0 | ||
- First public release |
@@ -20,9 +20,13 @@ "use strict"; | ||
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty")); | ||
var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof")); | ||
var _deepExtend = _interopRequireDefault(require("@jalik/deep-extend")); | ||
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; } | ||
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { (0, _defineProperty2["default"])(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; } | ||
/* | ||
* The MIT License (MIT) | ||
* Copyright (c) 2020 Karl STEIN | ||
* Copyright (c) 2021 Karl STEIN | ||
*/ | ||
@@ -350,3 +354,3 @@ | ||
var opt = (0, _deepExtend["default"])({ | ||
var opts = _objectSpread({ | ||
dynamicTyping: true, | ||
@@ -357,2 +361,3 @@ nullify: true, | ||
}, options); | ||
var isCheckable = isCheckableField(field); | ||
@@ -388,3 +393,3 @@ var value = field.value; // Fetch value from special fields | ||
if (opt.dynamicTyping) { | ||
if (opts.dynamicTyping) { | ||
// Parse value excepted for special fields | ||
@@ -436,3 +441,3 @@ if ((!isCheckable || field.checked) && !contains(['email', 'file', 'password', 'search', 'url'], field.type) && !contains(['textarea'], field.localName)) { | ||
} | ||
} else if (opt.smartTyping) { | ||
} else if (opts.smartTyping) { | ||
// Parse value using the "type" attribute | ||
@@ -466,3 +471,3 @@ switch (field.type) { | ||
if (opt.trim && field.type !== 'password') { | ||
if (opts.trim && field.type !== 'password') { | ||
value = trim(value); | ||
@@ -472,3 +477,3 @@ } // Replaces empty strings with null | ||
if (opt.nullify) { | ||
if (opts.nullify) { | ||
value = nullify(value); | ||
@@ -493,3 +498,3 @@ } | ||
var opt = (0, _deepExtend["default"])({ | ||
var opts = _objectSpread({ | ||
cleanFunction: null, | ||
@@ -507,18 +512,19 @@ dynamicTyping: true, | ||
if (typeof opt.parseValues !== 'undefined') { | ||
if (typeof opts.parseValues !== 'undefined') { | ||
// eslint-disable-next-line no-console | ||
console.warn('option "parseValues" is deprecated, rename it to "dynamicTyping" instead'); | ||
opt.dynamicTyping = opt.parseValues; | ||
opts.dynamicTyping = opts.parseValues; | ||
} | ||
if (typeof opt.smartParsing !== 'undefined') { | ||
if (typeof opts.smartParsing !== 'undefined') { | ||
// eslint-disable-next-line no-console | ||
console.warn('option "smartParsing" is deprecated, rename it to "smartTyping" instead'); | ||
opt.smartTyping = opt.smartParsing; | ||
opts.smartTyping = opts.smartParsing; | ||
} | ||
if (typeof opt.trimValues !== 'undefined') { | ||
if (typeof opts.trimValues !== 'undefined') { | ||
// eslint-disable-next-line no-console | ||
console.warn('option "trimValues" is deprecated, rename it to "trim" instead'); | ||
opt.trim = opt.trimValues; | ||
opts.trim = opts.trimValues; | ||
} | ||
@@ -545,3 +551,3 @@ | ||
if (opt.ignoreButtons && isButton(field)) { | ||
if (opts.ignoreButtons && isButton(field)) { | ||
// eslint-disable-next-line | ||
@@ -552,3 +558,3 @@ continue; | ||
if (opt.ignoreDisabled && field.disabled) { | ||
if (opts.ignoreDisabled && field.disabled) { | ||
// eslint-disable-next-line | ||
@@ -559,3 +565,3 @@ continue; | ||
if (opt.ignoreUnchecked && isCheckable && !field.checked) { | ||
if (opts.ignoreUnchecked && isCheckable && !field.checked) { | ||
// eslint-disable-next-line | ||
@@ -566,3 +572,3 @@ continue; | ||
if (typeof opt.filterFunction === 'function' && opt.filterFunction(field) !== true) { | ||
if (typeof opts.filterFunction === 'function' && opts.filterFunction(field) !== true) { | ||
// eslint-disable-next-line | ||
@@ -573,13 +579,13 @@ continue; | ||
var value = parseField(field, opt); // Execute custom clean function on fields with type different of password | ||
var value = parseField(field, opts); // Execute custom clean function on fields with type different of password | ||
if (typeof opt.cleanFunction === 'function' && field.type !== 'password') { | ||
if (typeof opts.cleanFunction === 'function' && field.type !== 'password') { | ||
if (value instanceof Array) { | ||
for (var k = 0; k < value.length; k += 1) { | ||
if (typeof value[k] === 'string' && value[k].length) { | ||
value[k] = opt.cleanFunction(value[k], field); | ||
value[k] = opts.cleanFunction(value[k], field); | ||
} | ||
} | ||
} else if (typeof value === 'string' && value.length) { | ||
value = opt.cleanFunction(value, field); | ||
value = opts.cleanFunction(value, field); | ||
} | ||
@@ -589,3 +595,3 @@ } // Ignore empty value | ||
if (opt.ignoreEmpty && (value === '' || value === null || typeof value === 'undefined')) { | ||
if (opts.ignoreEmpty && (value === '' || value === null || typeof value === 'undefined')) { | ||
// eslint-disable-next-line | ||
@@ -592,0 +598,0 @@ continue; |
{ | ||
"name": "@jalik/form-parser", | ||
"version": "2.0.10", | ||
"version": "2.0.11", | ||
"description": "A utility to parse complex forms with minimum effort.", | ||
@@ -39,20 +39,22 @@ "license": "MIT", | ||
}, | ||
"files": [ | ||
"/dist", | ||
"/src" | ||
], | ||
"dependencies": { | ||
"@babel/runtime": "^7.14.0", | ||
"@jalik/deep-extend": "^1.1.12" | ||
"@babel/runtime": "^7.15.4" | ||
}, | ||
"devDependencies": { | ||
"@babel/cli": "^7.14.3", | ||
"@babel/core": "^7.14.3", | ||
"@babel/plugin-transform-runtime": "^7.14.3", | ||
"@babel/preset-env": "^7.14.2", | ||
"acorn": "^8.2.4", | ||
"ajv": "^7.2.4", | ||
"eslint": "^7.26.0", | ||
"@babel/cli": "^7.15.7", | ||
"@babel/core": "^7.15.5", | ||
"@babel/plugin-transform-runtime": "^7.15.0", | ||
"@babel/preset-env": "^7.15.6", | ||
"acorn": "^8.5.0", | ||
"eslint": "^7.32.0", | ||
"eslint-config-airbnb-base": "^14.2.1", | ||
"eslint-plugin-import": "^2.23.2", | ||
"eslint-plugin-jest": "^24.3.6", | ||
"jest": "^26.6.3", | ||
"typescript": "^4.2.4" | ||
"eslint-plugin-import": "^2.24.2", | ||
"eslint-plugin-jest": "^24.4.2", | ||
"jest": "^27.2.1", | ||
"typescript": "^4.4.3" | ||
} | ||
} |
/* | ||
* The MIT License (MIT) | ||
* Copyright (c) 2020 Karl STEIN | ||
* Copyright (c) 2021 Karl STEIN | ||
*/ | ||
import deepExtend from '@jalik/deep-extend'; | ||
/** | ||
@@ -301,3 +299,3 @@ * Builds an object from a string (ex: [colors][0][code]) | ||
// Set default options | ||
const opt = deepExtend({ | ||
const opts = { | ||
dynamicTyping: true, | ||
@@ -307,3 +305,4 @@ nullify: true, | ||
trim: true, | ||
}, options); | ||
...options, | ||
}; | ||
@@ -338,3 +337,3 @@ const isCheckable = isCheckableField(field); | ||
if (opt.dynamicTyping) { | ||
if (opts.dynamicTyping) { | ||
// Parse value excepted for special fields | ||
@@ -385,3 +384,3 @@ if ((!isCheckable || field.checked) | ||
} | ||
} else if (opt.smartTyping) { | ||
} else if (opts.smartTyping) { | ||
// Parse value using the "type" attribute | ||
@@ -413,7 +412,7 @@ switch (field.type) { | ||
// Removes extra spaces | ||
if (opt.trim && field.type !== 'password') { | ||
if (opts.trim && field.type !== 'password') { | ||
value = trim(value); | ||
} | ||
// Replaces empty strings with null | ||
if (opt.nullify) { | ||
if (opts.nullify) { | ||
value = nullify(value); | ||
@@ -436,3 +435,3 @@ } | ||
// Default options | ||
const opt = deepExtend({ | ||
const opts = { | ||
cleanFunction: null, | ||
@@ -448,19 +447,20 @@ dynamicTyping: true, | ||
trim: true, | ||
}, options); | ||
...options, | ||
}; | ||
// Check deprecated options | ||
if (typeof opt.parseValues !== 'undefined') { | ||
if (typeof opts.parseValues !== 'undefined') { | ||
// eslint-disable-next-line no-console | ||
console.warn('option "parseValues" is deprecated, rename it to "dynamicTyping" instead'); | ||
opt.dynamicTyping = opt.parseValues; | ||
opts.dynamicTyping = opts.parseValues; | ||
} | ||
if (typeof opt.smartParsing !== 'undefined') { | ||
if (typeof opts.smartParsing !== 'undefined') { | ||
// eslint-disable-next-line no-console | ||
console.warn('option "smartParsing" is deprecated, rename it to "smartTyping" instead'); | ||
opt.smartTyping = opt.smartParsing; | ||
opts.smartTyping = opts.smartParsing; | ||
} | ||
if (typeof opt.trimValues !== 'undefined') { | ||
if (typeof opts.trimValues !== 'undefined') { | ||
// eslint-disable-next-line no-console | ||
console.warn('option "trimValues" is deprecated, rename it to "trim" instead'); | ||
opt.trim = opt.trimValues; | ||
opts.trim = opts.trimValues; | ||
} | ||
@@ -486,3 +486,3 @@ | ||
// Ignore buttons | ||
if (opt.ignoreButtons && isButton(field)) { | ||
if (opts.ignoreButtons && isButton(field)) { | ||
// eslint-disable-next-line | ||
@@ -492,3 +492,3 @@ continue; | ||
// Ignore disabled element | ||
if (opt.ignoreDisabled && field.disabled) { | ||
if (opts.ignoreDisabled && field.disabled) { | ||
// eslint-disable-next-line | ||
@@ -498,3 +498,3 @@ continue; | ||
// Ignore unchecked element | ||
if (opt.ignoreUnchecked && (isCheckable && !field.checked)) { | ||
if (opts.ignoreUnchecked && (isCheckable && !field.checked)) { | ||
// eslint-disable-next-line | ||
@@ -504,3 +504,3 @@ continue; | ||
// Ignore element based on filter | ||
if (typeof opt.filterFunction === 'function' && opt.filterFunction(field) !== true) { | ||
if (typeof opts.filterFunction === 'function' && opts.filterFunction(field) !== true) { | ||
// eslint-disable-next-line | ||
@@ -511,14 +511,14 @@ continue; | ||
// Parse field value | ||
let value = parseField(field, opt); | ||
let value = parseField(field, opts); | ||
// Execute custom clean function on fields with type different of password | ||
if (typeof opt.cleanFunction === 'function' && field.type !== 'password') { | ||
if (typeof opts.cleanFunction === 'function' && field.type !== 'password') { | ||
if (value instanceof Array) { | ||
for (let k = 0; k < value.length; k += 1) { | ||
if (typeof value[k] === 'string' && value[k].length) { | ||
value[k] = opt.cleanFunction(value[k], field); | ||
value[k] = opts.cleanFunction(value[k], field); | ||
} | ||
} | ||
} else if (typeof value === 'string' && value.length) { | ||
value = opt.cleanFunction(value, field); | ||
value = opts.cleanFunction(value, field); | ||
} | ||
@@ -528,3 +528,3 @@ } | ||
// Ignore empty value | ||
if (opt.ignoreEmpty && (value === '' || value === null || typeof value === 'undefined')) { | ||
if (opts.ignoreEmpty && (value === '' || value === null || typeof value === 'undefined')) { | ||
// eslint-disable-next-line | ||
@@ -531,0 +531,0 @@ continue; |
49612
1
11
981
6
- Removed@jalik/deep-extend@^1.1.12
- Removed@jalik/deep-extend@1.2.2(transitive)
Updated@babel/runtime@^7.15.4