polly-text-split
Advanced tools
Comparing version 0.1.3 to 0.1.4
const { ConfigurationValidationError } = require('./errors') | ||
const { SOFT_LIMIT, HARD_LIMIT, EXTRA_SPLIT_CHARS } = require('./defaults') | ||
// Private properties | ||
const _softLimit = Symbol() | ||
const _hardLimit = Symbol() | ||
const _extraSplitChars = Symbol() | ||
const _batches = Symbol() | ||
/** | ||
@@ -18,6 +25,6 @@ * Splits text for batches. | ||
constructor(softLimit, hardLimit, extraSplitChars) { | ||
this._softLimit = softLimit | ||
this._hardLimit = hardLimit | ||
this._extraSplitChars = extraSplitChars | ||
this._batches = [] | ||
this[_softLimit] = softLimit | ||
this[_hardLimit] = hardLimit | ||
this[_extraSplitChars] = extraSplitChars | ||
this[_batches] = [] | ||
} | ||
@@ -44,7 +51,7 @@ | ||
} | ||
this._softLimit = options.softLimit | ||
this._hardLimit = options.hardLimit | ||
this[_softLimit] = options.softLimit | ||
this[_hardLimit] = options.hardLimit | ||
if (options.extraSplitChars && typeof options.extraSplitChars === 'string') { | ||
this._extraSplitChars = options.extraSplitChars | ||
this[_extraSplitChars] = options.extraSplitChars | ||
} | ||
@@ -63,6 +70,6 @@ } | ||
if (splitIdx === text.length - 1) { | ||
this._batches.push(text) | ||
return this._batches.splice(0) | ||
this[_batches].push(text) | ||
return this[_batches].splice(0) | ||
} else { | ||
this._batches.push(text.slice(0, splitIdx + 1)) | ||
this[_batches].push(text.slice(0, splitIdx + 1)) | ||
} | ||
@@ -80,10 +87,10 @@ | ||
splitIndex(text) { | ||
if (text.length < this._hardLimit) { | ||
if (text.length < this[_hardLimit]) { | ||
return text.length - 1 | ||
} | ||
let i = this._hardLimit | ||
let i = this[_hardLimit] | ||
let splitIdx | ||
while (i > this._softLimit) { | ||
while (i > this[_softLimit]) { | ||
// search for . | ||
@@ -96,5 +103,5 @@ if (text[i] === '.') return i | ||
// no . found - check for other split chars | ||
i = this._hardLimit | ||
while (i > this._softLimit) { | ||
if (this._extraSplitChars.indexOf(text[i]) !== -1) return i | ||
i = this[_hardLimit] | ||
while (i > this[_softLimit]) { | ||
if (this[_extraSplitChars].indexOf(text[i]) !== -1) return i | ||
i-- | ||
@@ -105,4 +112,4 @@ } | ||
// no split chars found - split by the nearest space char | ||
i = this._hardLimit | ||
while (i > this._softLimit) { | ||
i = this[_hardLimit] | ||
while (i > this[_softLimit]) { | ||
if (' \t\n\r\v'.indexOf(text[i]) !== -1) return i | ||
@@ -119,2 +126,2 @@ i-- | ||
module.exports = new PollyTextSplit(SOFT_LIMIT, HARD_LIMIT, EXTRA_SPLIT_CHARS) | ||
module.exports = new PollyTextSplit(SOFT_LIMIT, HARD_LIMIT, EXTRA_SPLIT_CHARS) |
{ | ||
"name": "polly-text-split", | ||
"version": "0.1.3", | ||
"version": "0.1.4", | ||
"description": "Text splitter for working with AWS Polly TTS.", | ||
@@ -17,3 +17,3 @@ "main": "index.js", | ||
}, | ||
"keywords": ["polly", "aws", "tts"], | ||
"keywords": ["polly", "aws", "tts", "alexa", "text split", "amazon"], | ||
"author": "Oleg Legun <oleg.legun@gmail.com>", | ||
@@ -20,0 +20,0 @@ "license": "MIT", |
@@ -6,3 +6,3 @@ # Polly Text Splitter | ||
[![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) | ||
[![License: MIT](https://img.shields.io/badge/License-MIT-green.svg)](https://opensource.org/licenses/MIT) | ||
@@ -22,3 +22,3 @@ ## Synopsis | ||
3. if (2) not found - split by space `` | ||
4. if (3) not found - hard split at `HARD_LIMIT` index | ||
4. if (3) not found - hard split at the `HARD_LIMIT` index | ||
@@ -36,3 +36,3 @@ ## Installation | ||
// 1. Method split() return array of strings. | ||
// 1. Method split() returns array of strings. | ||
const batches = pollyTextSplit.split('your long text here') | ||
@@ -48,3 +48,3 @@ | ||
By default, configuration is not necessary, but if you need to set your own limits or split characters - use method `configure()`. | ||
By default, configuration is not necessary, but if you need to set your own limits or split characters, you can use method `configure()` for that. | ||
@@ -64,2 +64,3 @@ ```js | ||
// Apply configuration | ||
pollyTextSplit.configure(options) | ||
@@ -87,16 +88,15 @@ | ||
### [0.1.4] - 2018-04-23 | ||
- Hide private properties from user API. | ||
### [0.1.3] - 2018-04-13 | ||
- Update JSDoc annotations. | ||
* Update JSDoc annotations. | ||
### [0.1.2] - 2018-04-13 | ||
- Code refactor and optimizations. | ||
* Code refactor and optimizations. | ||
### [0.1.1] - 2018-04-10 | ||
- Add Readme. | ||
* Add Readme. | ||
### [0.1.0] - 2018-04-10 | ||
* Initial release. | ||
- Initial release. |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
14084
189