diff --git a/.cz-config.js b/.cz-config.js new file mode 100644 index 0000000..69b0f3d --- /dev/null +++ b/.cz-config.js @@ -0,0 +1,76 @@ +module.exports = { + types: [ + { + value: 'build', + name: 'build: Changes that affect the build system configuration, package scripts, or dev dependencies (i.e. adds/remove/modify/update)' + }, + { + value: 'ci', + name: 'ci: Changes to CI configuration files and scripts (e.g. release configs, YAML scripts)' + }, + { value: 'docs', name: 'docs: Documentation only changes' }, + { value: 'feat', name: 'feat: Adds a new feature' }, + { + value: 'fix', + name: 'fix: Fixes a bug in an existing feature. Also used for non-dev dependency updates.' + }, + { + value: 'perf', + name: 'perf: A code change that improves performance' + }, + { + value: 'refactor', + name: 'refactor: A code change that neither fixes a bug nor adds a feature' + }, + { value: 'revert', name: 'revert: Revert to a commit' }, + { value: 'test', name: 'test: Add missing tests or correct existing tests' } + ], + + scopes: [ + { name: 'api' }, + { name: 'contributing' }, + { name: 'license' }, + { name: 'readme' }, + { name: 'security' } + ], + + allowTicketNumber: false, + isTicketNumberRequired: false, + ticketNumberPrefix: 'TICKET-', + ticketNumberRegExp: '\\d{1,5}', + + // it needs to match the value for field type. Eg.: 'fix' + /* + scopeOverrides: { + fix: [ + {name: 'merge'}, + {name: 'style'}, + {name: 'e2eTest'}, + {name: 'unitTest'} + ] + }, + */ + // override the messages, defaults are as follows + messages: { + type: "Select the type of change that you're committing:", + scope: '\nDenote the SCOPE of this change (optional):', + // used if allowCustomScopes is true + customScope: 'Denote the SCOPE of this change:', + subject: 'Write a SHORT, IMPERATIVE tense description of the change:\n', + body: 'Provide a LONGER description of the change (optional). Use "|" to break new line:\n', + breaking: 'List any BREAKING CHANGES (optional):\n', + footer: 'List any ISSUES CLOSED by this change (optional). E.g.: #31, #34:\n', + confirmCommit: 'Are you sure you want to proceed with the commit above?' + }, + + allowCustomScopes: true, + allowBreakingChanges: ['feat', 'fix'], + // skip any questions you want + // skipQuestions: ['body'], + + // limit subject length + subjectLimit: 100, + // breaklineChar: '|', // It is supported for fields body and footer. + footerPrefix: 'Resolves:' + // askForBreakingChangeFirst : true, // default is false +} diff --git a/.eslintignore b/.eslintignore new file mode 100644 index 0000000..3091757 --- /dev/null +++ b/.eslintignore @@ -0,0 +1,2 @@ +node_modules +coverage \ No newline at end of file diff --git a/.github/ISSUE_TEMPLATE/bug_report.yml b/.github/ISSUE_TEMPLATE/bug_report.yml index d93f474..a19ca08 100644 --- a/.github/ISSUE_TEMPLATE/bug_report.yml +++ b/.github/ISSUE_TEMPLATE/bug_report.yml @@ -54,6 +54,7 @@ body: - 14 - 16 - 17 + - 18 validations: required: true - type: textarea diff --git a/.github/SECURITY.md b/.github/SECURITY.md index cb07c5d..39aaa1b 100644 --- a/.github/SECURITY.md +++ b/.github/SECURITY.md @@ -24,4 +24,4 @@ This information will help me triage your report more quickly. ## Response -Once the issue has been fixed, the [CI/CD process](https://github.com/M-Scott-Lassiter/Alphanumeric-Encoder/blob/main/CONTRIBUTING.md) will trigger a new build. Once that build releases, I will make a [security advisory](https://github.com/M-Scott-Lassiter/Alphanumeric-Encoder/security/advisories). +Once the issue has been fixed, the [CI/CD process](https://github.com/M-Scott-Lassiter/Alphanumeric-Encoder/blob/main/CONTRIBUTING.md#continuous-integrationcontinuous-deployment-setup) will trigger a new build. Once that build releases, I will make a [security advisory](https://github.com/M-Scott-Lassiter/Alphanumeric-Encoder/security/advisories). diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index e7e9545..e2a8bcc 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -5,7 +5,7 @@ name: CI Tests on: push: - branches: [main, next] + branches: [main] pull_request: branches: [main] diff --git a/.husky/pre-commit b/.husky/pre-commit new file mode 100644 index 0000000..c37466e --- /dev/null +++ b/.husky/pre-commit @@ -0,0 +1,4 @@ +#!/bin/sh +. "$(dirname "$0")/_/husky.sh" + +npx lint-staged \ No newline at end of file diff --git a/.lintstagedrc b/.lintstagedrc new file mode 100644 index 0000000..3b0477c --- /dev/null +++ b/.lintstagedrc @@ -0,0 +1,4 @@ +{ + "**/*.{js,ts}": ["npm run lint"], + "**/*.{js,jsx,ts,tsx,json,html,css,scss,md,yml}": ["npm run format"] +} \ No newline at end of file diff --git a/API.md b/API.md index e55bff6..ee44fd3 100644 --- a/API.md +++ b/API.md @@ -4,10 +4,14 @@ - [AlphanumericEncoder][1] - [dictionary][2] - - [dictionary][3] - - [Parameters][4] + - [Parameters][3] + - [Examples][4] - [encode][5] - [Parameters][6] + - [Examples][7] + - [decode][8] + - [Parameters][9] + - [Examples][10] ## AlphanumericEncoder @@ -15,32 +19,116 @@ A class for encoding and decoding base 10 integers to a custom alphanumeric base ### dictionary -Returns the current dictionary. Default is the English alphabet in order: 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' +Set or get the current dictionary. -Returns **[string][7]** The current dictionary in use - -### dictionary +Default is the English alphabet in order: `ABCDEFGHIJKLMNOPQRSTUVWXYZ` #### Parameters -- `newDictionary` **[string][7]** String of unique characters in order for the new dictionary +- `newDictionary` **[string][11]** (If setting) String of unique letters and numbers, in order, for the new dictionary + +#### Examples + +```javascript +console.log(AlphanumericEncoder.dictionary) // 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' + +AlphanumericEncoder.dictionary = 'ABCD' +console.log(AlphanumericEncoder.dictionary) // 'ABCD' + +AlphanumericEncoder.dictionary = 'ABCDA' // Throws error because the letter 'A' is repeated +``` + +Returns **[string][11]** (If used as getter) The current dictionary in use ### encode Takes any number and converts it into a base (dictionary length) letter combo. -It converts any numerical entry into a positive integer. #### Parameters -- `number` **[number][8]** Base 10 number. Must be positive and non-zero. Decimals values are truncated. +- `integerToEncode` **[number][12]** Base 10 integer. If passed a non-integer number, decimal values are truncated. + Passing zero, negative numbers, or non-numbers will return `undefined`. + +#### Examples + +```javascript +const encoder = new AlphanumericEncoder() +console.log(encoder.encode(5)) // 'E' +console.log(encoder.encode(48)) // 'AV' +console.log(encoder.encode(733)) // 'ABE' +``` + +```javascript +const encoder = new AlphanumericEncoder() +encoder.dictionary = 'ABCD' +console.log(encoder.encode(5)) // 'AA' +console.log(encoder.encode(48)) // 'BCD' +console.log(encoder.encode(733)) // 'BCACA' +``` + +```javascript +const encoder = new AlphanumericEncoder() +encoder.dictionary = 'DCBA' +console.log(encoder.encode(5)) // 'DD' +console.log(encoder.encode(48)) // 'CBA' +console.log(encoder.encode(733)) // 'CBDBD' +``` + +```javascript +const encoder = new AlphanumericEncoder() +encoder.dictionary = 'ABC123' +console.log(encoder.encode(5)) // '2' +console.log(encoder.encode(48)) // 'AA3' +console.log(encoder.encode(733)) // 'CBBA' +``` + +Returns **[string][11]** Dictionary encoded value + +### decode + +Takes any string and converts it into a base 10 integer based on the defined dictionary. + +#### Parameters + +- `stringToDecode` **[string][11]** If passed a non-integer number, decimal values are truncated. + Passing an empty string, `null`, or `undefined` will return `undefined`. + +#### Examples + +```javascript +const encoder = new AlphanumericEncoder() +console.log(encoder.decode('A')) // 1 +console.log(encoder.decode('AC')) // 29 +console.log(encoder.decode('ANE')) // 1045 +``` + +```javascript +const encoder = new AlphanumericEncoder() +console.log(encoder.decode('a')) // undefined +console.log(encoder.decode(123)) // undefined +console.log(encoder.decode('A?')) // undefined +``` + +```javascript +const encoder = new AlphanumericEncoder() +encoder.dictionary = 'ABCD' +console.log(encoder.decode('A')) // 1 +console.log(encoder.decode('AC')) // 7 +console.log(encoder.decode('ADBAC')) // 551 +console.log(encoder.decode('ANE')) // undefined +``` -Returns **[string][7]** Dictionary encoded value +Returns **[number][12]** Positive integer representation. If one of the characters is not present in the dictionary, it will return `undefined`. [1]: #alphanumericencoder [2]: #dictionary -[3]: #dictionary-1 -[4]: #parameters +[3]: #parameters +[4]: #examples [5]: #encode [6]: #parameters-1 -[7]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String -[8]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number +[7]: #examples-1 +[8]: #decode +[9]: #parameters-2 +[10]: #examples-2 +[11]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String +[12]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number diff --git a/CHANGELOG.md b/CHANGELOG.md index 9586ada..7f09366 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,30 +1,27 @@ ## [1.1.0](https://github.com/M-Scott-Lassiter/Alphanumeric-Encoder/compare/v1.0.5...v1.1.0) (2022-04-26) - ### :building_construction: Build Changes -* add Airbnb style guide to the ESLint configuration ([c30eac9](https://github.com/M-Scott-Lassiter/Alphanumeric-Encoder/commit/c30eac9ce98e3f564343ac5a83a1969e14e82430)), closes [#20](https://github.com/M-Scott-Lassiter/Alphanumeric-Encoder/issues/20) -* add Prettier for code formatting ([398dc54](https://github.com/M-Scott-Lassiter/Alphanumeric-Encoder/commit/398dc5416133df3b252fa429bf040293295955da)), closes [#21](https://github.com/M-Scott-Lassiter/Alphanumeric-Encoder/issues/21) - +- add Airbnb style guide to the ESLint configuration ([c30eac9](https://github.com/M-Scott-Lassiter/Alphanumeric-Encoder/commit/c30eac9ce98e3f564343ac5a83a1969e14e82430)), closes [#20](https://github.com/M-Scott-Lassiter/Alphanumeric-Encoder/issues/20) +- add Prettier for code formatting ([398dc54](https://github.com/M-Scott-Lassiter/Alphanumeric-Encoder/commit/398dc5416133df3b252fa429bf040293295955da)), closes [#21](https://github.com/M-Scott-Lassiter/Alphanumeric-Encoder/issues/21) ### :lady_beetle: Bug Fixes -* remove unnecessary files from distribution ([a40e6be](https://github.com/M-Scott-Lassiter/Alphanumeric-Encoder/commit/a40e6beab4d9d2bb076acfa7b08e85d2d957ec0a)), closes [#22](https://github.com/M-Scott-Lassiter/Alphanumeric-Encoder/issues/22) - +- remove unnecessary files from distribution ([a40e6be](https://github.com/M-Scott-Lassiter/Alphanumeric-Encoder/commit/a40e6beab4d9d2bb076acfa7b08e85d2d957ec0a)), closes [#22](https://github.com/M-Scott-Lassiter/Alphanumeric-Encoder/issues/22) ### :gift: Feature Changes -* add engine support for Node v10.x ([a04bd74](https://github.com/M-Scott-Lassiter/Alphanumeric-Encoder/commit/a04bd747b5e54c5c392ee308f9ceeeb4bfe27cc8)), closes [#23](https://github.com/M-Scott-Lassiter/Alphanumeric-Encoder/issues/23) -* add support for Node v18.x ([6056d72](https://github.com/M-Scott-Lassiter/Alphanumeric-Encoder/commit/6056d72a9d81c1db9bdaee6f4d06eda6af45e75b)), closes [#23](https://github.com/M-Scott-Lassiter/Alphanumeric-Encoder/issues/23) +- add engine support for Node v10.x ([a04bd74](https://github.com/M-Scott-Lassiter/Alphanumeric-Encoder/commit/a04bd747b5e54c5c392ee308f9ceeeb4bfe27cc8)), closes [#23](https://github.com/M-Scott-Lassiter/Alphanumeric-Encoder/issues/23) +- add support for Node v18.x ([6056d72](https://github.com/M-Scott-Lassiter/Alphanumeric-Encoder/commit/6056d72a9d81c1db9bdaee6f4d06eda6af45e75b)), closes [#23](https://github.com/M-Scott-Lassiter/Alphanumeric-Encoder/issues/23) -### [1.0.5](https://github.com/M-Scott-Lassiter/Alphanumeric-Encoder/compare/v1.0.4...v1.0.5) (2022-04-24) +## [1.0.5](https://github.com/M-Scott-Lassiter/Alphanumeric-Encoder/compare/v1.0.4...v1.0.5) (2022-04-24) ### :building_construction: Build Changes - add a build script to the package ([51016bf](https://github.com/M-Scott-Lassiter/Alphanumeric-Encoder/commit/51016bf462f7e851635a38d7b2193b9bbfc0b0c2)), closes [#18](https://github.com/M-Scott-Lassiter/Alphanumeric-Encoder/issues/18) - update the CD scripts to run `build` ([15f8d48](https://github.com/M-Scott-Lassiter/Alphanumeric-Encoder/commit/15f8d483f29bf3b5afdd9810b6d03a7f70c98f02)), closes [#18](https://github.com/M-Scott-Lassiter/Alphanumeric-Encoder/issues/18) -### [1.0.4](https://github.com/M-Scott-Lassiter/Alphanumeric-Encoder/compare/v1.0.3...v1.0.4) (2022-04-24) +## [1.0.4](https://github.com/M-Scott-Lassiter/Alphanumeric-Encoder/compare/v1.0.3...v1.0.4) (2022-04-24) ### :building_construction: Build Changes diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 5e93f69..d71f84a 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -2,11 +2,10 @@
- - +[![Commitizen friendly](https://img.shields.io/badge/commitizen-friendly-brightgreen.svg)](http://commitizen.github.io/cz-cli/) [![Linting: ESLint](https://img.shields.io/badge/eslint-4B32C3?logo=eslint&logoColor=white)](https://github.com/eslint/eslint) [![Code format: Prettier](https://img.shields.io/badge/prettier-F7B93E.svg?style=flat-square&logo=prettier&logoColor=black)](https://github.com/prettier/prettier) -[![Style Guide: Air b n b](https://img.shields.io/badge/code_style-airbnb-FF5A5F?logo=airbnb&logoColor=FF5A5F)](https://github.com/airbnb/javascript) +[![Style Guide: Airbnb](https://img.shields.io/badge/code_style-airbnb-FF5A5F?logo=airbnb&logoColor=FF5A5F)](https://github.com/airbnb/javascript) [![Testing: Jest](https://img.shields.io/badge/jest-C21325?logo=jest&logoColor=white)](https://github.com/facebook/jest) [![semantic-release: angular](https://img.shields.io/badge/semantic--release-angular-e10079?logo=semantic-release)](https://github.com/semantic-release/semantic-release) @@ -35,8 +34,9 @@ Before contributing, please take a moment to read through this document. This gu - [Testing](#testing) - [Documentation](#documentation) - [Commits](#commits) - - [Reverts](#reverts) - [Commit Header Format](#commit-header-format) + - [Commit Body Format](#commit-body-format) + - [Commit Footer Format](#commit-footer-format) - [Versioning Triggers](#versioning-triggers) @@ -61,7 +61,7 @@ _For security related issues, see the [security policy](https://github.com/M-Sco ### Improve Documentation -Open a new issue [here](https://github.com/M-Scott-Lassiter/Alphanumeric-Encoder/issues). +Open a new issue [here](https://github.com/M-Scott-Lassiter/Alphanumeric-Encoder/issues/new/choose). ### Submit a Pull Request @@ -89,7 +89,7 @@ npm install # or `yarn install` ### Project Structure -A single file, `index.js` contains all functionality. `index.test.js` contains the test suite. Before submitting changes, run the build script locally then commit: +A single file, `index.js` contains all functionality. Before submitting changes, run the build script locally then commit: ``` npm run build @@ -113,7 +113,7 @@ npm run format ### Testing -This project uses Jest for testing. To run the test suite, run: +This project uses Jest for testing. `index.test.js` contains the test suite. To execute it, run: ``` npm run test @@ -157,17 +157,12 @@ Each commit message consists of a **header**, a **body**, and a **footer**.