{"id":22886917,"url":"https://github.com/itsawa/safest-function","last_synced_at":"2026-02-03T19:32:22.280Z","repository":{"id":266849602,"uuid":"899548352","full_name":"ITSawa/safest-function","owner":"ITSawa","description":"Safest Function is a JavaScript library that ensures safe execution of functions by validating the types of arguments before they are passed. It supports primitive types, arrays, and objects, offering customizable error handling for safer and more reliable function execution.","archived":false,"fork":false,"pushed_at":"2024-12-06T13:53:26.000Z","size":5,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-10-02T20:44:05.661Z","etag":null,"topics":["argument-validation","dev-tool","dev-tools","error-handling","funcion-safety","function","javascript","js","library","npm-package","safety","typesafety","utility","validation"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","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-06T13:50:43.000Z","updated_at":"2024-12-06T13:58:35.000Z","dependencies_parsed_at":null,"dependency_job_id":"9a4800e3-b9a5-4e91-ab17-29751950ba0a","html_url":"https://github.com/ITSawa/safest-function","commit_stats":null,"previous_names":["itsawa/safest-function"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/ITSawa/safest-function","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ITSawa%2Fsafest-function","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ITSawa%2Fsafest-function/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ITSawa%2Fsafest-function/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ITSawa%2Fsafest-function/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ITSawa","download_url":"https://codeload.github.com/ITSawa/safest-function/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ITSawa%2Fsafest-function/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29054691,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-03T15:43:47.601Z","status":"ssl_error","status_checked_at":"2026-02-03T15:43:46.709Z","response_time":96,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["argument-validation","dev-tool","dev-tools","error-handling","funcion-safety","function","javascript","js","library","npm-package","safety","typesafety","utility","validation"],"created_at":"2024-12-13T20:28:43.955Z","updated_at":"2026-02-03T19:32:22.238Z","avatar_url":"https://github.com/ITSawa.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Safest Function\n\nA JavaScript library for safely executing functions with type-checked arguments. This library ensures that the arguments passed to a function match the expected types or structures, reducing runtime errors and improving reliability.\n\n## Features\n\n- **Type Checking**: Validates function arguments to ensure they match the specified types or structures.\n- **Flexible Type Support**: Supports primitive types (e.g., `string`, `number`), arrays, and objects.\n- **Safe Function Execution**: Executes functions only if argument types are valid, with options for error handling.\n- **Customizable Error Handling**: Choose whether errors should be thrown or logged to the console.\n\n## Installation\n\n### Using npm\n\n```bash\nnpm install safest-function\n\nUsage\ncheckType(value, type)\nChecks if the value matches the specified type.\n\nParameters:\nvalue: The value to be checked (any JavaScript data type).\ntype: The expected type or structure (string, array, or object).\nReturns:\ntrue if the value matches the type.\nfalse if the value does not match the type.\nExample:\njavascript\n\nimport { checkType } from \"safest-function\";\n\nconsole.log(checkType(\"Hello\", \"string\"));  // true\nconsole.log(checkType(123, \"string\"));      // false\nconsole.log(checkType([1, 2, 3], [\"number\"]));  // true\nconsole.log(checkType({ id: 1, name: \"John\" }, { id: \"number\", name: \"string\" }));  // true\nsafestFunction(types, args, func, throwError = false)\nSafely executes a function after validating that the argument types match the specified types.\n\nParameters:\ntypes: An array of types or structures that the arguments should match.\nargs: An array of arguments to be passed to the function.\nfunc: The function to execute.\nthrowError (optional): If true, errors are thrown; otherwise, they are logged to the console (default: false).\nReturns:\nThe result of the function execution, or undefined if an error occurred.\nExample:\njavascript\n\nimport { safestFunction } from \"safest-function\";\n\n// Define the expected types\nconst types = [\n  { user: { id: \"number\", profile: { name: \"string\" } } }, // Object with a user\n  [\"number\"],  // Array of numbers\n];\n\n// Define the arguments to pass\nconst args = [\n  { user: { id: 1, profile: { name: \"John\" } } },  // First argument: Object\n  [42, 43],  // Second argument: Array of numbers\n];\n\n// Define the function to execute\nfunction exampleFunc(userDetails, numbers) {\n  console.log(\"User Details:\", userDetails);\n  console.log(\"Numbers:\", numbers);\n}\n\n// Usage without throwing errors\nsafestFunction(types, args, exampleFunc, false);\n\n// Usage with throwing errors\ntry {\n  safestFunction(types, args, exampleFunc, true);\n} catch (error) {\n  console.error(\"Caught an error:\", error.message);\n}\nError Handling\nYou can customize how errors are handled when the argument types do not match the expected types:\n\nLog Errors to Console: By default, errors are logged to the console.\nThrow Errors: Set throwError to true in safestFunction to throw errors when arguments do not match the expected types.\nExample:\njavascript\n\ntry {\n  safestFunction(types, args, exampleFunc, true);  // Throws an error\n} catch (error) {\n  console.error(error.message);  // Caught an error\n}\nLicense\nThis library is released under the MIT License.\n\nContributing\nWe welcome contributions! Please feel free to submit issues and pull requests.\n\nHow to contribute:\nFork the repository.\nCreate a new branch (git checkout -b feature-branch).\nMake your changes.\nCommit your changes (git commit -am 'Add new feature').\nPush to the branch (git push origin feature-branch).\nCreate a pull request.\nAuthors\nITSawa Savva - Initial work - ITSawa\nAcknowledgments\nThanks to all the contributors and the open-source community!\nvbnet\n\n\n### Key Improvements:\n\n- **Markdown Structure**: Structured for readability with clear sections like \"Features\", \"Installation\", and \"Usage\".\n- **Code Blocks**: Example code is provided in clear, syntax-highlighted code blocks.\n- **Detailed Descriptions**: Explanations for parameters and return values to guide users in understanding how to use the library.\n- **Contributing Section**: A section for contributing, which is common for open-source projects on GitHub.\n\nThis format is optimized for displaying well on GitHub and in JavaScript files, providing a professional and clean presentation of your library's documentation.\n\n\n\n\n\n\n\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fitsawa%2Fsafest-function","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fitsawa%2Fsafest-function","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fitsawa%2Fsafest-function/lists"}