{"id":20731120,"url":"https://github.com/stevenmhunt/interfacejs","last_synced_at":"2025-07-11T12:10:00.256Z","repository":{"id":7517848,"uuid":"8868441","full_name":"stevenmhunt/interfaceJS","owner":"stevenmhunt","description":"Provides a simple mechanism for code contracts I.E. interfaces in JavaScript.","archived":false,"fork":false,"pushed_at":"2013-03-19T02:35:26.000Z","size":112,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-27T15:02:29.135Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/stevenmhunt.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}},"created_at":"2013-03-19T01:38:47.000Z","updated_at":"2025-01-02T01:13:25.000Z","dependencies_parsed_at":"2022-09-22T13:23:27.163Z","dependency_job_id":null,"html_url":"https://github.com/stevenmhunt/interfaceJS","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/stevenmhunt/interfaceJS","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stevenmhunt%2FinterfaceJS","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stevenmhunt%2FinterfaceJS/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stevenmhunt%2FinterfaceJS/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stevenmhunt%2FinterfaceJS/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/stevenmhunt","download_url":"https://codeload.github.com/stevenmhunt/interfaceJS/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stevenmhunt%2FinterfaceJS/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":264804048,"owners_count":23666514,"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":[],"created_at":"2024-11-17T05:13:46.558Z","updated_at":"2025-07-11T12:10:00.215Z","avatar_url":"https://github.com/stevenmhunt.png","language":"JavaScript","readme":"interfaceJS\n===========\n\nProvides a simple mechanism for code contracts I.E. interfaces in JavaScript.\n\nHow to use\n----------\n\n*Step 1 - Create your interface definition.*\n\nYou will use the create() method of interfaceJS to create the interface definition. Provide a list of required members for the interface, and when you check this against your objects it will be able to enforce the interface.\n\n```javascript\n\nvar iMyInterface = interfaceJS.create([\"prop1\", \"func1\", \"etc.\"])\n````\n\n*Step 2 - Validate your objects.*\n\nYou will use the implementedBy() method to check if your object implements the interface.\n\n```javascript\n\nvar myObj = {\n  \"prop1\": 1,\n  \"prop2\": 2,\n  \"prop3\": 3\n};\n\nalert(\"Does the object implement the interface? \" + (iMyInterface.implementedBy(myObj) ? \"Yes\" : \"No\");\n```\n\nIn the case, the implementedBy() method would return false, since the object does not contain all of the required elements defined in the interface.\n\n*More Advanced Features*\n\nMuch like languages that implement interfaces natively, you can require than an interface implement any number of other interfaces. You can specify the other interfaces when defining the interface using the implement() method as follows:\n\n```javascript\n\nvar iMyChildInterface = interfaceJS.create([\n  \"foo\", \"bar\"\n]).implement([\n  iMyInterface\n]);\n```\n\nNote that I have taken special care to avoid any future reserved words in the JavaScript language such as \"interface\", \"implements\", and \"extends\". While these keywords are not current in use by the language, they are best avoided.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstevenmhunt%2Finterfacejs","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fstevenmhunt%2Finterfacejs","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstevenmhunt%2Finterfacejs/lists"}