# pt-client

> Client-side library to interact with the Perfect Tense API.

Latest version **1.0.1** (published 2018-04-04) · ISC license · 0 weekly downloads

> **Deprecated.** This package is deprecated.

## Install

```sh
npm install pt-client
pnpm add pt-client
yarn add pt-client
bun add pt-client
```

## Health

**Score 10/100 (F)** — status: deprecated.

Negative: deprecated.

## Facts

| | |
|---|---|
| Version | 1.0.1 |
| Published | 2018-04-04 |
| First published | 2018-04-04 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 36.8 KB |
| Known vulnerabilities | 0 (+24 in 1 direct dependencies) |
| Install scripts | no |
| Author | Cortx |
| Maintainers | david_cortx |

## Links

- npm: https://www.npmjs.com/package/pt-client
- Repository: https://github.com/dagreene7/perfecttense
- Homepage: https://github.com/dagreene7/perfecttense#readme
- Issues: https://github.com/dagreene7/perfecttense/issues
- npm.io page: https://npm.io/package/pt-client

## Dependencies (1)

- [axios](https://npm.io/package/axios.md) ^0.18.0

## Recent versions

- 1.0.1 (latest) — 2018-04-04

## README

# pt-client

A Node.js app used to interact with the Perfect Tense API.

All asynchronous operations are performed using Promises.

## Installing

Using npm:
```
$ npm install pt-client --save
```

## Examples

Initializing pt-client

```
const ptClient = require('pt-client')

// Configure app key (will be sent in the Header during all interactions with API)
ptClient.setAppKey([your registered app key])

// Configure verbose console output (useful for debugging)
ptClient.setVerbose(true)

// Configure persisting correction statuses (allows Perfect Tense to learn and develop over time)
ptClient.setPersistCorrections(true)
```

Submit a job to Perfect Tense

```
function ptSuccess(result) {
	// operate on successful result
}

function ptFailure(error) {
	// operate on error
}

ptClient.submitJob([text], [user's API Key]).then(ptSuccess, ptFailure)

```

Interaction with a Perfect Tense result

```
// Create an interactive editor Object
const intEditor = ptClient.interactiveEditor(result, [user's API Key])

// Ignore all suggestions that are pure comments ("This sentence is a fragment", etc.)
intEditor.setIgnoreNoReplacement(true)

// Iterate through all transformations in the response
while (intEditor.hasNextTransform()) {

	// Get the next available transformation
	const nextTransform = intEditor.getNextTransform()

	if (...) {
		// Accept the correction
		intEditor.acceptCorrection(nextTransform)
	} else {

		// Reject the correction
		intEditor.rejectCorrection(nextTransform)
	}

	// Re-construct the current state of the job (considering accepted/rejected corrections)
	const currentText = intEditor.getCurrentText()

	console.log(currentText)
}

```

The interactive editor is the recommended way use a Perfect Tense result. 

If the interactive editor's API is not sufficient for your use case, there are additional utilities provides directly through the pt-client.

When operating independently on the result object, please note that not all corrections are available at all times. Some corrections are dependent on others.

For example:

```
Input: "He hzve be there before"

Transformation 1: "hzve" -> "have" (spelling error)
Transformation 2: "have be" -> "has been" (verb agreement error)
```

Transformation 2 is not available until Transformation 1 has been accepted. If Transformation 1 is rejected, Transformation 2 will be lost.

When in doubt, there is a utility function to determine if a transformation is currently available or not:

```
// Returns true if the transform is currently available in the sentence, else false
ptClient.transformIsAvailable(transform, sentence)
```

## API Documentation

See our [API documentation](https://www.perfecttense.com/docs/#introduction) for more information.

---
_Source: https://npm.io/package/pt-client · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
