Add semantic token highlighting for 'that' variable and comment file references in VS Code extension Add Phone_Text_Input and Currency_Input components with formatting utilities Implement client widgets, form standardization, and soft delete functionality Add modal scroll lock and update documentation Implement comprehensive modal system with form integration and validation Fix modal component instantiation using jQuery plugin API Implement modal system with responsive sizing, queuing, and validation support Implement form submission with validation, error handling, and loading states Implement country/state selectors with dynamic data loading and Bootstrap styling Revert Rsx::Route() highlighting in Blade/PHP files Target specific PHP scopes for Rsx::Route() highlighting in Blade Expand injection selector for Rsx::Route() highlighting Add custom syntax highlighting for Rsx::Route() and Rsx.Route() calls Update jqhtml packages to v2.2.165 Add bundle path validation for common mistakes (development mode only) Create Ajax_Select_Input widget and Rsx_Reference_Data controller Create Country_Select_Input widget with default country support Initialize Tom Select on Select_Input widgets Add Tom Select bundle for enhanced select dropdowns Implement ISO 3166 geographic data system for country/region selection Implement widget-based form system with disabled state support 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
96 lines
2.1 KiB
JavaScript
96 lines
2.1 KiB
JavaScript
'use strict';
|
|
|
|
import utils from '../utils.js';
|
|
|
|
/**
|
|
* It takes a string like `foo[x][y][z]` and returns an array like `['foo', 'x', 'y', 'z']
|
|
*
|
|
* @param {string} name - The name of the property to get.
|
|
*
|
|
* @returns An array of strings.
|
|
*/
|
|
function parsePropPath(name) {
|
|
// foo[x][y][z]
|
|
// foo.x.y.z
|
|
// foo-x-y-z
|
|
// foo x y z
|
|
return utils.matchAll(/\w+|\[(\w*)]/g, name).map(match => {
|
|
return match[0] === '[]' ? '' : match[1] || match[0];
|
|
});
|
|
}
|
|
|
|
/**
|
|
* Convert an array to an object.
|
|
*
|
|
* @param {Array<any>} arr - The array to convert to an object.
|
|
*
|
|
* @returns An object with the same keys and values as the array.
|
|
*/
|
|
function arrayToObject(arr) {
|
|
const obj = {};
|
|
const keys = Object.keys(arr);
|
|
let i;
|
|
const len = keys.length;
|
|
let key;
|
|
for (i = 0; i < len; i++) {
|
|
key = keys[i];
|
|
obj[key] = arr[key];
|
|
}
|
|
return obj;
|
|
}
|
|
|
|
/**
|
|
* It takes a FormData object and returns a JavaScript object
|
|
*
|
|
* @param {string} formData The FormData object to convert to JSON.
|
|
*
|
|
* @returns {Object<string, any> | null} The converted object.
|
|
*/
|
|
function formDataToJSON(formData) {
|
|
function buildPath(path, value, target, index) {
|
|
let name = path[index++];
|
|
|
|
if (name === '__proto__') return true;
|
|
|
|
const isNumericKey = Number.isFinite(+name);
|
|
const isLast = index >= path.length;
|
|
name = !name && utils.isArray(target) ? target.length : name;
|
|
|
|
if (isLast) {
|
|
if (utils.hasOwnProp(target, name)) {
|
|
target[name] = [target[name], value];
|
|
} else {
|
|
target[name] = value;
|
|
}
|
|
|
|
return !isNumericKey;
|
|
}
|
|
|
|
if (!target[name] || !utils.isObject(target[name])) {
|
|
target[name] = [];
|
|
}
|
|
|
|
const result = buildPath(path, value, target[name], index);
|
|
|
|
if (result && utils.isArray(target[name])) {
|
|
target[name] = arrayToObject(target[name]);
|
|
}
|
|
|
|
return !isNumericKey;
|
|
}
|
|
|
|
if (utils.isFormData(formData) && utils.isFunction(formData.entries)) {
|
|
const obj = {};
|
|
|
|
utils.forEachEntry(formData, (name, value) => {
|
|
buildPath(parsePropPath(name), value, obj, 0);
|
|
});
|
|
|
|
return obj;
|
|
}
|
|
|
|
return null;
|
|
}
|
|
|
|
export default formDataToJSON;
|