Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@casret/dedupe

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@casret/dedupe - npm Package Compare versions

Comparing version 0.0.1 to 0.0.2

index.test.js

24

index.js

@@ -1,4 +0,4 @@

export const SortedItems = Symbol("SortedItems")
export const SortedKeys = Symbol("SortedKeys")
export const Unsorted = Symbol("Unsorted")
const SortedItems = Symbol("SortedItems")
const SortedKeys = Symbol("SortedKeys")
const Unsorted = Symbol("Unsorted")

@@ -12,3 +12,3 @@ class DedupeError extends Error {

export function dedupe(strategy, items, key_cache, key_mapper = item => item.id) {
function dedupe(strategy, items, key_cache, key_mapper = item => item.id) {
const isArray = Array.isArray(items)

@@ -24,3 +24,3 @@ if (!isArray) {

if (key.length > 64) {
console.log(`Key too long: ${item} was mapped to ${key}`)
console.error(`Key too long: ${item} was mapped to ${key}`)
throw new DedupeError("Dedup error, check logs")

@@ -35,2 +35,3 @@ }

// deal with the degenerate cases

@@ -48,3 +49,3 @@ if (!key_cache || !Array.isArray(key_cache)) {

} else if (strategy == SortedItems) {
const index = current_keys.find(key => key == key_cache[0])
const index = current_keys.findIndex(key => key == key_cache[0])
if (index) items = items.slice(0, index)

@@ -54,4 +55,5 @@ key_cache = current_keys

// strategy UNSORTED
const key_cache = key_cache.reduce(
(acc, obj) => (acc[obj] = true)
const key_map = key_cache.reduce(
(acc, obj) => {acc[obj] = true; return acc},
{}
)

@@ -62,3 +64,3 @@ const undropped_keys = []

items = items.filter((_obj, index) => {
if (!(current_keys[index] in key_cache)) {
if (!(current_keys[index] in key_map)) {
undropped_keys.push(current_keys[index])

@@ -101,1 +103,5 @@ return true

}
module.exports = {
SortedItems, SortedKeys, Unsorted, dedupe
}
{
"name": "@casret/dedupe",
"version": "0.0.1",
"version": "0.0.2",
"description": "Dedupe utilities for pipedream",

@@ -21,3 +21,6 @@ "main": "index.js",

},
"homepage": "https://github.com/casret/dedupe#readme"
"homepage": "https://github.com/casret/dedupe#readme",
"devDependencies": {
"jest": "^24.9.0"
}
}
SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc