Comparing version 0.0.1 to 0.0.2
@@ -14,11 +14,11 @@ 'use strict' | ||
} | ||
if(~source.indexOf(element)){ | ||
let cloned = source.slice(); | ||
if(~cloned.indexOf(element)){ | ||
return; | ||
} else { | ||
source.push(element); | ||
cloned.push(element); | ||
} | ||
return source; | ||
return cloned; | ||
} | ||
module.exports = addToSet; |
{ | ||
"name": "addtoset", | ||
"version": "0.0.1", | ||
"version": "0.0.2", | ||
"description": "Utility array function to add value to array if doesn't exist", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -0,2 +1,28 @@ | ||
© ,Kailash Yogeshwar, Licensed under MIT-License | ||
# addToSet | ||
A library to add an element to array set if doesn't already exist else return the source array. | ||
# Install | ||
```bash | ||
npm install addtoset -S | ||
``` | ||
# Features | ||
Adds element to array if it doesn't already exist in array and return the new array version with modified value if any. | ||
``` javascript | ||
const addToSet = require('addtoset'); | ||
let arr = [1,2,3,4,5]; | ||
addToSet.push(arr, 6); // [1,2,3,4,5,6] | ||
addToSet.push(arr, 1); // [1,2,3,4,5] | ||
// Error if parameter is not array | ||
let str = "msg"; | ||
addToSet.push(str,1); // Error: Source must be array | ||
``` | ||
Thank you. Happy Coding |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
3084
21
28