dawg-lookup
Advanced tools
Comparing version 2.0.0 to 2.1.0
{ | ||
"name": "dawg-lookup", | ||
"version": "2.0.0", | ||
"version": "2.1.0", | ||
"description": "Directed Acyclic Word Graph", | ||
"main": "lib/index.js", | ||
"bin": "lib/dawg.js", | ||
"files": [ | ||
"lib", | ||
"src" | ||
], | ||
"scripts": { | ||
@@ -8,0 +12,0 @@ "test": "tools/run-tests" |
@@ -1,34 +0,59 @@ | ||
// Command-line interface for | ||
#!/usr/bin/env node | ||
/* | ||
Command-line interface for dawg-lookup package. | ||
Compress a file containing a dictionary of words into a packed | ||
directed acyclic graph to be used with the 'dawg-lookup/ptrie' | ||
decoder. | ||
Usage: | ||
dawg-lookup dictionary.txt > dictionary.dawg | ||
To load the resulting DAWG for decoding (ES6 or TypeScript): | ||
import { PTrie } from 'dawg-lookup/ptrie'; | ||
let dawg: string = <load compressed dictionary from ajax or file system>; | ||
let ptrie = new PTrie(dawg); | ||
if (ptrie.isWord('hello')) { | ||
console.log("'Hello' is in the dictionary."); | ||
} | ||
*/ | ||
import * as fs from 'fs'; | ||
import { pack, stringStats } from './pack'; | ||
import { Trie } from './trie'; | ||
import { readFile } from './file-util'; | ||
// Command-line argument processing. | ||
export function main(args: string[]) { | ||
function main(args: string[]) { | ||
if (args.length !== 1) { | ||
throw new Error("Usage: string-pack-js <file.js>"); | ||
throw new Error("Usage: dawg-lookup dictionary.txt > dictionary.dawg"); | ||
} | ||
packFile(args[0]); | ||
compressDictionaryFile(args[0]) | ||
.then((packed) => { | ||
process.stdout.write(packed + '\n'); | ||
}); | ||
} | ||
// Pack a single file and write to '<name>.packed'. | ||
export function packFile(name: string) { | ||
console.log("Packing strings in: " + name); | ||
// Pack a single file and write to standard output. | ||
function compressDictionaryFile(path: string): Promise<string> { | ||
return readFile(path) | ||
.then((data) => { | ||
let trie = new Trie(data); | ||
let packed = trie.pack(); | ||
const contents = fs.readFileSync(name, 'utf8'); | ||
const stats = stringStats(contents); | ||
console.error('Compressed ' + trie.wordCount + ' words.'); | ||
console.error('Input size: ' + data.length + ' bytes.'); | ||
console.error('Compressed size: ' + packed.length + ' bytes.'); | ||
console.log(`File length: ${contents.length}`); | ||
console.log("All lengths:\n" + stats['lengths'].histogramReport()); | ||
console.log("Duplicates:\n" + stats['duplicates'].histogramReport()); | ||
const packed = pack(contents); | ||
const bytesSaved = contents.length - packed.length; | ||
const percentSaved = Math.floor(100 * bytesSaved / contents.length); | ||
console.log(`Packed size: ${packed.length} (saved ${bytesSaved} or ` + | ||
`${percentSaved}%).`); | ||
fs.writeFileSync(name + '.packed', packed, 'utf8'); | ||
return packed; | ||
}); | ||
} | ||
// Call main() if run from command line (as opposed to required). | ||
// Call main() if run from command line (as opposed to being required). | ||
if (require.main === module) { | ||
@@ -35,0 +60,0 @@ try { |
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
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
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
46
2145
109843
2