sentence-splitter
Advanced tools
Comparing version 3.0.4 to 3.0.6
@@ -76,3 +76,3 @@ "use strict"; | ||
if (/^([a-zA-Z]\.){3,}$/.test(currentWord)) { | ||
return sourceCode.markContextRange([sourceCode.index, sourceCode.index + currentWord.length]); | ||
return sourceCode.markContextRange([sourceCode.offset, sourceCode.offset + currentWord.length]); | ||
} | ||
@@ -85,3 +85,3 @@ // EXCALAMATION_WORDS | ||
if (isMatchedEXCALAMATION_WORDS) { | ||
return sourceCode.markContextRange([sourceCode.index, sourceCode.index + currentWord.length]); | ||
return sourceCode.markContextRange([sourceCode.offset, sourceCode.offset + currentWord.length]); | ||
} | ||
@@ -94,3 +94,3 @@ // PREPOSITIVE_ABBREVIATIONS | ||
if (isMatchedPREPOSITIVE_ABBREVIATIONS) { | ||
return sourceCode.markContextRange([sourceCode.index, sourceCode.index + currentWord.length]); | ||
return sourceCode.markContextRange([sourceCode.offset, sourceCode.offset + currentWord.length]); | ||
} | ||
@@ -110,3 +110,3 @@ // ABBREVIATIONS | ||
if (isCapitalized(prevWord) && /[A-Z]\./.test(currentWord) && isCapitalized(nextWord)) { | ||
sourceCode.markContextRange([sourceCode.index, sourceCode.index + currentWord.length]); | ||
sourceCode.markContextRange([sourceCode.offset, sourceCode.offset + currentWord.length]); | ||
} | ||
@@ -116,3 +116,3 @@ else if (isMatched && !isCapitalized(nextWord)) { | ||
// A.M. is store. | ||
sourceCode.markContextRange([sourceCode.index, sourceCode.index + currentWord.length]); | ||
sourceCode.markContextRange([sourceCode.offset, sourceCode.offset + currentWord.length]); | ||
} | ||
@@ -119,0 +119,0 @@ }; |
@@ -21,3 +21,17 @@ "use strict"; | ||
AnyValueParser.prototype.seek = function (sourceCode) { | ||
while (this.test(sourceCode)) { | ||
var currentNode = sourceCode.readNode(); | ||
if (!currentNode) { | ||
// Text mode | ||
while (this.test(sourceCode)) { | ||
this.markers.forEach(function (marker) { return marker.mark(sourceCode); }); | ||
sourceCode.peek(); | ||
} | ||
return; | ||
} | ||
// node - should not over next node | ||
var isInCurrentNode = function () { | ||
var currentOffset = sourceCode.offset; | ||
return currentNode.range[0] <= currentOffset && currentOffset < currentNode.range[1]; | ||
}; | ||
while (isInCurrentNode() && this.test(sourceCode)) { | ||
this.markers.forEach(function (marker) { return marker.mark(sourceCode); }); | ||
@@ -24,0 +38,0 @@ sourceCode.peek(); |
import { TxtNode, TxtParentNode } from "@textlint/ast-node-types"; | ||
import { AbstractParser } from "./AbstractParser"; | ||
export declare class SourceCode { | ||
private _index; | ||
private index; | ||
private source; | ||
@@ -10,6 +10,5 @@ private textCharacters; | ||
private contextRanges; | ||
private firstChildOffset; | ||
private firstChildPadding; | ||
private startOffset; | ||
constructor(input: string | TxtParentNode); | ||
index: number; | ||
markContextRange(range: [number, number]): void; | ||
@@ -21,4 +20,10 @@ isInContextRange(): boolean; | ||
/** | ||
* Return absolute position object | ||
* Return current offset value | ||
* @returns {number} | ||
*/ | ||
readonly offset: number; | ||
/** | ||
* Return current position object. | ||
* It includes line, column, offset. | ||
*/ | ||
now(): { | ||
@@ -25,0 +30,0 @@ line: number; |
@@ -6,3 +6,3 @@ "use strict"; | ||
function SourceCode(input) { | ||
this._index = 0; | ||
this.index = 0; | ||
this.contexts = []; | ||
@@ -14,3 +14,3 @@ this.contextRanges = []; | ||
this.startOffset = 0; | ||
this.firstChildOffset = 0; | ||
this.firstChildPadding = 0; | ||
} | ||
@@ -33,20 +33,10 @@ else { | ||
// Example: # Header | ||
// It firstChildOffset is `2` | ||
this.firstChildOffset = this.sourceNode.children[0].range[0] - this.startOffset; | ||
// It firstChildPadding is `2` | ||
this.firstChildPadding = this.sourceNode.children[0].range[0] - this.startOffset; | ||
} | ||
else { | ||
this.firstChildOffset = 0; | ||
this.firstChildPadding = 0; | ||
} | ||
} | ||
} | ||
Object.defineProperty(SourceCode.prototype, "index", { | ||
get: function () { | ||
return this._index; | ||
}, | ||
set: function (newIndex) { | ||
this._index = newIndex; | ||
}, | ||
enumerable: true, | ||
configurable: true | ||
}); | ||
SourceCode.prototype.markContextRange = function (range) { | ||
@@ -56,5 +46,5 @@ this.contextRanges.push(range); | ||
SourceCode.prototype.isInContextRange = function () { | ||
var index = this.index; | ||
var offset = this.offset; | ||
return this.contextRanges.some(function (range) { | ||
return range[0] <= index && index < range[1]; | ||
return range[0] <= offset && offset < range[1]; | ||
}); | ||
@@ -77,7 +67,19 @@ }; | ||
}; | ||
Object.defineProperty(SourceCode.prototype, "offset", { | ||
/** | ||
* Return current offset value | ||
* @returns {number} | ||
*/ | ||
get: function () { | ||
return this.index + this.firstChildPadding; | ||
}, | ||
enumerable: true, | ||
configurable: true | ||
}); | ||
/** | ||
* Return absolute position object | ||
* Return current position object. | ||
* It includes line, column, offset. | ||
*/ | ||
SourceCode.prototype.now = function () { | ||
var indexWithChildrenOffset = this.index + this.firstChildOffset; | ||
var indexWithChildrenOffset = this.offset; | ||
var position = this.source.indexToPosition(indexWithChildrenOffset); | ||
@@ -107,3 +109,3 @@ return { | ||
if (over === void 0) { over = 0; } | ||
var index = this.index + this.firstChildOffset + over; | ||
var index = this.offset + over; | ||
if (index < this.startOffset) { | ||
@@ -127,3 +129,3 @@ return false; | ||
} | ||
var index = this.index + this.firstChildOffset + over; | ||
var index = this.offset + over; | ||
if (index < this.startOffset) { | ||
@@ -130,0 +132,0 @@ return false; |
@@ -14,3 +14,3 @@ { | ||
}, | ||
"version": "3.0.4", | ||
"version": "3.0.6", | ||
"description": "split {japanese, english} text into sentences.", | ||
@@ -17,0 +17,0 @@ "main": "lib/sentence-splitter.js", |
@@ -83,3 +83,3 @@ import { SourceCode } from "./SourceCode"; | ||
if (/^([a-zA-Z]\.){3,}$/.test(currentWord)) { | ||
return sourceCode.markContextRange([sourceCode.index, sourceCode.index + currentWord.length]); | ||
return sourceCode.markContextRange([sourceCode.offset, sourceCode.offset + currentWord.length]); | ||
} | ||
@@ -92,3 +92,3 @@ // EXCALAMATION_WORDS | ||
if (isMatchedEXCALAMATION_WORDS) { | ||
return sourceCode.markContextRange([sourceCode.index, sourceCode.index + currentWord.length]); | ||
return sourceCode.markContextRange([sourceCode.offset, sourceCode.offset + currentWord.length]); | ||
} | ||
@@ -101,3 +101,3 @@ // PREPOSITIVE_ABBREVIATIONS | ||
if (isMatchedPREPOSITIVE_ABBREVIATIONS) { | ||
return sourceCode.markContextRange([sourceCode.index, sourceCode.index + currentWord.length]); | ||
return sourceCode.markContextRange([sourceCode.offset, sourceCode.offset + currentWord.length]); | ||
} | ||
@@ -117,9 +117,9 @@ // ABBREVIATIONS | ||
if (isCapitalized(prevWord) && /[A-Z]\./.test(currentWord) && isCapitalized(nextWord)) { | ||
sourceCode.markContextRange([sourceCode.index, sourceCode.index + currentWord.length]); | ||
sourceCode.markContextRange([sourceCode.offset, sourceCode.offset + currentWord.length]); | ||
} else if (isMatched && !isCapitalized(nextWord)) { | ||
// Exception. This allow to write Capitalized word at next word | ||
// A.M. is store. | ||
sourceCode.markContextRange([sourceCode.index, sourceCode.index + currentWord.length]); | ||
sourceCode.markContextRange([sourceCode.offset, sourceCode.offset + currentWord.length]); | ||
} | ||
} | ||
} |
@@ -33,3 +33,17 @@ import { SourceCode } from "./SourceCode"; | ||
seek(sourceCode: SourceCode) { | ||
while (this.test(sourceCode)) { | ||
const currentNode = sourceCode.readNode(); | ||
if (!currentNode) { | ||
// Text mode | ||
while (this.test(sourceCode)) { | ||
this.markers.forEach(marker => marker.mark(sourceCode)); | ||
sourceCode.peek(); | ||
} | ||
return; | ||
} | ||
// node - should not over next node | ||
const isInCurrentNode = () => { | ||
const currentOffset = sourceCode.offset; | ||
return currentNode.range[0] <= currentOffset && currentOffset < currentNode.range[1]; | ||
}; | ||
while (isInCurrentNode() && this.test(sourceCode)) { | ||
this.markers.forEach(marker => marker.mark(sourceCode)); | ||
@@ -36,0 +50,0 @@ sourceCode.peek(); |
@@ -7,3 +7,3 @@ import { TxtNode, TxtParentNode } from "@textlint/ast-node-types"; | ||
export class SourceCode { | ||
private _index: number = 0; | ||
private index: number = 0; | ||
private source: any; | ||
@@ -14,3 +14,3 @@ private textCharacters: string[]; | ||
private contextRanges: [number, number][] = []; | ||
private firstChildOffset: number; | ||
private firstChildPadding: number; | ||
private startOffset: number; | ||
@@ -23,3 +23,3 @@ | ||
this.startOffset = 0; | ||
this.firstChildOffset = 0; | ||
this.firstChildPadding = 0; | ||
} else { | ||
@@ -41,6 +41,6 @@ this.sourceNode = input; | ||
// Example: # Header | ||
// It firstChildOffset is `2` | ||
this.firstChildOffset = this.sourceNode.children[0].range[0] - this.startOffset; | ||
// It firstChildPadding is `2` | ||
this.firstChildPadding = this.sourceNode.children[0].range[0] - this.startOffset; | ||
} else { | ||
this.firstChildOffset = 0; | ||
this.firstChildPadding = 0; | ||
} | ||
@@ -50,10 +50,2 @@ } | ||
get index() { | ||
return this._index; | ||
} | ||
set index(newIndex) { | ||
this._index = newIndex; | ||
} | ||
markContextRange(range: [number, number]) { | ||
@@ -64,5 +56,5 @@ this.contextRanges.push(range); | ||
isInContextRange() { | ||
const index = this.index; | ||
const offset = this.offset; | ||
return this.contextRanges.some(range => { | ||
return range[0] <= index && index < range[1]; | ||
return range[0] <= offset && offset < range[1]; | ||
}); | ||
@@ -90,6 +82,15 @@ } | ||
/** | ||
* Return absolute position object | ||
* Return current offset value | ||
* @returns {number} | ||
*/ | ||
get offset() { | ||
return this.index + this.firstChildPadding; | ||
} | ||
/** | ||
* Return current position object. | ||
* It includes line, column, offset. | ||
*/ | ||
now() { | ||
const indexWithChildrenOffset = this.index + this.firstChildOffset; | ||
const indexWithChildrenOffset = this.offset; | ||
const position = this.source.indexToPosition(indexWithChildrenOffset); | ||
@@ -116,3 +117,3 @@ return { | ||
read(over: number = 0) { | ||
const index = this.index + this.firstChildOffset + over; | ||
const index = this.offset + over; | ||
if (index < this.startOffset) { | ||
@@ -136,3 +137,3 @@ return false; | ||
} | ||
const index = this.index + this.firstChildOffset + over; | ||
const index = this.offset + over; | ||
if (index < this.startOffset) { | ||
@@ -139,0 +140,0 @@ return false; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
103350
2281