{"id":23328943,"url":"https://github.com/itsawa/basic-input-validation","last_synced_at":"2025-04-07T08:58:44.649Z","repository":{"id":268752874,"uuid":"905364581","full_name":"ITSawa/basic-input-validation","owner":"ITSawa","description":"A comprehensive library for server-side validations, including type checking, structure validation, and common field validations such as email, password, and username. It also includes checks for empty values, script injections, and SQL injections. ","archived":false,"fork":false,"pushed_at":"2024-12-18T17:17:40.000Z","size":12,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-02-13T12:41:23.822Z","etag":null,"topics":["input","input-validation","lib","library","validation"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ITSawa.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-12-18T17:13:37.000Z","updated_at":"2024-12-18T19:24:34.000Z","dependencies_parsed_at":"2024-12-18T18:24:56.708Z","dependency_job_id":"08a4f93f-7533-4d6c-a4ff-89c11657a223","html_url":"https://github.com/ITSawa/basic-input-validation","commit_stats":null,"previous_names":["itsawa/basic-input-validation"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ITSawa%2Fbasic-input-validation","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ITSawa%2Fbasic-input-validation/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ITSawa%2Fbasic-input-validation/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ITSawa%2Fbasic-input-validation/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ITSawa","download_url":"https://codeload.github.com/ITSawa/basic-input-validation/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247623010,"owners_count":20968574,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["input","input-validation","lib","library","validation"],"created_at":"2024-12-20T21:29:41.639Z","updated_at":"2025-04-07T08:58:44.622Z","avatar_url":"https://github.com/ITSawa.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Basic Input Validation\n\nThis project provides a set of utility functions for validating and sanitizing various data types such as strings, emails, usernames, passwords, and more. The utilities include checks for type validation, length constraints, SQL injection prevention, JavaScript injection prevention, and other security measures.\n\n## Functions Overview\n\n### `validateByStructure`\n\nValidates if the given data matches the defined structure.\n\n#### Parameters:\n\n- `structure`: The structure to validate against. It can be a string, array, or object.\n- `arg`: The data to be validated.\n- `path`: The current path in the structure for error reporting (default: `\"\"`).\n\n#### Returns:\n\n- Throws an error if validation fails, otherwise returns `void`.\n\n---\n\n### `validateType`\n\nValidates the type of a value against a given type.\n\n#### Parameters:\n\n- `type`: The type that the value should match.\n- `value`: The value whose type is being validated.\n\n#### Returns:\n\n- Throws an error if the types do not match.\n\n---\n\n### `validateEmail`\n\nValidates an email address based on a specific format and length constraints.\n\n#### Parameters:\n\n- `email`: The email address to validate.\n- `possibleEmailMinLength`: Minimum length of the email (default: `5`).\n- `possibleEmailLength`: Maximum length of the email (default: `64`).\n\n#### Returns:\n\n- Throws an error if the email format or length is invalid.\n\n---\n\n### `validateUserName`\n\nValidates a username based on length constraints and allowed characters.\n\n#### Parameters:\n\n- `userName`: The username to validate.\n- `possibleUserNameMinLength`: Minimum length of the username (default: `5`).\n- `possibleUserNameLength`: Maximum length of the username (default: `32`).\n\n#### Returns:\n\n- Throws an error if the username format or length is invalid.\n\n---\n\n### `validatePassword`\n\nValidates a password to ensure it meets strength requirements (length, character types).\n\n#### Parameters:\n\n- `password`: The password to validate.\n- `possiblePasswordMinLength`: Minimum length of the password (default: `8`).\n- `possiblePasswordLength`: Maximum length of the password (default: `128`).\n\n#### Returns:\n\n- Throws an error if the password does not meet the required criteria.\n\n---\n\n### `isSqlInjection`\n\nPrevents SQL injections by checking and escaping dangerous SQL keywords and patterns.\n\n#### Parameters:\n\n- `input`: The string to check for SQL injection.\n\n#### Returns:\n\n- The sanitized string with SQL keywords escaped.\n\n---\n\n### `isJsScript`\n\nPrevents JavaScript injections by checking and sanitizing `\u003cscript\u003e` tags in a string.\n\n#### Parameters:\n\n- `input`: The string to check for JavaScript injections.\n\n#### Returns:\n\n- The sanitized string with `\u003cscript\u003e` tags replaced by escaped versions.\n\n---\n\n## Example Usage\n\n```javascript\nimport { validateEmail, validateUserName, validatePassword, isSqlInjection, isJsScript } from 'basic-input-validation';\n\ntry {\n  validateEmail('example@example.com');\n  validateUserName('user123');\n  validatePassword('StrongP@ssw0rd!');\n} catch (error) {\n  console.error('Validation error:', error.message);\n}\n\nconst sanitizedInput = isSqlInjection(\"SELECT * FROM users WHERE name = 'admin';\");\nconst safeInput = isJsScript(\"\u003cscript\u003ealert('Hello!');\u003c/script\u003e\");\n\nconsole.log(sanitizedInput);  // Sanitized SQL input\nconsole.log(safeInput);       // Safe JavaScript input\nInstallation\nYou can install the package using npm:\n\nbash\n\nnpm install basic-input-validation\nLicense\nThis project is licensed under the MIT License - see the LICENSE file for details.\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fitsawa%2Fbasic-input-validation","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fitsawa%2Fbasic-input-validation","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fitsawa%2Fbasic-input-validation/lists"}