npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

marchio-id-uuid

v0.1.1

Published

uuid promise-based generator and validator

Downloads

4

Readme

marchio-id-uuid

uuid promise-based generator and validator

Installation

$ npm init
$ npm install marchio-id-uuid --save

Usage

This package can generate v1 or v4 (default) uuids. It can also validate v1 through v5 uuids.

Generate default v4 uuid

var factory = require("marchio-id-uuid");

factory.create({})
.then(function(obj) {
     return obj.generate();
})
.then(function(result) {
    console.log("ID: ", result);
})
.catch( function(err) { 
    console.error(err); 
});

Generate v1 uuid

var factory = require("marchio-id-uuid");

factory.create({})
.then(function(obj) {
     return obj.generate( { version: "v1" } );
})
.then(function(result) {
    console.log("ID: ", result);
})
.catch( function(err) { 
    console.error(err); 
});

Browser Example

<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <title>marchio-id-uuid example</title>
    <meta name="description" content="marchio-id-uuid example">
    <!-- either cdn should work once tagged and published -->
    <!--
    <script src="https://cdn.rawgit.com/mitchallen/marchio-id-uuid/v0.1.0/dist/marchio-id-uuid.min.js"></script>
    <script src="https://unpkg.com/[email protected]/dist/marchio-id-uuid.min.js"></script>
    -->
    <script src="https://unpkg.com/[email protected]/dist/marchio-id-uuid.min.js"></script>
    <script>
      // Note that the 'window.'' prefix is not needed by most if not all browsers
      // var factory = window.MitchAllen.MarchioIdUuid;
      var factory = MitchAllen.MarchioIdUuid;
      factory.create({})
      .then(function(obj) {
        return obj.generate();
      })
      .then(function(result) {
        console.log("ID: ", result);
      })
      .catch( function(err) { 
        console.error(err); 
      }); 
    </script>
  </head>
  <body>
    <h1>marchio-id-uuid example</h1>
    <p>See JavaScript developer console for output.</p>
  </body>
</html>

References:


Modules

marchio-id-uuid

Module

marchio-id-uuid.package()

Returns the package name

Kind: instance method of marchio-id-uuid

marchio-id-uuid.health()

Health check

Kind: instance method of marchio-id-uuid
Example (Usage Example)

var factory = require("marchio-id-uuid");

factory.create({})
.then(function(obj) {
    return obj.health();
})
.then(function(result) {
    console.log("HEALTH: ", result);
})
.catch( function(err) { 
    console.error(err); 
});

marchio-id-uuid.generate(spec) ⇒ Promise

Generate ID String

Kind: instance method of marchio-id-uuid
Returns: Promise - that resolves to a uuid based on the version

| Param | Type | Description | | --- | --- | --- | | spec | Object | Named parameters object | | [spec.version] | string | Optional version. Valid values: "v1" or "v4" (default) |

Example (Generate default v4 uuid)

var factory = require("marchio-id-uuid");

factory.create({})
.then(function(obj) {
     return obj.generate();
})
.then(function(result) {
    console.log("ID: ", result);
})
.catch( function(err) { 
    console.error(err); 
});

Example (Generate v1 uuid)

var factory = require("marchio-id-uuid");

factory.create({})
.then(function(obj) {
     return obj.generate( { version: "v1" } );
})
.then(function(result) {
    console.log("ID: ", result);
})
.catch( function(err) { 
    console.error(err); 
});

marchio-id-uuid.validate(uuid, [version]) ⇒ Promise

Validate ID String

Kind: instance method of marchio-id-uuid
Returns: Promise - that resolves to a uuid based on the version

| Param | Type | Description | | --- | --- | --- | | uuid | string | a uuid | | [version] | string | Optional version. Default to "v4". Valid values: "v1","v2","v3","v4", or "v5". |

Example (Validate version v4 (default) uuid)

var factory = require("marchio-id-uuid");

factory.create({})
.then(function(obj) {
    return obj.validate('110ec58a-a0f2-4ac4-8393-c866d813b8d1');
})
.then(function(result) {
    console.log( result ? "valid" : "invalid" );
})
.catch( function(err) { 
    console.error(err); 
});

Example (Validate version v1 uuid)

var factory = require("marchio-id-uuid");

factory.create({})
.then(function(obj) {
    return obj.validate(
        '110ec58a-a0f2-1ac4-8393-c866d813b8d1', 
        'v1'
    );
})
.then(function(result) {
    console.log( result ? "valid" : "invalid" );
})
.catch( function(err) { 
    console.error(err); 
});

marchio-id-uuid-factory

Factory module

marchio-id-uuid-factory.create(spec) ⇒ Promise

Factory method It takes one spec parameter that must be an object with named parameters

Kind: static method of marchio-id-uuid-factory
Returns: Promise - that resolves to {module:marchio-id-uuid}

| Param | Type | Description | | --- | --- | --- | | spec | Object | Named parameters object |

Example (Usage example)

 var factory = require("marchio-id-uuid");

 factory.create({})
 .then(function(obj) {
     return obj.health();
 })
 .catch( function(err) { 
     console.error(err); 
 });

marchio-id-uuid-ERROR

Error module

| Param | Type | Description | | --- | --- | --- | | GENERATE_V1_V4_ONLY | string | marchio-id-uuid.generate only supports version values of v1 or v4 | | INVALID_VERSION_PARAMETER | string | marchio-id-uuid.validate - invalid version parameter |

Example (Usage example)

.catch( (err) => {
   if( err.message == _factory.ERROR.MODEL_MUST_BE_DEFINED ) {
       ...
   }
}

Testing

To test, go to the root folder and type (sans $):

$ npm test

Repo(s)


Donations

In lieu of donations you can support this project by buying one of my books: http://amazon.com/author/mitch.allen


Contributing

In lieu of a formal style guide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code.


Version History

Version 0.1.1

  • Updated browser example and documentation

Version 0.1.0

  • initial release