{"_id":"form","_rev":"21-842f9f7f35f80ad647da366e060ce138","name":"form","dist-tags":{"latest":"0.2.5"},"versions":{"0.1.0":{"name":"form","version":"0.1.0","keywords":["form"],"author":{"name":"Vadim M. Baryshev","email":"vadimbaryshev@gmail.com"},"_id":"form@0.1.0","maintainers":[{"name":"baryshev","email":"vadimbaryshev@gmail.com"}],"dist":{"shasum":"ec79ffa78eb8772d1cc5ff95269dde37f0bc5f7c","tarball":"https://registry.npmjs.org/form/-/form-0.1.0.tgz","integrity":"sha512-NyTWDN7OZutOmwKECLG372+fqakDLYt2BZxyOVG2P2coqV1WeUdRPXmBS060XUibQt7WCGTKWwFUoYDm3AecoQ==","signatures":[{"sig":"MEQCIEUAAODZFHhVCJPvS5bP4tT12ZTpyTS1NU+w8SOPq/z1AiAfaqBUwUpjrC5k/gEe+RkL6KakowCcrRZiEmSp8uestg==","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}]},"main":"index","engines":{"node":">= 0.2.0"},"scripts":{},"repository":{"url":"git://github.com/baryshev/form.git","type":"git"},"_npmVersion":"1.0.22","description":"Form processor for filter and validation form data","_nodeVersion":"v0.4.10","_npmJsonOpts":{"file":"/home/vadim/.npm/form/0.1.0/package/package.json","wscript":false,"serverjs":false,"contributors":false},"dependencies":{"async":">= 0.1.10","validator":">= 0.2.8"},"_defaultsLoaded":true,"devDependencies":{},"_engineSupported":true,"directories":{}},"0.1.1":{"name":"form","version":"0.1.1","keywords":["form"],"author":{"name":"Vadim M. Baryshev","email":"vadimbaryshev@gmail.com"},"_id":"form@0.1.1","maintainers":[{"name":"baryshev","email":"vadimbaryshev@gmail.com"}],"dist":{"shasum":"cc75771c10437a5f1d732f1cf7a3396c1b354e16","tarball":"https://registry.npmjs.org/form/-/form-0.1.1.tgz","integrity":"sha512-L7OgpZt0YsMAYmd+4lagW0Vyqpl5AlLodWhkuxmobf95k/RyGM3fhmsUO/zEcEnYQkd8haLZbgOvlhVZgMc6qQ==","signatures":[{"sig":"MEUCIQC4b6K/sOoCm+f7Z2Z9V/BdCitFiX7D2iA+UlbH7Y0fhQIgEphyycrr9Vhy0Y9aq/kWBZqU6H5DpLKU316IMHauEKc=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}]},"main":"index","engines":{"node":">= 0.2.0"},"scripts":{},"repository":{"url":"git://github.com/baryshev/form.git","type":"git"},"_npmVersion":"1.0.22","description":"Form processor for filter and validation form data","_nodeVersion":"v0.4.10","_npmJsonOpts":{"file":"/home/vadim/.npm/form/0.1.1/package/package.json","wscript":false,"serverjs":false,"contributors":false},"dependencies":{"async":">= 0.1.10","validator":">= 0.2.8"},"_defaultsLoaded":true,"devDependencies":{},"_engineSupported":true,"directories":{}},"0.1.2":{"name":"form","version":"0.1.2","keywords":["form"],"author":{"name":"Vadim M. Baryshev","email":"vadimbaryshev@gmail.com"},"_id":"form@0.1.2","maintainers":[{"name":"baryshev","email":"vadimbaryshev@gmail.com"}],"dist":{"shasum":"058970f309b10070b7c24e7dd3b0c534ccf17fca","tarball":"https://registry.npmjs.org/form/-/form-0.1.2.tgz","integrity":"sha512-pea76xEvLYS6WP0gYhH6EIx94gXywHC0ckD4O/51aojFPEcuiVyjGOYsE9E0f1m+aN36DmiHdiCE2+1T0kNbxQ==","signatures":[{"sig":"MEUCIBjzMwiM9ClZLBtkSBG56GbO2LAj/oKi7hbCGf1nSMB+AiEA7iO2Od0crGZt8JmPBFzDI8ZNCWTNRF3tSBmXaDpt/+I=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}]},"main":"index","readme":"","engines":{"node":">= 0.2.0"},"_npmUser":{"name":"baryshev","email":"vadimbaryshev@gmail.com"},"repository":{"url":"git://github.com/baryshev/form.git","type":"git"},"_npmVersion":"1.1.0-beta-4","description":"Form processor for filter and validation form data","_nodeVersion":"v0.6.6","dependencies":{"async":">= 0.1.15","validator":">= 0.2.8"},"_defaultsLoaded":true,"devDependencies":{},"_engineSupported":true,"directories":{}},"0.2.0":{"name":"form","version":"0.2.0","keywords":["form"],"author":{"name":"Vadim M. Baryshev","email":"vadimbaryshev@gmail.com"},"_id":"form@0.2.0","maintainers":[{"name":"baryshev","email":"vadimbaryshev@gmail.com"}],"dist":{"shasum":"85b56a9748ecdccb732449900d38ae638a11b5bb","tarball":"https://registry.npmjs.org/form/-/form-0.2.0.tgz","integrity":"sha512-+6glf+PZFNKIct7DQHehhZDxrnGHeJJnbuHe1StQVTQfBH0sN+sRLjMdylOqbR+eVRtRAhzxA9hT4iEix6B3lw==","signatures":[{"sig":"MEUCICpRxSBE9xMyCbUYQDLjVVcPyCgynksmHBeN6wECt+HWAiEA5Tx6Wv8U0G113LJrcu5gOGj728MeiuZ6Gr+80+RDweg=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}]},"main":"index","readme":"","engines":{"node":">= 0.2.2"},"repository":{"url":"https://github.com/baryshev/form.git","type":"git"},"description":"Form processor for filter and validation form data","dependencies":{"async":">= 0.1.22","validator":">= 0.4.9"},"directories":{}},"0.2.1":{"name":"form","version":"0.2.1","keywords":["form"],"author":{"name":"Vadim M. Baryshev","email":"vadimbaryshev@gmail.com"},"_id":"form@0.2.1","maintainers":[{"name":"baryshev","email":"vadimbaryshev@gmail.com"}],"dist":{"shasum":"e891dc71e8305ed9aad34c12a049c978165f6882","tarball":"https://registry.npmjs.org/form/-/form-0.2.1.tgz","integrity":"sha512-mws+QQ74IFfi3pHJq6uBwswU/SPRqUVvbh+6l4hVuIUOJ4WNB/CSJ5OaO9/+nXux5WuE4Kei851M1jLBHoU3Lg==","signatures":[{"sig":"MEUCIQDaYH+C2ZfC2R0uXjlf5+afEvajtWax0gI1Lsyh+LBqxwIgDQFWtqgephnVJS7+YN/Ut2mI/jsHtRHoLmiDTYRp+oM=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}]},"main":"index","readme":"","engines":{"node":">= 0.2.2"},"repository":{"url":"https://github.com/baryshev/form.git","type":"git"},"description":"Form processor for filter and validation form data","dependencies":{"async":">= 0.1.22","validator":">= 0.4.9"},"directories":{}},"0.2.2":{"name":"form","version":"0.2.2","keywords":["form"],"author":{"name":"Vadim M. Baryshev","email":"vadimbaryshev@gmail.com"},"_id":"form@0.2.2","maintainers":[{"name":"baryshev","email":"vadimbaryshev@gmail.com"}],"dist":{"shasum":"f32e78e959c14801852898c5d27a1bdebd2d0198","tarball":"https://registry.npmjs.org/form/-/form-0.2.2.tgz","integrity":"sha512-d3J3O2POIF9YV5aCAmnN+bjPnqJ1tDA1B4iAtBNCOV7Is3sFBmRgpLfqF1by4nczw4BtnOOSDRYA093ZQSWqZQ==","signatures":[{"sig":"MEUCIGlo8k94KqBCONgFwRsC7J/7K+BT+AdearHHuVSfHXDdAiEAxo9W7LHXynamlmSYs/pYhGMFLcyxwUJ8kqvl6yavKeM=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}]},"main":"index","readme":"","engines":{"node":">= 0.2.2"},"repository":{"url":"https://github.com/baryshev/form.git","type":"git"},"description":"Form processor for filter and validation form data","dependencies":{"async":">= 0.1.22","validator":">= 0.4.9"},"directories":{}},"0.2.3":{"name":"form","version":"0.2.3","keywords":["form"],"author":{"name":"Vadim M. Baryshev","email":"vadimbaryshev@gmail.com"},"_id":"form@0.2.3","maintainers":[{"name":"baryshev","email":"vadimbaryshev@gmail.com"}],"dist":{"shasum":"8fe60bfef30d25c133ad277593adf8e8f83203e5","tarball":"https://registry.npmjs.org/form/-/form-0.2.3.tgz","integrity":"sha512-5pXth7haGwOEM9lP6WCzr9cj5voCNU9GTLKeOcBCTmh+rLaAgDFTmyoSOpcYtC76ToI55CnhADXpZfON9bA7QA==","signatures":[{"sig":"MEQCIG3vdkkC1mNqhjswRT7F6kwsSiyZ+JpuwJRAAMcR4m4YAiA9m5Ro7TWqpRQPw1GdrxMfJQYHX5Xw72KI9Bsbj+AynA==","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}]},"main":"index","readme":"","engines":{"node":">= 0.2.2"},"repository":{"url":"https://github.com/baryshev/form.git","type":"git"},"description":"Form processor for filter and validation form data","dependencies":{"async":">= 0.1.22","validator":">= 0.4.9"},"directories":{}},"0.2.4":{"name":"form","version":"0.2.4","keywords":["form"],"author":{"name":"Vadim M. Baryshev","email":"vadimbaryshev@gmail.com"},"_id":"form@0.2.4","maintainers":[{"name":"baryshev","email":"vadimbaryshev@gmail.com"}],"dist":{"shasum":"69a0e9bf9003e7d6e4eee7f9d16239148a129a21","tarball":"https://registry.npmjs.org/form/-/form-0.2.4.tgz","integrity":"sha512-3Of3Giw5TP2fzbfUec9PFil79CiRbhsnhPKN/xAqdt9fnDaclsCbTdoJsQxeWdoN3Pb4x0gCwQyLNmdPAzlenQ==","signatures":[{"sig":"MEQCIDSayaK3nYH6zF8OUVW4quG1ZTEFc64LmrxUcRdV00ZpAiAvAEBpnuBQ4X+pkt136bbezQPIlCf9zy0JitIbE58Jrw==","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}]},"main":"index","readme":"","engines":{"node":">= 0.2.2"},"repository":{"url":"https://github.com/baryshev/form.git","type":"git"},"description":"Form processor for filter and validation form data","dependencies":{"async":">= 0.1.22","validator":">= 0.4.9"},"directories":{}},"0.2.5":{"name":"form","version":"0.2.5","description":"Form processor for filter and validation form data","keywords":["form"],"author":{"name":"Vadim M. Baryshev","email":"vadimbaryshev@gmail.com"},"repository":{"type":"git","url":"git+https://github.com/baryshev/form.git"},"main":"index","dependencies":{"validator":">= 0.4.9","async":">= 0.1.22"},"engines":{"node":">= 0.2.2"},"_id":"form@0.2.5","gitHead":"c3b28e98abb73f84c5f70ba16e9f8621745f0962","bugs":{"url":"https://github.com/baryshev/form/issues"},"homepage":"https://github.com/baryshev/form#readme","_nodeVersion":"22.5.1","_npmVersion":"10.8.2","dist":{"integrity":"sha512-0UweRvfZfGSKDNREb1J++S0D4oTdcSHYWhT5ipZiqJE/bcay+tP+gzWAL1esgz7aEqeZVAAaPtrfCAdlU9lqgw==","shasum":"b82cd3a44028ef1f5449f55b7a1fa967433f7046","tarball":"https://registry.npmjs.org/form/-/form-0.2.5.tgz","fileCount":5,"unpackedSize":8570,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIFW+1yETuz2BFfFTNC8tE6icTtEFOzgKQLH2iST9WtJlAiAfirZ84UkwfvcZQS7rzZZ24odalXkpdrskjArj4FLgag=="}]},"_npmUser":{"name":"baryshev","email":"vadimbaryshev@gmail.com"},"directories":{},"maintainers":[{"name":"baryshev","email":"vadimbaryshev@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/form_0.2.5_1728538994297_0.9794198833262291"},"_hasShrinkwrap":false}},"time":{"created":"2011-10-08T19:43:50.402Z","modified":"2024-10-10T05:43:14.637Z","0.1.0":"2011-10-08T19:43:52.481Z","0.1.1":"2011-10-08T19:45:09.787Z","0.1.2":"2012-01-29T10:47:23.872Z","0.2.0":"2012-07-14T22:40:19.059Z","0.2.1":"2012-07-15T01:44:30.060Z","0.2.2":"2012-07-15T12:39:14.531Z","0.2.3":"2012-07-16T00:20:48.569Z","0.2.4":"2012-07-16T23:32:53.021Z","0.2.5":"2024-10-10T05:43:14.482Z"},"author":{"name":"Vadim M. Baryshev","email":"vadimbaryshev@gmail.com"},"repository":{"type":"git","url":"git+https://github.com/baryshev/form.git"},"description":"Form processor for filter and validation form data","keywords":["form"],"maintainers":[{"name":"baryshev","email":"vadimbaryshev@gmail.com"}],"readme":"# Form - Node.js Form Validation and Filtering Library\n\n`form` is a lightweight Node.js library designed for form validation and data filtering. It leverages `async` to handle validation and filtering tasks asynchronously and uses `validator` to check and sanitize form inputs.\n\n## Features\n\n- **Customizable Form Fields**: Easily define rules for validating and filtering individual form fields.\n- **Asynchronous Execution**: Uses async series and parallel execution to process form fields without blocking.\n- **Built-in Validators and Filters**: Utilizes `validator` for common validation and filtering tasks (e.g., checking if a field is empty, matching a regex pattern, trimming, etc.).\n- **Error Handling**: Automatically collects and returns errors during validation.\n\n## Installation\n\n```bash\nnpm install form\n```\n\n## Usage\n\n### Example\n\n```javascript\nconst form = require('form');\n\n// Define validation rules and filters for fields\nconst fields = {\n  name: [\n    form.filter(form.Filter.trim), // Trim whitespace\n    form.validator(form.Validator.notEmpty, 'Empty name'), // Name cannot be empty\n    form.validator(form.Validator.is, /[0-9]+/, 'Bad name') // Must contain numbers\n  ],\n  text: [\n    form.filter(form.Filter.trim), // Trim whitespace\n    form.validator(form.Validator.notEmpty, 'Empty text'), // Text cannot be empty\n    form.validator(form.Validator.len, 30, 1000, 'Bad text length') // Text must be between 30 and 1000 characters\n  ]\n};\n\n// Create a form instance with defined fields\nconst textForm = form.create(fields);\n\n// Process incoming form data\ntextForm.process({ text: 'some short text', name: 'tester' }, (error, data) => {\n  if (error) {\n    console.log('Errors:', error); // Print any validation errors\n  } else {\n    console.log('Valid data:', data); // Print valid form data\n  }\n});\n```\n\n### Defining Form Fields\n\nFields are defined as an object where each key is the name of the form field and its value is an array of filters and validators applied in sequence.\n\n- **Filters**: Functions that modify the field's data (e.g., trimming whitespace, converting to lowercase).\n- **Validators**: Functions that ensure the field's data meets specific criteria (e.g., not empty, matching a regex).\n\n#### Example\n\n```javascript\nconst fields = {\n  email: [\n    form.filter(form.Filter.trim), // Trim whitespace from the email\n    form.validator(form.Validator.isEmail, 'Invalid email address') // Ensure the field is a valid email address\n  ],\n  age: [\n    form.filter(form.Filter.toInt), // Convert age to an integer\n    form.validator(form.Validator.isInt, { min: 18 }, 'Must be 18 or older') // Ensure age is at least 18\n  ]\n};\n```\n\n### Processing Form Data\n\nThe `process` function validates and filters incoming data, returning the sanitized data or any validation errors.\n\n```javascript\ntextForm.process({ field1: 'some input' }, function (error, data) {\n  if (error) {\n    console.log('Validation errors:', error);\n  } else {\n    console.log('Sanitized data:', data);\n  }\n});\n```\n\n### Creating Custom Filters and Validators\n\nYou can also create custom filters and validators.\n\n#### Custom Filter Example\n\n```javascript\nform.filter(function (fields, field, callback) {\n  fields[field] = fields[field].toUpperCase(); // Convert input to uppercase\n  callback();\n});\n```\n\n#### Custom Validator Example\n\n```javascript\nform.validator(function (fields, field, callback) {\n  if (fields[field] !== 'customValue') {\n    callback('Invalid value');\n  } else {\n    callback();\n  }\n}, 'Invalid value');\n```\n\n## API\n\n### `form.create(fields)`\n\nCreates a new `Form` instance with the given fields and rules.\n\n- `fields`: An object where each key represents a form field, and its value is an array of filters and validators.\n\n### `form.process(request, callback)`\n\nProcesses incoming form data.\n\n- `request`: The form data to validate and filter (usually from an HTTP request).\n- `callback(error, data)`: A callback that receives any validation errors and the sanitized form data.\n\n### Filters\n\n- `form.Filter.trim`: Trims whitespace from a string.\n- `form.Filter.toInt`: Converts a string to an integer.\n\n### Validators\n\n- `form.Validator.notEmpty`: Ensures the field is not empty.\n- `form.Validator.isEmail`: Validates that the field contains a valid email address.\n- `form.Validator.isInt(options)`: Ensures the field is an integer (with optional range options).\n- `form.Validator.len(min, max)`: Ensures the field length is between `min` and `max`.\n","homepage":"https://github.com/baryshev/form#readme","bugs":{"url":"https://github.com/baryshev/form/issues"},"readmeFilename":"README.md"}