Research
Recent Trends in Malicious Packages Targeting Discord
The Socket research team breaks down a sampling of malicious packages that download and execute files, among other suspicious behaviors, targeting the popular Discord platform.
@kamilmielnik/trie
Advanced tools
Readme
Trie data structure implemented in TypeScript:
npm install @kamilmielnik/trie --save
yarn add @kamilmielnik/trie
See full API Docs - generated by typedoc.
Good to know:
There are 2 ways to use the API.
Create Trie
instance and use its methods.
import { Trie } from '@kamilmielnik/trie';
const trie = new Trie();
trie.add('master');
trie.add('mask');
trie.hasPrefix('man'); // false
trie.hasPrefix('mas'); // true
trie.has('mas'); // false
trie.remove('mas'); // false
trie.has('master'); // true
trie.serialize(); // "(m(a(s(t(e(r))k))))"
trie.remove('master'); // true
trie.serialize(); // "(m(a(s(k))))"
Manipulate existing instances of Node
with functions.
The following example works identically to the object-oriented example above.
import { add, has, hasPrefix, Node, remove, serialize } from '@kamilmielnik/trie';
const root: Node = {};
add(root, 'master');
add(root, 'mask');
hasPrefix(root, 'man'); // false
hasPrefix(root, 'mas'); // true
has(root, 'mas'); // false
remove(root, 'mas'); // false
has(root, 'master'); // true
serialize(root); // "(m(a(s(t(e(r))k))))"
remove(root, 'master'); // true
serialize(root); // "(m(a(s(k))))"
Node
to a fileNode
from a fileimport { fromArray, Node } from '@kamilmielnik/trie';
import fs from 'fs';
const fromFile = (filepath: string): Node => {
const file = fs.readFileSync(filepath, 'utf-8');
// Assuming file contains 1 word per line
const words = file.split('\n').filter(Boolean);
const node = fromArray(words);
return node;
};
Node
to a fileimport { Trie } from '@kamilmielnik/trie';
import fs from 'fs';
const toFile = (filepath: string, trie: Trie): void => {
const serialized = trie.serialize();
fs.writeFileSync(filepath, serialized);
};
Node
from a fileimport { deserialize, Node } from '@kamilmielnik/trie';
import fs from 'fs';
const fromFile = (filepath: string): Node => {
const serialized = fs.readFileSync(filepath, 'utf-8');
const node = deserialize(serialized);
return node;
};
import { find, Node, toArray } from '@kamilmielnik/trie';
const findWordsWithPrefix = (node: Node, prefix: string): string[] => {
const prefixNode = find(node, prefix) || {};
const descendants = toArray(prefixNode, { prefix, sort: true, wordsOnly: true });
const words = descendants.map(({ prefix: word }) => word);
return words;
};
This package can be used to efficiently serialize and compress dictionaries. It reaches 54.79 compression ratio (98.17% space saving) for Polish dictionary when combined with 7-Zip at ultra compression level.
Language | 🇺🇸 en-US | 🇬🇧 en-GB | 🇵🇱 pl-PL |
---|---|---|---|
Name | TWL06 | SOWPODS | SJP.PL |
Source | Download | Download | Download |
Words count | 178,691 | 267,753 | 3,045,878 |
File size [B] | 1,941,856 | 2,974,773 | 42,838,508 |
File size (serialized) [B] | (-29.75%) 1,364,242 | (-31.57%) 2,035,697 | (-56.33%) 18,705,990 |
File size (7z) [B] | (-80.46%) 379,483 | (-81.04%) 563,913 | (-87.58%) 5,320,397 |
File size (serialized + 7z) [B] | (-89.94%) 195,299 | (-90.40%) 285,430 | (-98.17%) 781,875 |
add
, find
, has
, hasPrefix
, remove
are very fast - $O(\log_2 n)$ (millions of operations per second).
deserialize
, fromArray
, serialize
, toArray
are slow - $O(n)$ (few operations per second).
FAQs
Trie data structure implementation in TypeScript. Highly performant. No dependencies. Built for a Scrabble Solver.
We found that @kamilmielnik/trie demonstrated a healthy version release cadence and project activity because the last version was released less than 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.
Research
The Socket research team breaks down a sampling of malicious packages that download and execute files, among other suspicious behaviors, targeting the popular Discord platform.
Security News
Socket CEO Feross Aboukhadijeh joins a16z partners to discuss how modern, sophisticated supply chain attacks require AI-driven defenses and explore the challenges and solutions in leveraging AI for threat detection early in the development life cycle.
Security News
NIST's new AI Risk Management Framework aims to enhance the security and reliability of generative AI systems and address the unique challenges of malicious AI exploits.