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

define-uniqueid

v0.0.6

Published

uniqueId property generator for arbitrary object types

Downloads

12

Readme

Build Status npm version Bower version

Define-uniqueid is a sequential, unique id generator that can be attached to arbitrary object prototypes. We would like to think that the following are its advantages over the alternatives:

  • Portability - It works across all the different JavaScript module formats.
  • Efficiency - uniqueId's are generated lazily, on-demand. This saves CPU cycles and memory space.
  • Customizability - You can add uniqueId to more specialized prototypes other than Object. You can customize the uniqueId by passing in your own formatting function, in the defineUniqueId call.

License

Usage

DOM / Chrome / Safari / Firefox / Opera

<script src="/bower_components/define-uniqueid/uniqid.js"></script>
<script>
var undefineFx = defineUniqueId(HTMLElement);
var div = document.createElement('div');
div.uniqueId;
</script>

CommonJS / Node


var defineUniqueId = require('define-uniqueid');
var undefineFx = defineUniqueId(Object);
({}).uniqueId;

AMD / Require.js

requirejs.config({
  baseUrl: '.',
  paths: {
    'define-uniqueid': './uniqid'
  }
});

requirejs(['define-uniqueid'], function(defineUniqueId) {
  var undefineFx = defineUniqueId(Object);
  ({}).uniqueId;
});

Options

An object containing options can be passed in the defineUniqueId call.

defineUniqueId(Object, {
  configurable: true,
  enumerable: true,
  redefine: true,
  format: function(id) { return 'obj-' + id; }
})

opts.property

Default: 'uniqueId'

Customize the name of the unique ID property.

opts.format

Customize the uniqueId by passing in your own formatting function.

defineUniqueId(Object, { format: function(id) { return 'obj-' + id; })

opts.configurable

Default: false

False means that the uniqueId property cannot be redefined. True means that the property can be redefined in both the object and the prototype object.

opts.enumerable

Default: false

True means that the uniqueId property can be enumerated.

opts.redefine

Default: false

By default, an error is thrown when the Object prototype already has a defineUniqueId property. Set this to true, to suppress these errors and to allow this property to be redefined.

Browser Support

This library has been tested with good success on a variety of browsers including :

  • Google Nexus 7 : Android 4.1
  • Samsung Galaxy S3 : Android 4.1
  • Chrome 36.0 : Windows 8.1
  • Firefox 30.0 : Windows 8.1
  • Safari 7.0 : OS X Mavericks

Internet Explorer is a confirmed exception. You should be able to work around this, by checking for the the presence of IE's doppelganger uniqueID first. Something like this:

var uniqueId = div.uniqueID || div.uniqueId;

Let me know if your particular browser has issues.