Socket
Socket
Sign inDemoInstall

define-uniqueid

Package Overview
Dependencies
0
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.0.4 to 0.0.6

test/test.js

2

bower.json
{
"name": "define-uniqueid",
"version": "0.0.4",
"version": "0.0.6",
"homepage": "https://github.com/dicksont/define-uniqueid",

@@ -5,0 +5,0 @@ "authors": [

{
"name": "define-uniqueid",
"version": "0.0.4",
"version": "0.0.6",
"description": "uniqueId property generator for arbitrary object types",

@@ -13,3 +13,3 @@ "main": "uniqid.js",

"scripts": {
"test": "mocha spec/spec.js"
"test": "mocha test/test.js"
},

@@ -16,0 +16,0 @@ "repository": {

@@ -13,3 +13,3 @@ [![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)

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

@@ -56,3 +56,3 @@ ```html

```javascript
defineUniqueId('Object', {
defineUniqueId(Object, {
configurable: true,

@@ -65,2 +65,8 @@ enumerable: true,

### opts.property
Default: *'uniqueId'*
Customize the name of the unique ID property.
### opts.format

@@ -70,3 +76,3 @@ Customize the *uniqueId* by passing in your own formatting function.

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

@@ -94,1 +100,20 @@

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.

@@ -40,2 +40,3 @@ /*

opts.enumerable = opts.enumerable || false;
opts.property = opts.property || 'uniqueId';

@@ -46,10 +47,11 @@ if (typeof(opts.format) != 'undefined' && typeof(opts.format) != 'function') {

if (ctor.prototype.hasOwnProperty('uniqueId') && !opts.redefine) {
throw new Error('Object prototype already has uniqueId property defined.');
if (ctor.prototype.hasOwnProperty(opts.property) && !opts.redefine) {
throw new Error('Object prototype already has ' + opts.property + ' property defined.');
}
Object.defineProperty(ctor.prototype, 'uniqueId', {
Object.defineProperty(ctor.prototype, opts.property, {
get: function() {
Object.defineProperty(this, 'uniqueId', {
value: (opts.format)? opts.format(generateId()) : generateId(),
var myId = (opts.format)? opts.format(generateId()) : generateId();
Object.defineProperty(this, opts.property, {
value: myId,
writable: false,

@@ -60,3 +62,3 @@ enumerable: opts.enumerable,

return this.uniqueId;
return myId;
},

@@ -69,3 +71,3 @@ enumerable: opts.enumerable,

function undefine() {
delete ctor.prototype['uniqueId'];
delete ctor.prototype[opts.property];
}

@@ -72,0 +74,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc