{"id":23465635,"url":"https://github.com/erichenry/interfacejs","last_synced_at":"2025-06-20T04:06:45.007Z","repository":{"id":79548727,"uuid":"69467501","full_name":"EricHenry/interfaceJS","owner":"EricHenry","description":"a lightweight api to create, implement, and compose interfaces","archived":false,"fork":false,"pushed_at":"2017-02-01T21:11:16.000Z","size":26,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-06-20T04:06:06.794Z","etag":null,"topics":[],"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/EricHenry.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":"2016-09-28T13:44:55.000Z","updated_at":"2017-02-01T21:11:17.000Z","dependencies_parsed_at":null,"dependency_job_id":"d01a4d96-bc07-43a7-b420-b0b4f715967c","html_url":"https://github.com/EricHenry/interfaceJS","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/EricHenry/interfaceJS","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/EricHenry%2FinterfaceJS","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/EricHenry%2FinterfaceJS/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/EricHenry%2FinterfaceJS/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/EricHenry%2FinterfaceJS/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/EricHenry","download_url":"https://codeload.github.com/EricHenry/interfaceJS/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/EricHenry%2FinterfaceJS/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":260878328,"owners_count":23075959,"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-12-24T11:30:01.021Z","updated_at":"2025-06-20T04:06:39.985Z","avatar_url":"https://github.com/EricHenry.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"![interfaceJS] (.assests/interfaceJS_logo.png)\n\nA simple lightweight api to create, implement, and compose interfaces.\n\nThis is a work in progress. The API will probably change. Please be aware if you are using the library.\n\n## What is an interface?\n\nWhat does it mean to create an interface? Basically you are defining a contract.\nThat contract is between the interface's structure (the properties \u0026 types of those properties)\nand an object you are creating. That contract guarantees that any object that you create of that\ninterface will have the same structure as the interface.\n\n## Why should I use this?\n\nThis library is meant to provide a way to define and use interfaces natively without needing a\ntranspiler. With this library you can define these strict contracts. Building objects from these\ncontracts gives you error checking so you can guarantee that the structure of the object you are creating\nmatches the interface you want to implement.\n\n## How to use\n\n### `create()`\n\nTo create an interface, provide the interface `create()` method with two arguments.\nThe first argument is the name of the interface, this should be a unique identifier among all interfaces.\nThe second argument is an object that defines the interface. The keys are the names of the properties while\nthe values are the types those properties should hold.\n\n`create()` will return an immutable (frozen) object.\nRight now that object has an id (the passed interface name)\nand the properties defining that interface.\n\n```JavaScript\n// creating an interface\nconst personInterface = Interface.create('person', {\n    nickname: 'string', //nickname will be prop of the implementing object and its value has to be a string.\n    age: 'number',\n    greet: 'function',\n});\n```\n\n### `implement()`\n\nTo implement an interface, provide the interface `implement()` method two arguments.\nFirst is the interface that you want to implement. The second argument is the object\nthat you are creating.\n\n`implement()` will return a new object with the defined properties and values.\nany function will be put on the object's prototype. Before returning, this object will check\nagainst the interface to make sure the object being created matches the interface's structure.\n\n```JavaScript\nlet brittany = Interface.implement(personInterface, {\n    nickname: 'Brinny',\n    age: 25,\n    greet() { return `Hello! Call me ${this.nickname} and I'm ${this.age}.`; }\n});\n```\n\n### `compose()`\n\nTODO\n\n## Pitfalls\n\n1. Because this a library and not a transpiler, errors when implementing an interface\nwill only be thrown at runtime. This is not as nice as having compile time errors. A possible\nworkaround would be to make an eslint plugin. (or some other work around)\n\n2. Right now the library only handles built in types. I would like to handle full function signatures\nand other interfaces as types. As well as adding types defined in node js.\n\n3. There are probably other things wrong with this idea. Please open an issue to tell me more short\ncomings of this library.\n\n## More To Come\n\n1. handle more types. (custom and node types)\n2. handle function signatures.\n3. handle optional types.\n4. allow other interfaces to be types.\n5. implement a compose function to create a new interface from existing interface.\n6. add a linter and linting rules.\n7. add some sort of build process.\n8. create function to check against interfaces being passed to functions as parameters.\n9. suggestions and ideas?!\n\n## Contributing\n\nI encourage anyone to open an issue with a problem or suggestion.\nAnyone may also submit a pull request with a fix/suggestion/or new feature. I will work to\nfully flesh out the Contributing document as well as providing linting rules and a build process\nfor anyone who wished to contribute.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ferichenry%2Finterfacejs","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ferichenry%2Finterfacejs","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ferichenry%2Finterfacejs/lists"}