{"id":27201090,"url":"https://github.com/gregl83/codejs","last_synced_at":"2025-06-27T16:32:03.780Z","repository":{"id":57202336,"uuid":"41977673","full_name":"gregl83/codejs","owner":"gregl83","description":"JavaScript Code class for NodeJS and Browsers","archived":false,"fork":false,"pushed_at":"2015-09-26T18:47:57.000Z","size":248,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-06-14T11:04:30.434Z","etag":null,"topics":[],"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/gregl83.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":"2015-09-05T22:27:49.000Z","updated_at":"2015-11-23T08:53:15.000Z","dependencies_parsed_at":"2022-09-17T12:00:19.515Z","dependency_job_id":null,"html_url":"https://github.com/gregl83/codejs","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"purl":"pkg:github/gregl83/codejs","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gregl83%2Fcodejs","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gregl83%2Fcodejs/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gregl83%2Fcodejs/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gregl83%2Fcodejs/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/gregl83","download_url":"https://codeload.github.com/gregl83/codejs/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gregl83%2Fcodejs/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":261868587,"owners_count":23222255,"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":"2025-04-09T21:55:06.970Z","updated_at":"2025-06-27T16:32:03.758Z","avatar_url":"https://github.com/gregl83.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![Build Status](https://travis-ci.org/gregl83/codejs.svg?branch=master)](https://travis-ci.org/gregl83/codejs)\n[![Coverage Status](https://coveralls.io/repos/gregl83/codejs/badge.svg)](https://coveralls.io/r/gregl83/codejs?branch=master)\n# codejs\n\nJavaScript Code class for NodeJS and Browsers\n\nCodejs provides a robust class factory for compound codes with character separator(s) or delimiter(s).\n\nCreate new code objects or re-build existing ones using data in one of the supported formats (`array`, `string`, or `object`).\n\nFeatures include code segment type checking, default segment values, and regex code validation.\n\n## Requirements\n\n### NodeJS\n\n- NodeJS v0.12.x or higher\n- NPM\n\nSee `./package.json`\n\n### Browser\n\n- Any modern browser with JavaScript enabled\n\n## Installation\n\nSource available on [GitHub](https://github.com/gregl83/codejs) or install module via NPM:\n\n    $ npm install codejs\n    \nSee project root for browser compatible script.\n\n## Usage\n\nAfter requiring Codejs create a Code class using supported options. Create instances from resulting Code class.\n\n```js\nvar Codejs = require('codejs');\n\n// Code class options (see `Options`)\nvar options = {\n  \"separator\": \"-\",\n  \"parts\": [\n    {\n      \"name\": \"alpha\",\n      \"type\": \"string\",\n      \"default\": \"a\",\n      \"separator\": \"-\"\n    },\n    {\n      \"name\": \"beta\",\n      \"type\": \"string\",\n      \"default\": \"b\"\n    }\n  ],\n  \"regex\": \"^([a-z]+)\\-([a-z]+)$\"\n};\n\n// create Code class\nvar Code = new Codejs(options);\n\n// create code class instance\nvar code = new Code(\"a-b\");\n\n// cast code instance in various formats\nvar codeArray = code.toArray();\nvar codeString = code.toString();\nvar codeObject = code.toObject();\n\n// get code parts by name\nvar alpha = code.get('alpha');\nvar beta = code.get('beta');\n\nvar valueUndefined = code.get('undefined');\n```\n\nThe above first creates a new Code class and then creates a instance of that class.\n\nThat's it!\n\n## Options\n\nThe following are the supported options for creating a Code class.\n\n- `separator` character that separates or delimits compound code segments\n- `parts` array of objects used to define each segment in a compound code\n  - `parts.name` name used to distinguish code segment\n  - `parts.type` segment value type `string` or `number`\n  - `parts.default` default segment value (optional)\n  - `parts.separator` character that separates or delimits the following segment (optional: defaults to main separator)\n- `regex` regular expression to test code instance against (optional)\n\n## License\n\nMIT","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgregl83%2Fcodejs","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgregl83%2Fcodejs","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgregl83%2Fcodejs/lists"}