@casret/dedupe
Advanced tools
Comparing version 0.0.1 to 0.0.2
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" | ||
} | ||
} |
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
5165
5
111
1