Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

polly-text-split

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

polly-text-split - npm Package Compare versions

Comparing version 0.1.1 to 0.1.3

50

API.md

@@ -1,4 +0,4 @@

<a name="TextSplit"></a>
<a name="PollyTextSplit"></a>
## TextSplit
## PollyTextSplit
Splits text for batches.

@@ -8,13 +8,12 @@

* [TextSplit](#TextSplit)
* [new TextSplit(softLimit, hardLimit, extraSplitChars)](#new_TextSplit_new)
* [.configure(options)](#TextSplit+configure)
* [.split(text)](#TextSplit+split) ⇒ <code>Array.&lt;string&gt;</code>
* [.splitIndex(text)](#TextSplit+splitIndex) ⇒ <code>number</code>
* [PollyTextSplit](#PollyTextSplit)
* [new PollyTextSplit(softLimit, hardLimit, extraSplitChars)](#new_PollyTextSplit_new)
* [.configure(options)](#PollyTextSplit+configure)
* [.split(text)](#PollyTextSplit+split) ⇒ <code>Array.&lt;string&gt;</code>
* [.splitIndex(text)](#PollyTextSplit+splitIndex) ⇒ <code>number</code>
<a name="new_TextSplit_new"></a>
<a name="new_PollyTextSplit_new"></a>
### new TextSplit(softLimit, hardLimit, extraSplitChars)
Set default character limits.
Initialize array for separated batches.
### new PollyTextSplit(softLimit, hardLimit, extraSplitChars)
Set the default options.

@@ -28,23 +27,28 @@

<a name="TextSplit+configure"></a>
<a name="PollyTextSplit+configure"></a>
### textSplit.configure(options)
Set configuration options.
This is optional. Default options are perfect for working with AWS Polly TTS.
### pollyTextSplit.configure(options)
Set the configuration options.
This is optional.
Default options are perfect for working with AWS Polly TTS.
**Kind**: instance method of [<code>TextSplit</code>](#TextSplit)
**Kind**: instance method of [<code>PollyTextSplit</code>](#PollyTextSplit)
**Throws**:
- <code>ConfigurationValidationError</code> Argument `options` is not valid.
| Param | Type | Default | Description |
| --- | --- | --- | --- |
| options | <code>Object</code> | | Object with configuration options. |
| options.softLimit | <code>number</code> | <code>1000</code> | Limit of a min batch size. |
| options.hardLimit | <code>number</code> | <code>1500</code> | Limit of a max possible batch size. |
| options.softLimit | <code>number</code> | <code>1000</code> | Limit of a min batch size. |
| [options.extraSplitChars] | <code>string</code> | <code>&quot;,;&quot;</code> | String with characters, that can be used as split markers. Optional parameter. |
<a name="TextSplit+split"></a>
<a name="PollyTextSplit+split"></a>
### textSplit.split(text) ⇒ <code>Array.&lt;string&gt;</code>
### pollyTextSplit.split(text) ⇒ <code>Array.&lt;string&gt;</code>
Splits text for batches of <=1500 chars or of custom size set by configure().
**Kind**: instance method of [<code>TextSplit</code>](#TextSplit)
**Kind**: instance method of [<code>PollyTextSplit</code>](#PollyTextSplit)
**Returns**: <code>Array.&lt;string&gt;</code> - Array with text batches.

@@ -56,8 +60,8 @@

<a name="TextSplit+splitIndex"></a>
<a name="PollyTextSplit+splitIndex"></a>
### textSplit.splitIndex(text) ⇒ <code>number</code>
### pollyTextSplit.splitIndex(text) ⇒ <code>number</code>
Search for possible split text index.
**Kind**: instance method of [<code>TextSplit</code>](#TextSplit)
**Kind**: instance method of [<code>PollyTextSplit</code>](#PollyTextSplit)
**Returns**: <code>number</code> - Position (index of `text` array) for possible split (including).

@@ -64,0 +68,0 @@

@@ -0,3 +1,3 @@

exports.SOFT_LIMIT = 1000
exports.HARD_LIMIT = 1500
exports.SOFT_LIMIT = 1000
exports.EXTRA_SPLIT_CHARS = ',;'

@@ -1,11 +0,13 @@

class ValidationError extends Error {
class ConfigurationValidationError extends Error {
/**
* Constructs the ConfigurationValidationError class.
* @param {string} message
* @constructor
*/
constructor(message) {
super(message)
this.name = 'Validation Error'
this.name = this.constructor.name
}
}
module.exports = { ValidationError }
module.exports = { ConfigurationValidationError }

@@ -1,3 +0,3 @@

const { ValidationError } = require('./errors')
const { HARD_LIMIT, SOFT_LIMIT, EXTRA_SPLIT_CHARS } = require('./defaults')
const { ConfigurationValidationError } = require('./errors')
const { SOFT_LIMIT, HARD_LIMIT, EXTRA_SPLIT_CHARS } = require('./defaults')

@@ -8,6 +8,5 @@ /**

*/
class TextSplit {
class PollyTextSplit {
/**
* Set default character limits.
* Initialize array for separated batches.
* Set the default options.
*

@@ -17,6 +16,7 @@ * @param {number} softLimit

* @param {string} extraSplitChars
* @constructor
*/
constructor(hardLimit, softLimit, extraSplitChars) {
constructor(softLimit, hardLimit, extraSplitChars) {
this._softLimit = softLimit
this._hardLimit = hardLimit
this._softLimit = softLimit
this._extraSplitChars = extraSplitChars

@@ -27,17 +27,19 @@ this._batches = []

/**
* Set configuration options.
* This is optional. Default options are perfect for working with AWS Polly TTS.
* Set the configuration options.
* This is optional.
* Default options are perfect for working with AWS Polly TTS.
*
* @param {Object} options Object with configuration options.
* @param {number} options.softLimit=1000 Limit of a min batch size.
* @param {number} options.hardLimit=1500 Limit of a max possible batch size.
* @param {number} options.softLimit=1000 Limit of a min batch size.
* @param {string} [options.extraSplitChars=,;] String with characters, that can be used as split markers. Optional parameter.
* @throws {ConfigurationValidationError} Argument `options` is not valid.
*/
configure(options) {
if (!options) {
throw new ValidationError('Parameter `options` is missing.')
throw new ConfigurationValidationError('Parameter `options` is missing.')
}
if (typeof options !== 'object') {
throw new ValidationError('Parameter `options` must be an object.')
throw new ConfigurationValidationError('Parameter `options` must be an object.')
}

@@ -63,5 +65,3 @@ this._softLimit = options.softLimit

this._batches.push(text)
const result = this._batches.slice(0)
this._batches = []
return result
return this._batches.splice(0)
} else {

@@ -117,2 +117,2 @@ this._batches.push(text.slice(0, splitIdx + 1))

module.exports = new TextSplit(HARD_LIMIT, SOFT_LIMIT, EXTRA_SPLIT_CHARS)
module.exports = new PollyTextSplit(SOFT_LIMIT, HARD_LIMIT, EXTRA_SPLIT_CHARS)
{
"name": "polly-text-split",
"version": "0.1.1",
"version": "0.1.3",
"description": "Text splitter for working with AWS Polly TTS.",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -5,2 +5,3 @@ # Polly Text Splitter

[![Coverage Status](https://coveralls.io/repos/github/oleglegun/polly-text-split/badge.svg?branch=master)](https://coveralls.io/github/oleglegun/polly-text-split?branch=master)
[![code style: prettier](https://img.shields.io/badge/code_style-prettier-ff69b4.svg?style=flat)](https://github.com/prettier/prettier)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)

@@ -18,8 +19,7 @@

1. at the nearest dot `.`
2. if (1) not found - split by `,` or `;` (by default, can be configured)
3. if (2) not found - split by space ` `
4. if (3) not found - hard split at `HARD_LIMIT` index
1. at the nearest dot `.`
2. if (1) not found - split by `,` or `;` (by default, can be configured)
3. if (2) not found - split by space ``
4. if (3) not found - hard split at `HARD_LIMIT` index
## Installation

@@ -39,5 +39,4 @@

// 2. Method splitIndex() returns index of the possible split position.
const splitIndex = pollyRuSSML.splitIndex('your long text here')
const splitIndex = pollyTextSplit.splitIndex('your long text here')
// So you can split manually using native string method

@@ -56,8 +55,8 @@ const batch = 'your long text here'.slice(0, splitIndex + 1)

const options = {
// MIN length of a single batch of split text
softLimit: 1000,
// MAX length of a single batch of split text
hardLimit: 1500,
// MIN length of a single batch of split text
softLimit: 1000,
// Set of extra split characters (Optional property)
extraSplitChars: ',;'
// Set of extra split characters (Optional property)
extraSplitChars: ',;',
}

@@ -69,3 +68,2 @@

const batches = pollyTextSplit.split('your long text here')
```

@@ -75,3 +73,2 @@

## Tests

@@ -91,7 +88,16 @@

### [0.1.3] - 2018-04-13
* Update JSDoc annotations.
### [0.1.2] - 2018-04-13
* Code refactor and optimizations.
### [0.1.1] - 2018-04-10
- Add Readme.
* Add Readme.
### [0.1.0] - 2018-04-10
- Initial release.
* Initial release.
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc