{"id":18573897,"url":"https://github.com/basedwon/encoder","last_synced_at":"2025-10-28T02:40:02.659Z","repository":{"id":198365871,"uuid":"700725831","full_name":"basedwon/encoder","owner":"basedwon","description":"Provides a convenient way to define models and their associated fields allowing users to easily encode and decode data structures using different encoding schemes such as Base58 and foreign fields","archived":false,"fork":false,"pushed_at":"2023-11-07T11:27:38.000Z","size":16,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-22T03:01:54.013Z","etag":null,"topics":["base58","data-modeling","encoder"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/basedwon.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"docs/contributing.md","funding":null,"license":"LICENSE","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":"2023-10-05T07:09:02.000Z","updated_at":"2023-10-05T08:25:37.000Z","dependencies_parsed_at":"2023-11-07T12:30:13.617Z","dependency_job_id":"b945401a-742f-4fb2-93db-5b76090b37cb","html_url":"https://github.com/basedwon/encoder","commit_stats":null,"previous_names":["basedwon/encoder"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/basedwon%2Fencoder","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/basedwon%2Fencoder/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/basedwon%2Fencoder/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/basedwon%2Fencoder/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/basedwon","download_url":"https://codeload.github.com/basedwon/encoder/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254442330,"owners_count":22071863,"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":["base58","data-modeling","encoder"],"created_at":"2024-11-06T23:13:20.332Z","updated_at":"2025-10-28T02:39:57.594Z","avatar_url":"https://github.com/basedwon.png","language":"JavaScript","readme":"# Encoder\n\n[![npm](https://img.shields.io/npm/v/@basd/encoder?style=flat\u0026logo=npm)](https://www.npmjs.com/package/@basd/encoder)\n[![pipeline](https://gitlab.com/frenware/utils/encoder/badges/master/pipeline.svg)](https://gitlab.com/frenware/utils/encoder/-/pipelines)\n[![license](https://img.shields.io/npm/l/@basd/encoder)](https://gitlab.com/frenware/utils/encoder/-/blob/master/LICENSE)\n[![downloads](https://img.shields.io/npm/dw/@basd/encoder)](https://www.npmjs.com/package/@basd/encoder) \n\n[![Gitlab](https://img.shields.io/badge/Gitlab%20-%20?logo=gitlab\u0026color=%23383a40)](https://gitlab.com/frenware/utils/encoder)\n[![Github](https://img.shields.io/badge/Github%20-%20?logo=github\u0026color=%23383a40)](https://github.com/basedwon/encoder)\n[![Twitter](https://img.shields.io/badge/@basdwon%20-%20?logo=twitter\u0026color=%23383a40)](https://twitter.com/basdwon)\n[![Discord](https://img.shields.io/badge/Basedwon%20-%20?logo=discord\u0026color=%23383a40)](https://discordapp.com/users/basedwon)\n\nA highly extensible encoding library built on top of the @basd/codex package. It provides a convenient way to define models and their associated fields allowing users to easily encode and decode data structures using different encoding schemes such as Base58 and foreign fields.\n\n## Features\n\n- **Custom Field Types**: Supports different field types including `base58` and `foreign`.\n- **Flexible Models**: Define and use models easily to work with complex data structures.\n- **Encoding and Decoding**: Provides simple and efficient encoding and decoding capabilities.\n- **Foreign Field Encoding:** Seamlessly encode and decode foreign fields linked to other models.\n- **Bs58 Encoding:** Out-of-the-box support for Base58 encoding and decoding.\n\n## Installation\n\nInstall the package with:\n\n```bash\nnpm install @basd/encoder\n```\n\n## Usage\n\nFirst, import the `Encoder` library.\n\n```js\nimport Encoder from '@basd/encoder'\n```\nor\n```js\nconst Encoder = require('@basd/encoder')\n```\n\n**Use the Encoder**:\n```js\n// Define models in the constructor\nconst encoder = new Encoder({ someType: { someField: 'string' }})\n\n// Define a model by adding it\nencoder.addModel('myModelType', { someField: 'string' })\n// or\nencoder.addModel('myModelType', { fields: { someField: 'string' }})\n\n// Encode the data\nconst encodedData = encoder.encode('myModelType', data)\n\n// Decode the data\nconst decodedData = encoder.decode('myModelType', encodedData)\n```\n\n### Advanced Usage\n\nHere's an example of using a foreign field to reference another model:\n\n```js\nconst models = {\n  user: { name: 'string', age: 'number' },\n  post: { title: 'string', body: 'string', author: 'user' },\n}\nconst encoder = new Encoder(models, opts)\nlet data = { name: 'Alice', age: 33 }\nlet user = encoder.create('user', data)\nlet content = { title: 'Hello', body: 'World', author: user }\nlet post = encoder.create('post', content)\n\nlet encoded = encoder.encode('post', post)\nlet decoded = encoder.decode('post', encoded)\n```\n\n## Documentation\n\n- [API Reference](/docs/api.md)\n\n## Classes\n\n### Base58Field\n\nThis class extends the string field type and provides encoding and decoding capabilities specific to the Base58 format.\n\n### EncoderForeignField\n\nThe EncoderForeignField class extends the Codex's foreign field type to provide specific encoding and decoding functionality for foreign types.\n\n### EncoderModel\n\nThe EncoderModel class provides methods for encoding and decoding a complete model by iterating through the defined fields.\n\n### Encoder\n\nThe Encoder class is the main interface for working with models, defining encoding, and decoding methods based on the schema and options provided.\n\n## Tests\n\nIn order to run the test suite, simply clone the repository and install its dependencies:\n\n```bash\ngit clone https://gitlab.com/frenware/utils/encoder.git\ncd encoder\nnpm install\n```\n\nTo run the tests:\n\n```bash\nnpm test\n```\n\n## Contributing\n\nThank you! Please see our [contributing guidelines](/docs/contributing.md) for details.\n\n## Donations\n\nIf you find this project useful and want to help support further development, please send us some coin. We greatly appreciate any and all contributions. Thank you!\n\n**Bitcoin (BTC):**\n```\n1JUb1yNFH6wjGekRUW6Dfgyg4J4h6wKKdF\n```\n\n**Monero (XMR):**\n```\n46uV2fMZT3EWkBrGUgszJCcbqFqEvqrB4bZBJwsbx7yA8e2WBakXzJSUK8aqT4GoqERzbg4oKT2SiPeCgjzVH6VpSQ5y7KQ\n```\n\n## License\n\n@basd/encoder is [MIT licensed](https://gitlab.com/frenware/utils/encoder/-/blob/master/LICENSE).\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbasedwon%2Fencoder","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbasedwon%2Fencoder","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbasedwon%2Fencoder/lists"}