GithubHelp home page GithubHelp logo

danakt / uuid-by-string Goto Github PK

View Code? Open in Web Editor NEW
64.0 2.0 11.0 529 KB

Generates the RFC-4122 Name-Based UUID

License: MIT License

JavaScript 100.00%
uuid guid uuid-by-string hash md5 sha-1 rfc-4122 v3 v5

uuid-by-string's Introduction

uuid-by-string NPM Downloads

Generates the RFC-4122 Name-Based UUID. Supports 3 and 5 versions of UUID.

Installation

# via NPM
npm install uuid-by-string

# or Yarn
yarn add uuid-by-string

Usage

The package has only one default exported method. Method receives any string and returns generated hash

const getUuid = require('uuid-by-string');

const uuidHash = getUuid('Hello world!');
// d3486ae9-136e-5856-bc42-212385ea7970

The string Hello world! will always returns d3486ae9-136e-5856-bc42-212385ea7970.

You can specify the UUID version. Available versions is 3 and 5 according to RFC-4122. The version is responsible for the hashing algorithm: version 3 uses MD5, and version 5 uses SHA-1. SHA-1 used by default if version is not specified.

const uuidV3Hash = getUuid('Hello world!', 3);
// 86fb269d-190d-3c85-b6e0-468ceca42a20

const uuidV5Hash = getUuid('Hello world!', 5);
// d3486ae9-136e-5856-bc42-212385ea7970

API

getUuid(name [, version]);

getUuid(name [, namespace, version]);

  • name — hashing target
  • namespace Optional — UUID namespace
  • version Optional — 3 or 5, version of UUID

License

MIT licensed

uuid-by-string's People

Contributors

danakt avatar danaktsaushkin avatar dependabot[bot] avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

uuid-by-string's Issues

Incorrect UUID generated - RFC 4122

Hello

I am trying to generate the UUID from a string. I have done the same in Android and Python. On both the platforms the same UUID is generated, but in this library the generated one different (Only the partial part is different).

The outputs:

Android:
12f01aa4-5090-3f83-b823-7e7cb43246e7

Python3:
12f01aa4-5090-3f83-b823-7e7cb43246e7

Nodejs (This library):
12f01aa4-5090-1f83-b823-7e7cb43246e7

As you can see, the third segment (3f83 != 1f83) is different in generated value. Please let me know if this is an issue in the library.

Code used:
getUuid("9239107d-259f-4cf8-b62d-0964b680ab08", 3)

Reverse UUID

Hi @danakt - I understand that this module always returns the same UUID for a particular input string.

I had a quick question - is it possible to reverse the generated UUID to get back the original string?

Much thanks,
Mahendra

RFC-4122 specifies using lowercase

I'd like to point out that according to the spec,

The hexadecimal values “a” through “f” are output as lower case characters and are case insensitive on input.

So this tool is technically not quite compliant, although I don't know how much practical consequence that is since tools that read the id are required to ignore the case.

It's probably a one-line change here, but of course the documentation and tests would also need to change to match.

Can't find variable: Buffer

Hi,

I found an issue with the following versions:
React: "16.8.3"
React-Native: "0.59.2"
uuid-by-string: "^2.1.0"

Issue:
in /src/lib.js, line 74, ...new Buffer... returns the error. adding import { Buffer, } from 'buffer'; to the top of the file and as a dependency in the package.json file, will solve this issue.

Please let me know if this can be fixed in the next version or if I need to handle it on my own?

Thanks,
-Mazen

Several characters got the same uuid

const getUuid = require('uuid-by-string');

const uuidHash = getUuid("好");
console.log(uuidHash)
const uuidHash2 = getUuid("白");
console.log(uuidHash2)

result:

c2b7df62-01fd-5336-a399-091f0a29550d
c2b7df62-01fd-5336-a399-091f0a29550d

What breaking changes were introduced in 4.0.0?

I cannot find a changelog, version 4 has not even a tag or a release, the PR for version 4 has no info.

Where can we find info about what changed in version 4 so we can update?
Please add some documentation about this.

Consider using `crypto` to generate md5/sha1 hashes

First of all, thank you for the library!

Have you considered using crypto.createHash to create md5/sha1 hashes instead of the js dependencies?

This would allow us to use your libraries in non-node runtimes like cloudflare workers (currently it fails because js-md5 contains eval which is usually a no-no for security reasons).

I created a temporary fork and replaced the dependencies for the native crypto and all tests passed succesfully, can create a PR if you agree.

Thanks!

Module not es5 compatible

Hi,

please provide your package es5 compatible. For example the index.js files uses object destructuring, an es6 feature:
const { md5Hash, stringToCharBuffer, sha1Hash, hashToUuid, concatBuffers } = require('./lib')

Best regards, Florian

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.