textlint-util-to-string
Advanced tools
Comparing version 1.1.1 to 1.2.0
@@ -40,6 +40,6 @@ // LICENSE : MIT | ||
original : [start, end] | ||
// trim value from Original = intermediate | ||
// intermediate = trim decoration from Original | ||
// e.g.) [2, 5] | ||
intermediate: [start, end] | ||
// actual value = Str | ||
// generaged value = "Str" | ||
// e.g.) [0, 3] | ||
@@ -58,5 +58,4 @@ generated : [start, end] | ||
/** | ||
* Pass index value and return original index value. | ||
* @param {number} targetIndex - position is a index value. | ||
* @returns {number|undefined} original | ||
* @deprecated use originalIndexFromIndex instead of | ||
* @param targetIndex | ||
*/ | ||
@@ -67,5 +66,29 @@ | ||
value: function originalIndexFor(targetIndex) { | ||
return this.originalIndexFromIndex(targetIndex); | ||
} | ||
/** | ||
* @deprecated use originalPositionFromPosition instead of | ||
* @param generatedPosition | ||
* @returns {Object} | ||
*/ | ||
}, { | ||
key: "originalPositionFor", | ||
value: function originalPositionFor(generatedPosition) { | ||
return this.originalPositionFromPosition(generatedPosition); | ||
} | ||
/** | ||
* Pass (generated)index value and return original index value. | ||
* @param {number} generatedIndex - position is a index value. | ||
* @returns {number|undefined} original | ||
*/ | ||
}, { | ||
key: "originalIndexFromIndex", | ||
value: function originalIndexFromIndex(generatedIndex) { | ||
var hitTokenMaps = this.tokenMaps.filter(function (tokenMap) { | ||
var generated = tokenMap.generated; | ||
if (generated[0] <= targetIndex && targetIndex < generated[1]) { | ||
if (generated[0] <= generatedIndex && generatedIndex < generated[1]) { | ||
return true; | ||
@@ -87,9 +110,16 @@ } | ||
// position-generated intermediate-origin | ||
var outAdjust = targetIndex - hitTokenMap.generated[0]; | ||
var outAdjust = generatedIndex - hitTokenMap.generated[0]; | ||
var inAdjust = hitTokenMap.intermediate[0] - hitTokenMap.original[0]; | ||
return outAdjust + inAdjust + hitTokenMap.original[0]; | ||
} | ||
/** | ||
* Pass generated position and return original position. | ||
* @param {object} position | ||
* @returns {object} original position | ||
*/ | ||
}, { | ||
key: "originalPositionFor", | ||
value: function originalPositionFor(position) { | ||
key: "originalPositionFromPosition", | ||
value: function originalPositionFromPosition(position) { | ||
if (typeof position.line === "undefined" || typeof position.column === "undefined") { | ||
@@ -103,6 +133,18 @@ throw new Error("position.{line, column} should not undefined: " + JSON.stringify(position)); | ||
} | ||
var originalIndex = this.originalIndexFor(generatedIndex); | ||
var originalIndex = this.originalIndexFromIndex(generatedIndex); | ||
return this.originalSource.indexToPosition(originalIndex); | ||
} | ||
}, { | ||
key: "originalIndexFromPosition", | ||
value: function originalIndexFromPosition(generatedPosition) { | ||
var originalPosition = this.originalPositionFromPosition(generatedPosition); | ||
return this.originalSource.positionToIndex(originalPosition); | ||
} | ||
}, { | ||
key: "originalPositionFromIndex", | ||
value: function originalPositionFromIndex(generatedIndex) { | ||
var originalIndex = this.originalIndexFromIndex(generatedIndex); | ||
return this.originalSource.indexToPosition(originalIndex); | ||
} | ||
}, { | ||
key: "isParagraphNode", | ||
@@ -165,3 +207,5 @@ value: function isParagraphNode(node) { | ||
var rawValue = container.raw; | ||
var paddingLeft = rawValue.indexOf(value, 1); // avoid match ! with ![ | ||
// avoid match ! with ![ | ||
// TODO: indexOf(value, 1) 1 is unexpected ... | ||
var paddingLeft = rawValue.indexOf(value, 1); | ||
var paddingRight = rawValue.length - (paddingLeft + value.length); | ||
@@ -168,0 +212,0 @@ // original range should be relative value from rootNode |
@@ -14,3 +14,3 @@ { | ||
}, | ||
"version": "1.1.1", | ||
"version": "1.2.0", | ||
"description": "textlint util convert Paragraph Node to text with SourceMap.", | ||
@@ -17,0 +17,0 @@ "main": "lib/StringSource.js", |
@@ -21,6 +21,6 @@ // LICENSE : MIT | ||
original : [start, end] | ||
// trim value from Original = intermediate | ||
// intermediate = trim decoration from Original | ||
// e.g.) [2, 5] | ||
intermediate: [start, end] | ||
// actual value = Str | ||
// generaged value = "Str" | ||
// e.g.) [0, 3] | ||
@@ -37,10 +37,27 @@ generated : [start, end] | ||
/** | ||
* Pass index value and return original index value. | ||
* @param {number} targetIndex - position is a index value. | ||
* @deprecated use originalIndexFromIndex instead of | ||
* @param targetIndex | ||
*/ | ||
originalIndexFor(targetIndex) { | ||
return this.originalIndexFromIndex(targetIndex); | ||
} | ||
/** | ||
* @deprecated use originalPositionFromPosition instead of | ||
* @param generatedPosition | ||
* @returns {Object} | ||
*/ | ||
originalPositionFor(generatedPosition) { | ||
return this.originalPositionFromPosition(generatedPosition); | ||
} | ||
/** | ||
* Pass (generated)index value and return original index value. | ||
* @param {number} generatedIndex - position is a index value. | ||
* @returns {number|undefined} original | ||
*/ | ||
originalIndexFor(targetIndex) { | ||
originalIndexFromIndex(generatedIndex) { | ||
let hitTokenMaps = this.tokenMaps.filter(tokenMap => { | ||
let generated = tokenMap.generated; | ||
if (generated[0] <= targetIndex && targetIndex < generated[1]) { | ||
if (generated[0] <= generatedIndex && generatedIndex < generated[1]) { | ||
return true; | ||
@@ -62,3 +79,3 @@ } | ||
// position-generated intermediate-origin | ||
let outAdjust = targetIndex - hitTokenMap.generated[0]; | ||
let outAdjust = generatedIndex - hitTokenMap.generated[0]; | ||
let inAdjust = hitTokenMap.intermediate[0] - hitTokenMap.original[0]; | ||
@@ -68,3 +85,8 @@ return outAdjust + inAdjust + hitTokenMap.original[0]; | ||
originalPositionFor(position) { | ||
/** | ||
* Pass generated position and return original position. | ||
* @param {object} position | ||
* @returns {object} original position | ||
*/ | ||
originalPositionFromPosition(position) { | ||
if (typeof position.line === "undefined" || typeof position.column === "undefined") { | ||
@@ -78,7 +100,17 @@ throw new Error("position.{line, column} should not undefined: " + JSON.stringify(position)); | ||
} | ||
let originalIndex = this.originalIndexFor(generatedIndex); | ||
let originalIndex = this.originalIndexFromIndex(generatedIndex); | ||
return this.originalSource.indexToPosition(originalIndex); | ||
} | ||
originalIndexFromPosition(generatedPosition) { | ||
const originalPosition = this.originalPositionFromPosition(generatedPosition); | ||
return this.originalSource.positionToIndex(originalPosition); | ||
} | ||
originalPositionFromIndex(generatedIndex) { | ||
let originalIndex = this.originalIndexFromIndex(generatedIndex); | ||
return this.originalSource.indexToPosition(originalIndex); | ||
} | ||
isParagraphNode(node) { | ||
@@ -140,3 +172,5 @@ return node.type === "Paragraph"; | ||
let rawValue = container.raw; | ||
let paddingLeft = rawValue.indexOf(value, 1); // avoid match ! with ![ | ||
// avoid match ! with ![ | ||
// TODO: indexOf(value, 1) 1 is unexpected ... | ||
let paddingLeft = rawValue.indexOf(value, 1); | ||
let paddingRight = rawValue.length - (paddingLeft + value.length); | ||
@@ -196,2 +230,2 @@ // original range should be relative value from rootNode | ||
} | ||
} | ||
} |
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
33321
448