-
Notifications
You must be signed in to change notification settings - Fork 22
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
v6 Roadmap #41
Comments
This is my initial try to implement use std::time::{SystemTime, UNIX_EPOCH};
use rand_core::{RngCore};
use rand_pcg::Pcg32;
const DEFAULT_DICT: &[u8] = b"dx4sqy6W8vX5fJMwa9icNgm7QPl32BhTVEutR1U0rbGeoYAKZSLDjpkInOzHCF";
const MAX_RGN: f32 = u32::MAX as f32;
pub fn random_uuid(uuid_length: i32) -> String {
if uuid_length <= 0 {
panic!("Invalid UUID Length Provided");
}
const DICT_SIZE: usize = DEFAULT_DICT.len();
let mut id = String::with_capacity(uuid_length as usize);
let mut random_fragment_idx: usize;
let mut rng = Pcg32::new(
SystemTime::now()
.duration_since(UNIX_EPOCH)
.expect("Time went backwards").subsec_nanos() as u64,
0xa02bdbf7bb3c0a7
);
let mut rgf: f32;
for _ in 0..uuid_length {
rgf = rng.next_u32() as f32;
random_fragment_idx = (
((rgf / MAX_RGN) * DICT_SIZE as f32) as i32
).rem_euclid(DICT_SIZE as i32) as usize;
id.push(DEFAULT_DICT[random_fragment_idx] as char);
}
println!("> {}", id);
id
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn it_works() {
assert_eq!(random_uuid(1).len(), 1);
assert_eq!(random_uuid(3).len(), 3);
assert_eq!(random_uuid(6).len(), 6);
}
#[test]
#[should_panic(expected = "Invalid UUID Length Provided")]
fn it_panics() {
random_uuid(0);
}
} OUTPUT:
There's two decisions I'd like to highlight:
|
This repository has been fully refactored to be a more traditional Typescript/JS package. The Rust rework has been pushed to 2022 as v5. v4 is now live 🥳 |
Going over the notes regarding Each language should use their default pseudo-random generator (i.e. Math.random() for JS/TS). In order to achieve this we should consider implementing the ability to use your own pseudo-random generator as it has been aluded to on #49 . Then we can use the feature's logic to set the default based on the language you are compiling for. |
As of v4.4.0 (d260860) we can now use the cli as the much shorter command |
We're going to put this one to rest, there has been virtually zero interest from the community for ports of this repo to other languages, we've narrowed our scope at Simply Hexagonal to be creators and maintainers of Typescript libraries, and the features we wanted to see included in short-unique-id such as the CLI binary have been delivered in v5. |
This adopted library is taking wings of its own. In 2020-2021, weekly downloads briefly surpassed the
10k16k milestone. So much so, that large open source projects have trustedshort-unique-id
as generator in mission critical functionalities of production-ready solutions.Over the past 3+ years we have focused on improving quality of the tool specifically for the Javascript (and more recently Typescript) ecosystem.
Now that maturity has been reached, we have begun to hit some walls in regards to progress (#31), mainly due to our choice of being "Deno first". Also there is visible interest (#40) in having this tool ported to other languages.
With the previous in mind, we have done our best in regards of proper research and have committed to once again re-write this library, this time in Rust, in order to be able to compile native modules that can be wrapped-around by easily distributable packages in Javascript/Typescript, WebAssembly, C/C++, Python, etc.
Another significant change we will be introducing is a complete re-brand of short-unique-id, to become:Add
suid
alias to CLIFOR THE RECORD The main reason behind this decision is one of convenience when using the CLI version. At the end of the day, we truly believe that shorter is better!
Note: we are scrapping the idea of re-naming/re-branding since the name and domain have been effective and we have a large enough user-base that we do not want to cause confusion or frustration for existing users.
Minimum Viable Product (MVP)
In order to better serve the existing users of our library and CLI tool we will initially focus on building:
Also we need to figure out the best way to offer the CLI version of this tool through mainstream package managers (both in terms of OS package managers, as in apt-get, homebrew, etc, and programming language specific package managers, as in npm, pip, etc).
This sets an expectation that our core team will be focusing mainly on Javascript/Typescript backwards compatibility. This is not to say that work related to other programming languages will not be done. Any and all help in this regard will be welcome with open arms 🙌🏼
Roadmap
short-unique-id
to be a more traditional Typescript package (a.k.a. less Deno centric)suid
for shorter CLI usagerandom_uuid
function)struct
short-unique-id
with resulting package (Node.js compatible native module) on a fork of a back-end project that uses itshort-unique-id
with resulting package (WebAssembly module) on a fork of a front-end project that uses itshort-unique-id
with resulting package (vanilla JS transpiled function) on a fork of a front-end project that uses itThe text was updated successfully, but these errors were encountered: