@@ -5,7 +5,7 @@ const textchunk = require('textchunk')
5
5
* Chunk text into pieces.
6
6
*/
7
7
const chunkText = ( text , maxCharacterCount ) => {
8
- let parts = textchunk . chunk ( text , maxCharacterCount )
8
+ const parts = textchunk . chunk ( text , maxCharacterCount )
9
9
debug ( 'chunkText' ) ( `Chunked into ${ parts . length } text parts` )
10
10
return Promise . resolve ( parts )
11
11
}
@@ -22,9 +22,9 @@ const chunkXml = (xml, maxCharacterCount) => {
22
22
debug ( 'chunkXml' ) ( 'Started SAX XML parser' )
23
23
const attributeString = attrs => {
24
24
let str = ''
25
- for ( let prop in attrs ) {
25
+ for ( const prop in attrs ) {
26
26
/* istanbul ignore else: need to add test for this */
27
- if ( attrs . hasOwnProperty ( prop ) ) {
27
+ if ( Object . prototype . hasOwnProperty . call ( attrs , prop ) ) {
28
28
str += ` ${ prop } ="${ attrs [ prop ] } "`
29
29
}
30
30
}
@@ -33,16 +33,16 @@ const chunkXml = (xml, maxCharacterCount) => {
33
33
return new Promise ( ( resolve , reject ) => {
34
34
let err = null
35
35
let extraTags = '' // self-closing tags
36
- let tags = [ ] // stack of open tags
37
- let parts = [ ]
36
+ const tags = [ ] // stack of open tags
37
+ const parts = [ ]
38
38
/* istanbul ignore next */
39
39
parser . onerror = e => {
40
40
debug ( 'chunkXml' ) ( `Encountered error: ${ e } ` )
41
41
err = e
42
42
}
43
43
parser . ontext = text => {
44
44
debug ( 'chunkXml' ) ( `Found text: ${ text . substr ( 0 , 50 ) } ...` ) // eslint-disable-line no-magic-numbers
45
- let chunks = textchunk . chunk ( text , maxCharacterCount ) . map ( ( chunk , index ) => {
45
+ const chunks = textchunk . chunk ( text , maxCharacterCount ) . map ( ( chunk , index ) => {
46
46
if ( index === 0 ) {
47
47
debug ( 'chunkXml' ) ( 'Adding unused self-closing tags:' , extraTags )
48
48
chunk = `${ extraTags } ${ chunk } `
@@ -62,7 +62,7 @@ const chunkXml = (xml, maxCharacterCount) => {
62
62
parser . onopentag = tagData => {
63
63
debug ( 'chunkXml' ) ( `Found tag: ${ JSON . stringify ( tagData ) } ` )
64
64
if ( tagData . isSelfClosing ) {
65
- let attrs = attributeString ( tagData . attributes )
65
+ const attrs = attributeString ( tagData . attributes )
66
66
debug ( 'chunkXml' ) ( `Adding "${ tagData . name } " to self-closing tags` )
67
67
extraTags += `<${ tagData . name } ${ attrs } />`
68
68
} else {
@@ -78,7 +78,7 @@ const chunkXml = (xml, maxCharacterCount) => {
78
78
tags . pop ( )
79
79
} else {
80
80
// TODO should error
81
- debug ( 'chunkXml' ) ( ` Problem: mismatched tags` )
81
+ debug ( 'chunkXml' ) ( ' Problem: mismatched tags' )
82
82
}
83
83
}
84
84
parser . onend = ( ) => {
@@ -101,7 +101,7 @@ exports.splitText = (ctx) => {
101
101
const text = ctx . text
102
102
const maxCharacterCount = ctx . maxCharacterCount
103
103
const opts = ctx . args || { }
104
- let chunker = opts . type === 'ssml' ? chunkXml : chunkText
104
+ const chunker = opts . type === 'ssml' ? chunkXml : chunkText
105
105
return chunker ( text , maxCharacterCount ) . then ( parts => {
106
106
debug ( 'splitText' ) ( 'Stripping whitespace' )
107
107
return parts . map ( str => {
0 commit comments