Skip to content

Offline, privacy-first grammar checker. Fast, open-source, Rust-powered

Update +page.md

AminWhatbac07a8a9db0
diff --git a/packages/web/src/routes/docs/harperjs/introduction/+page.md b/packages/web/src/routes/docs/harperjs/introduction/+page.md
index 1ec082943..c128f95d2 100644
--- a/packages/web/src/routes/docs/harperjs/introduction/+page.md
+++ b/packages/web/src/routes/docs/harperjs/introduction/+page.md
@@ -21,3 +21,36 @@ On the inside, it uses a copy of Harper's core algorithm compiled to [WebAssembl
It can be imported [natively in a browser](./CDN) or through [npm](https://www.npmjs.com/package/harper.js).
@install-pkg(harper.js)
+
+
+## Sample Usage:
+```js
+let harper = require('harper.js');
+
+async function main() {
+ // We cannot use `WorkerLinter` on Node.js since it relies on web-specific APIs.
+ let linter = new harper.LocalLinter();
+
+ let lints = await linter.lint('This is a example of how to use `harper.js`.');
+
+ console.log('Here are the results of linting the above text:');
+
+ for (let lint of lints) {
+ console.log(' - ', lint.span().start, ':', lint.span().end, lint.message());
+
+ if (lint.suggestion_count() != 0) {
+ console.log('Suggestions:');
+
+ for (let sug of lint.suggestions()) {
+ console.log(
+ '\t - ',
+ sug.kind() == 1 ? 'Remove' : 'Replace with',
+ sug.get_replacement_text()
+ );
+ }
+ }
+ }
+}
+
+main();
+```