CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-node-forge

JavaScript implementations of network transports, cryptography, ciphers, PKI, message digests, and various utilities.

Pending
Quality

Pending

Does it follow best practices?

Impact

Pending

No eval scenarios have been run

SecuritybySnyk

Pending

The risk profile of this skill

Overview
Eval results
Files

web-forms.mddocs/

Web Form Utilities

jQuery-based utilities for manipulating web forms and serializing form data to structured JSON objects. These utilities handle complex form structures including nested objects and arrays through bracket notation.

Note: This module requires jQuery to be available and is primarily designed for browser environments.

Capabilities

Form Serialization

Convert jQuery form elements to structured JSON objects with support for nested properties and arrays.

/**
 * Serialize a form to a JSON object with nested property support
 * @param input - jQuery form element to serialize
 * @param sep - Property separator for nested objects (default: '.')
 * @param dict - Dictionary for field name replacement (name=replacement)
 * @returns Structured object representing the form data
 */
forge.form.serialize(input: jQuery, sep?: string, dict?: {[key: string]: string}): object;

Usage Examples:

// Basic form serialization
const form = $('#myForm');
const data = forge.form.serialize(form);

// Custom separator for nested properties
const data = forge.form.serialize(form, '_');

// Field name replacement
const data = forge.form.serialize(form, '.', {
  'oldFieldName': 'newFieldName',
  'user_id': 'userId'
});

Supported Form Structures

Simple Fields

Regular input fields are serialized as simple key-value pairs:

<input name="username" value="john">
<input name="email" value="john@example.com">

Results in:

{
  username: "john",
  email: "john@example.com"
}

Nested Objects

Use dot notation or custom separators to create nested objects:

<input name="user.name" value="john">
<input name="user.profile.age" value="30">
<input name="settings.theme" value="dark">

Results in:

{
  user: {
    name: "john",
    profile: {
      age: "30"
    }
  },
  settings: {
    theme: "dark"
  }
}

Arrays

Use square bracket notation to create arrays:

<input name="tags[]" value="javascript">
<input name="tags[]" value="crypto">
<input name="tags[]" value="security">

Results in:

{
  tags: ["javascript", "crypto", "security"]
}

Indexed Arrays

Specify array indices explicitly:

<input name="users[0].name" value="alice">
<input name="users[0].role" value="admin">
<input name="users[1].name" value="bob">
<input name="users[1].role" value="user">

Results in:

{
  users: [
    { name: "alice", role: "admin" },
    { name: "bob", role: "user" }
  ]
}

Complex Mixed Structures

Combine objects, arrays, and simple fields:

<input name="title" value="My Form">
<input name="metadata.version" value="1.0">
<input name="metadata.tags[]" value="form">
<input name="metadata.tags[]" value="utility">
<input name="sections[0].title" value="Personal Info">
<input name="sections[0].fields[]" value="name">
<input name="sections[0].fields[]" value="email">
<input name="sections[1].title" value="Preferences">
<input name="sections[1].fields[]" value="theme">

Results in:

{
  title: "My Form",
  metadata: {
    version: "1.0",
    tags: ["form", "utility"]
  },
  sections: [
    {
      title: "Personal Info",
      fields: ["name", "email"]
    },
    {
      title: "Preferences", 
      fields: ["theme"]
    }
  ]
}

Field Name Processing

Bracket Parsing

The utility parses bracket notation to determine structure:

  • field[] - Append to array
  • field[index] - Set specific array index
  • field[key] - Set object property
  • field[key][subkey] - Nested object properties

Name Replacement Dictionary

Use the dict parameter to rename fields during serialization:

const form = $('#registrationForm');
const data = forge.form.serialize(form, '.', {
  'user_name': 'username',
  'user_email': 'email',
  'pwd': 'password'
});

// Input field named 'user_name' becomes 'username' in output
// Input field named 'pwd' becomes 'password' in output

Integration Example

// Complete form processing example
$(document).ready(function() {
  $('#submitBtn').click(function() {
    const formData = forge.form.serialize($('#userForm'), '.', {
      'user_id': 'userId',
      'created_at': 'createdAt'
    });
    
    // Send structured data to server
    $.ajax({
      url: '/api/users',
      method: 'POST',
      contentType: 'application/json',
      data: JSON.stringify(formData),
      success: function(response) {
        console.log('User created:', response);
      }
    });
  });
});

Browser Compatibility

This module depends on jQuery and is designed for browser environments. It uses jQuery's serializeArray() method internally and requires:

  • jQuery library available globally
  • Modern browser with DOM support
  • Form elements with proper name attributes

docs

asn1.md

asymmetric-cryptography.md

index.md

logging.md

message-digests.md

network-http.md

pkcs.md

pki.md

random.md

symmetric-encryption.md

tls.md

utilities.md

web-forms.md

tile.json