
Security News
Feross on the 10 Minutes or Less Podcast: Nobody Reads the Code
Socket CEO Feross Aboukhadijeh joins 10 Minutes or Less, a podcast by Ali Rohde, to discuss the recent surge in open source supply chain attacks.
associative
Advanced tools
Dictionary class based on JavaScript object (associative) arrays
declare namespace Associative { type Func = (currentValue: any, key: string, index?: number) => any type Predicate = (currentValue: any, key: string, index?: number) => boolean type Accumulator = (accumulatedValue: any, currentValue: any, index?: number) => any
class Dictionary {
constructor(source?: Object | any[]);
hasKey(key): boolean;
get(key): Object;
put(key, value);
remove(key);
keys(): string[];
values(): any[];
entries(): { key: string, value: any }[];
getObject(): Object;
count(): number;
select(func): Dictionary;
where(func): Dictionary;
accumulate(initial, func);
forAll(func);
sum(func): number;
avg(func): number;
max(func): number;
min(func): number;
take(count): Dictionary;
skip(count): Dictionary;
toString();
}
}
const Dictionary = require("associative")// as typeof Associative.Dictionary; const consoleX = require("console-x");
var dict = new Dictionary({ foo: 'fooo', bar: 'baar' });
consoleX.notify("Key 'foo' exists?", dict.hasKey('foo')); // true consoleX.notify("Key 'zen' exists?", dict.hasKey('zen')); // false
consoleX.notify("Value of key 'foo'", dict.get('foo')); // "fooo" consoleX.notify("Value of key 'baar'", dict.get('baar')); // undefined
consoleX.warn("put 4 into key 'four'") dict.put("four", 4); // new key is "4" consoleX.notify("Value of key 'four'", dict.get("four")); // "four"
consoleX.warn("Put 'seven' into key 7") dict.put(7, "seven"); consoleX.notify("Value of key 7", dict.get(7)); // 7
consoleX.notify("Dictionary Keys", dict.keys()); // [foo, bar, 4, 7]
consoleX.warn("Remove nonexistent key 'test'") dict.remove("test"); // key does not exist, nothing removed consoleX.notify("Dictionary Keys", dict.keys()); // [foo, bar, 4, seven]
consoleX.notify("Dictionary Values", dict.values()); // seven,fooo,baar,4
consoleX.warn("Remove key 'four'")
dict.remove('four'); // key "four" removed
consoleX.notify("Dictionary Entries", JSON.stringify(dict.entries())); // [{"key":"7","value":"seven"},{"key":"foo","value":"fooo"},{"key":"bar","value":"baar"}]
consoleX.notify("Entries count", dict.count()); //
consoleX.notify(as object, JSON.stringify(dict.getObject())); // {"7":"seven","foo":"fooo","bar":"baar"}
consoleX.notify("Select value lengths", dict.select((item) => item.length).toString()); consoleX.notify("Where value length > 4", dict.where((item) => item.length > 4).toString()); consoleX.notify("Accumulate concat", dict.accumulate('', (currentAccumulation, newItem) => currentAccumulation + newItem)); consoleX.notify("Sum", dict.sum((item) => item.length)); //b13 consoleX.notify("Avg", dict.avg((item) => item.length)); // 4.333333333333333 consoleX.notify("Min", dict.min((item) => item.length)); // 4 consoleX.notify("Max", dict.max((item) => item.length)); // 5
consoleX.notify("Take 3", dict.take(3).toString()); consoleX.notify("Skip 2", dict.skip(2).toString());
consoleX.notify("Entries count", dict.count());
npm install associative --save
FAQs
Dictionary implementation based on JavaScript object (associative) arrays
We found that associative demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
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.

Security News
Socket CEO Feross Aboukhadijeh joins 10 Minutes or Less, a podcast by Ali Rohde, to discuss the recent surge in open source supply chain attacks.

Research
/Security News
Campaign of 108 extensions harvests identities, steals sessions, and adds backdoors to browsers, all tied to the same C2 infrastructure.

Security News
OpenAI rotated macOS signing certificates after a malicious Axios package reached its CI pipeline in a broader software supply chain attack.