Socket
Socket
Sign inDemoInstall

uniqs

Package Overview
Dependencies
0
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

uniqs

Tiny utility to create unions and de-duplicated lists


Version published
Maintainers
1
Weekly downloads
2,888,254
decreased by-10.7%

Weekly downloads

Package description

What is uniqs?

The uniqs npm package is a simple utility that allows you to filter out duplicate values from an array. It is particularly useful when you need to ensure that a list contains only unique items.

What are uniqs's main functionalities?

Removing duplicates from an array

This feature allows you to pass an array to the uniqs function, and it returns a new array with all the duplicate values removed, leaving only unique items.

[...new Set([1, 2, 2, 3, 4, 4, 5])] // returns [1, 2, 3, 4, 5]

Other packages similar to uniqs

Readme

Source

Build Status

Tiny utility to create unions and de-duplicated lists.

Example:

var uniqs = require('uniqs');

var foo = { foo: 23 };
var list = [3, 2, 2, 1, foo, foo];

uniqs(list);
// => [3, 2, 1, { foo: 23 }]

You can pass multiple lists to create a union:

uniqs([2, 1, 1], [2, 3, 3, 4], [4, 3, 2]);
// => [2, 1, 3, 4]

Passing individual items works too:

uniqs(3, 2, 2, [1, 1, 2]);
// => [3, 2, 1]

Summary

  • Uniqueness is defined based on strict object equality.
  • The lists do not need to be sorted.
  • The resulting array contains the items in the order of their first appearance.

About

This package has been written to accompany utilities like flatten as alternative to full-blown libraries like underscore or lodash.

The implementation is optimized for simplicity rather than performance and looks like this:

module.exports = function uniqs() {
  var list = Array.prototype.concat.apply([], arguments);
  return list.filter(function(item, i) {
    return i == list.indexOf(item);
  });
};

License

MIT

Keywords

FAQs

Last updated on 03 Jun 2014

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

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