GitXplorerGitXplorer
s

kwic-ts

public
1 stars
0 forks
5 issues

Commits

List of commits on branch master.
Unverified
683d07ffd95fbce6098e6cfa6a5b429fa21b0454

Add clear button to the example app

sstrboul committed 3 years ago
Unverified
699f7fec18940958be423c5187616ea40f08daf7

0.1.4

sstrboul committed 3 years ago
Unverified
1ddfc384a4df543898416e62452e9d063b6d900a

Add tsc-alias for module-path resolution

sstrboul committed 3 years ago
Unverified
c08282bf7c768ca7805e1fb5c89517c1543f3d38

0.1.3

sstrboul committed 3 years ago
Unverified
4d770416b643e732d234ac2a96a04dcff66c8a50

Improve types & interfaces

sstrboul committed 3 years ago
Unverified
f8b3961a8e68bc92f2a0324c22a98b71c518a4f2

Some small changes & bump up version

sstrboul committed 3 years ago

README

The README file for this repository.

kwic-ts

Locate keywords-in-contexts

CI deploy-gh-pages npm package.json

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 an I.

Module path resolution