universally-unique-identifier
v0.0.1
Published
Generate version 4 compatible UUIDs
Downloads
2
Readme
Universally Unique Identifier
Extends String
to build UUIDs that are truly unique for current scope
Requirements
NodeJS dependencies may be installed via NPM...
npm install
Notice as of version 0.0.1
NodeJS dependencies are for development only, ie. if utilizing this project within other applications or as a submodule, then no dependencies are required.
Quick Start
NodeJS projects may use npm
to install universally-unique-identifier
as a dependency...
npm install universally-unique-identifier
... or as a development dependency via --save-dev
command-line flag...
npm install --save-dev universally-unique-identifier
... Check NodeJS Examples for details on how to import this project within your own source code.
Web projects, such has those hosted on GitHub Pages, are encouraged to utilize Git Submodules instead...
Bash Variables
_module_name='universally-unique-identifier'
_module_https_url="https://github.com/javascript-utilities/universally-unique-identifier.git"
_module_base_dir='assets/javascript/modules'
_module_path="${_module_base_dir}/${_module_name}"
Bash Submodule Commands
cd "<your-git-project-path>"
git checkout gh-pages
mkdir -vp "${_module_base_dir}"
git submodule add -b main\
--name "${_module_name}"\
"${_module_https_url}"\
"${_module_path}"
Your ReadMe File
Suggested additions for your ReadMe.md
file so everyone has a good time with submodules
Clone with the following to avoid incomplete downloads
git clone --recurse-submodules <url-for-your-project>
Update/upgrade submodules via
git submodule update --init --merge --recursive
Commit and Push
git add .gitmodules
git add "${_module_path}"
## Add any changed files too
git commit -F- <<'EOF'
:heavy_plus_sign: Adds `javascript-utilities/universally-unique-identifier#1` submodule
**Additions**
- `.gitmodules`, tracks submodules AKA Git within Git _fanciness_
- `README.md`, updates installation and updating guidance
- `_modules_/universally-unique-identifier`, Extends `String` to build UUIDs that are truly unique for current scope
EOF
git push origin gh-pages
:tada: Excellent :tada: your project is now ready to begin unitizing code from this repository!
Usage
Examples on how to utilize this repository
NodeJS Examples
#!/usr/bin/env node
'use strict';
const { Universally_Unique_Identifier } = require('universally-unique-identifier');
const uuid_one = new Universally_Unique_Identifier();
const uuid_two = new Universally_Unique_Identifier();
console.log(`uuid_one -> ${uuid_one}`);
//> uuid_one -> 5340a411-e6f7-4afa-8b99-d3f0f6688a5e
console.log(`uuid_two -> ${uuid_two}`);
//> uuid_two -> c271d4f0-9b47-4736-a787-7ba6c4932661
console.assert(uuid_one.toString() !== uuid_two.toString());
Web Application Example
index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Example Universally Unique Identifier</title>
<script src="/assets/javascript/universally-unique-identifier.js" defer></script>
<script src="/assets/javascript/index.js" defer></script>
<style>
#text__output {
resize: horizontal;
min-width: 20em;
text-align: center;
}
</style>
</head>
<body>
<input id="text__output" type="text" readonly>
<br>
<input id="button__new_uuid" type="button" value="Click for UUID">
</body>
</html>
/assets/javascript/index.js
'use strict';
window.addEventListener('load', () => {
const text__output = document.getElementById('text__output');
const button__new_uuid = document.getElementById('button__new_uuid');
button__new_uuid.addEventListener('click', () => {
const uuid = new Universally_Unique_Identifier();
text__output.value = uuid.toString();
});
});
API
Documentation for classes, methods, paramaters, and custom types/data-structures
Class Universally_Unique_Identifier
Extends String
to build UUIDs that are truly unique for current scope
Example
const uuid_one = new Universally_Unique_Identifier();
const uuid_two = new Universally_Unique_Identifier();
console.log(`uuid_one -> ${uuid_one}`);
//> uuid_one -> 5340a411-e6f7-4afa-8b99-d3f0f6688a5e
console.log(`uuid_two -> ${uuid_two}`);
//> uuid_two -> c271d4f0-9b47-4736-a787-7ba6c4932661
console.assert(uuid_one.toString() !== uuid_two.toString());
Static Property Universally_Unique_Identifier.generated_uuids
Scope storage of all UUIDs generated by class instances
Method Universally_Unique_Identifier.constructor
Gross hack of super
call with closure-like arrow function
Notes
super
cannot referencethis
super
must proceed anythis.__prop__
assignments
Notes
Warning due to how the Universally_Unique_Identifier
class guaranties that IDs are unique for a given scope, it may run slower as more UUIDs are generated.
This repository may not be feature complete and/or fully functional, Pull Requests that add features or fix bugs are certainly welcomed.
Contributing
Options for contributing to universally-unique-identifier and javascript-utilities
Forking
Start making a Fork of this repository to an account that you have write permissions for.
- Add remote for fork URL. The URL syntax is
[email protected]:<NAME>/<REPO>.git
...
cd ~/git/hub/javascript-utilities/universally-unique-identifier
git remote add fork [email protected]:<NAME>/universally-unique-identifier.git
- Commit your changes and push to your fork, eg. to fix an issue...
cd ~/git/hub/javascript-utilities/universally-unique-identifier
git commit -F- <<'EOF'
:bug: Fixes #42 Issue
**Edits**
- `<SCRIPT-NAME>` script, fixes some bug reported in issue
EOF
git push fork main
Note, the
-u
option may be used to setfork
as the default remote, eg.git push -u fork main
however, this will also default thefork
remote for pulling from too! Meaning that pulling updates fromorigin
must be done explicitly, eg.git pull origin main
- Then on GitHub submit a Pull Request through the Web-UI, the URL syntax is
https://github.com/<NAME>/<REPO>/pull/new/<BRANCH>
Note; to decrease the chances of your Pull Request needing modifications before being accepted, please check the dot-github repository for detailed contributing guidelines.
Sponsor
Thanks for even considering it!
Via Liberapay you may on a repeating basis.
Regardless of if you're able to financially support projects such as universally-unique-identifier that javascript-utilities maintains, please consider sharing projects that are useful with others, because one of the goals of maintaining Open Source repositories is to provide value to the community.
Attribution
Wikipidea -- Universally unique identifier -- Version 4 (random)
Web Masters -- How do I open the JavaScript console in different browsers?
License
Extends `String` to build UUIDs that are truly unique for current scope
Copyright (C) 2021 S0AndS0
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published
by the Free Software Foundation, version 3 of the License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
For further details review full length version of AGPL-3.0 License.