Sapling Logo

Grammar Checking in Typescript

Typescript

TypeScript is a strongly-typed programming language that transpiles into JavaScript. It is a superset or extension of JavaScript and adds optional static typing functionality. The language is developed and maintained by Microsoft.

Sapling: AI Writing Assistant

With Sapling, you can add grammar or spell checking functionality to an existing Typescript application.

This page demonstrates a quick way to integrate grammar and spell checking functionality into a Typescript application using Sapling's API. If you are not looking for a Typescript guide, click here for guides for other programming languages.

Sapling maintains a Typescript specific SDK that you can view documentation for here, but you can also access the Sapling Grammar Checking HTTP API using any programming language that supports HTTP POST requests.

Setup Steps

Typescript Grammar Check Quickstart

HTML / Typescript

<script src="https://sapling.ai/static/js/sapling-sdk-v1.0.6.min.js"></script>
<div contenteditable="true" id="check-space"></div>

<script type="text/javascript">
Sapling.init({
  endpointHostname: "https://api.sapling.ai",
  editPathname: "/api/edits",
  completePathname: "/api/complete",
  autocomplete: true,
  statusBadge: true,
});

const contentEditable = document.getElementById('check-space');
Sapling.observe(contentEditable);
</script>

Node.js / Typescript

  npm install saplingai/sapling-js
import { Client } from "@saplingai/sapling-js/client";

const apiKey = '<API_KEY>';
const client = new Client(apiKey);
client
  .edits('Lets get started!')
  .then(function (response) {
    console.log(response.data);
  })

Returned result:

{
    "edits":[
      {
          "end":4,
          "error_type":"R:OTHER",
          "general_error_type":"Other",
          "id":"aa5ee291-a073-5146-8ebc-c9c899d01278",
          "replacement":"Let's",
          "sentence":"Lets get started!",
          "sentence_start":0,
          "start":0
      }
    ]
}

Documentation

Addtional parameters and Sapling's full API documentation can be accessed here: https://sapling.ai/docs