Sapling Logo

Grammar Checking in JavaScript

JavaScript

JavaScript is a scripting language used in browsers to provide client-side dynamic application behavior. Almost all websites use it. Additionally, JavaScript is also used in server-side applications through environments like Node.js. Cross-platform and desktop applications can be developed using the Electron framework.

Sapling: AI Writing Assistant

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

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

Sapling maintains a JavaScript 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

JavaScript Grammar Check Quickstart

HTML / JavaScript

<script src="https://sapling.ai/static/js/sapling-sdk-v1.0.6.min.js"></script>

<div contenteditable="true" id="check-space" sapling-ignore="true">Lets get started!</div>

<script type="text/javascript">
Sapling.init({
  key: '<API_KEY>',
  endpointHostname: 'https://api.sapling.ai',
  editPathname: '/api/v1/edits',
  statusBadge: true,
  mode: 'dev',
});

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

Node.js / JavaScript

  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