# define-uniqueid

> uniqueId property generator for arbitrary object types

Latest version **0.0.6** (published 2015-06-16) · MIT license · 0 weekly downloads

## Install

```sh
npm install define-uniqueid
pnpm add define-uniqueid
yarn add define-uniqueid
bun add define-uniqueid
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.6 |
| Published | 2015-06-16 |
| First published | 2015-06-02 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Dickson Tam |
| Maintainers | dicksont |
| Keywords | uniqueid, unique, id, property, object, html, element, browser |

## Links

- npm: https://www.npmjs.com/package/define-uniqueid
- Repository: https://github.com/dicksont/define-uniqueid
- Homepage: https://github.com/dicksont/define-uniqueid#readme
- Issues: https://github.com/dicksont/define-uniqueid/issues
- npm.io page: https://npm.io/package/define-uniqueid

## Alternatives

- [@sindresorhus/slugify](https://npm.io/package/@sindresorhus/slugify.md) — 3.7M weekly downloads
- [solid-js](https://npm.io/package/solid-js.md) — 2.7M weekly downloads
- [expo-glass-effect](https://npm.io/package/expo-glass-effect.md) — 2.5M weekly downloads
- [nanoassert](https://npm.io/package/nanoassert.md) — 780.8K weekly downloads
- [@ffmpeg/ffmpeg](https://npm.io/package/@ffmpeg/ffmpeg.md) — 529.5K weekly downloads

## Recent versions

- 0.0.6 (latest) — 2015-06-16
- 0.0.4 — 2015-06-05
- 0.0.3 — 2015-06-02
- 0.0.0 — 2015-06-02

## README

[![Build Status](https://travis-ci.org/dicksont/define-uniqueid.svg?branch=master)](https://travis-ci.org/dicksont/define-uniqueid) [![npm version](https://badge.fury.io/js/define-uniqueid.svg)](http://badge.fury.io/js/define-uniqueid) [![Bower version](https://badge.fury.io/bo/define-uniqueid.svg)](http://badge.fury.io/bo/define-uniqueid)

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](LICENSE)

## Usage

### DOM / Chrome / Safari / Firefox / Opera

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

### CommonJS / Node
```javascript

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

```

### AMD / Require.js

```javascript
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.

```javascript
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.

```javascript
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:

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


Let me know if your particular browser has issues.

---
_Source: https://npm.io/package/define-uniqueid · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
