0.1.4 • Published 4 years ago
@strboul/kwic-ts v0.1.4
kwic-ts
Locate keywords-in-contexts
KWIC (Keyword-in-context) helps you see a match with adjacent words in order to convey more information about the context.
Usage
import { Kwic } from "@strboul/kwic-ts";
const text = `
I'm a deep water sailor just come from Hong Kong
You give me some whiskey, I'll sing you a song
There's tinkers and tailors, shoemakers and all
They're all shipped for sailors aboard the Black Ball
`;
const term = "[s|t]ailor";
const kwic = new Kwic(text, term, [3, 3]);
kwic.getMatches();
// [
// {
// index: 'sailor',
// left: [ 'a', 'deep', 'water' ],
// right: [ 'just', 'come', 'from' ]
// },
// {
// index: 'tailors,',
// left: [ "There's", 'tinkers', 'and' ],
// right: [ 'shoemakers', 'and', 'all' ]
// },
// {
// index: 'sailors',
// left: [ 'all', 'shipped', 'for' ],
// right: [ 'aboard', 'the', 'Black' ]
// }
// ]
API
class | method | description |
---|---|---|
new Kwic(text, term, windows) | new Kwic class | |
.getPositions() | get word positions | |
.getMatches() | get word matches | |
.getRanges() | get matched word ranges |
Installation
$ npm install @strboul/kwic-ts
CDN
<script src="https://unpkg.com/@strboul/kwic-ts/dist/kwic.js"></script>
Development
Running tests & debugging
# run tests:
npm run test
# start debugger:
npm run test:debug-devtools # via Chrome DevTools
npm run test:debug-repl # via node.js REPL
npm run test:debug-repl -- kwic.test.ts -t "token" # specify optional file and test pattern
npm run npm:link # create a symbolic link from globally-installed package-name to node_modules
npm run npm:publish # publish to npm registry (with credentials)
Release to npm
npm run npm:bumpVersion <version> # e.g. 0.1.2
npm run npm:release
# after publishing
npm run npm:view
General
- The TS types starts with a
T
and follow the UpperCamelCase. Same rule applies for the interfaces but they start with anI
.
Module path resolution
tsconfig-paths is used for path resolution.
tsc-alias is to resolve paths in the
dist
folder.