A simple JavaScript Comb Guid Generator.
No guarantees it's perfect!
That being said, we have run tests generating 100,000 ids and not having any duplicates. Guids are generated based on current date/ time and this data is used to create the sequential unique identifiers.
Primary concept of the code was sparked within this discussion http://stackoverflow.com/a/8809472/173949.
Pretty simple implementation, simply import the module, and you're off an running!
npm install jscombguid
And cheap node example usage;
const comb = require("jscombguid");
console.log(comb.generateCombGuid());
The library source includes some straight forward mocha tests and a duplicate check test which executes 10,000 cycles of guid generation check for duplicates being created. These tests sre located in the test/index.test.js file.
To execute the tests fire off the following line of code in your fav tool.
npm run test
.nyc_output directory will have the coverage reports outputted to the coverage directory.
To view this report, and you have http-server
, a handy basic insta web server, you can instal it and simply run;
Total overkill for this small package, but a good example of code coverage reporting.
npm i -g http-server
Then fire it up and run it post the test execution;
http-server ./coverage/lcov-report/
and check out the server site at http://127.0.0.1:8080
- momentjs - used in working with date time to generate the combs (direct dependency)
- mocha - unsed in the unit testing of the simple function
- instabul - used to validate test coverage and reporting
- eslint - used for housekeeping and sanity
- babel - used to bust down the code, we aren't doing anything that would fully constitute this however
After cloning the repo run;
npm install
From that point, there are 3 possible scripts to run;
- build - runs lint, tests, then babel
- lint - runs eslint
- test - runs the mocha tests
To start, just run a build;
npm run build
And away you go. This is an overblown project repo, with probably more going on than necessary, however, it is a proof of concept on all aspects of npm package development. That being said, there are a few references which are worth mentioning here;
- Developing and Publishing an NPM Package
- BadgeFury
- How to Build and Publish an NPM Package
- Automate your NPM publish with GitHub Actions
Please read CONTRIBUTING.md for details on our code of conduct, and the process for submitting pull requests to us.
We use SemVer for versioning. For the versions available, see the tags on this repository.
This project is licensed under the MIT License - see the LICENSE.md file for details
- Big thanks to @thetinomen he refactored out the sophmoric code...