New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

textlint-util-to-string

Package Overview
Dependencies
Maintainers
1
Versions
18
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

textlint-util-to-string - npm Package Compare versions

Comparing version 1.1.0 to 1.1.1

16

lib/StringSource.js

@@ -124,2 +124,8 @@ // LICENSE : MIT

}, {
key: "_nodeRangeAsRelative",
value: function _nodeRangeAsRelative(node) {
// relative from root
return [node.range[0] - this.rootNode.range[0], node.range[1] - this.rootNode.range[0]];
}
}, {
key: "_valueOf",

@@ -144,4 +150,4 @@ value: function _valueOf(node, parent) {

return {
original: node.range,
intermediate: node.range,
original: this._nodeRangeAsRelative(node),
intermediate: this._nodeRangeAsRelative(node),
value: value

@@ -158,3 +164,4 @@ };

var paddingRight = rawValue.length - (paddingLeft + value.length);
var originalRange = container.range;
// original range should be relative value from rootNode
var originalRange = this._nodeRangeAsRelative(container);
var intermediateRange = [originalRange[0] + paddingLeft, originalRange[1] - paddingRight];

@@ -186,3 +193,3 @@ return {

/**
* Returns the text content of a node. If the node itself
* Compute text content of a node. If the node itself
* does not expose plain-text fields, `toString` will

@@ -193,3 +200,2 @@ * recursivly try its children.

* @param {Node} [parent] - Parent Node of the `node`.
* @return {string} - Textual representation.
*/

@@ -196,0 +202,0 @@

@@ -14,3 +14,3 @@ {

},
"version": "1.1.0",
"version": "1.1.1",
"description": "textlint util convert Paragraph Node to text with SourceMap.",

@@ -37,3 +37,4 @@ "main": "lib/StringSource.js",

"mocha": "^2.3.4",
"power-assert": "^1.2.0"
"power-assert": "^1.2.0",
"sentence-splitter": "^1.2.0"
},

@@ -40,0 +41,0 @@ "dependencies": {

@@ -5,2 +5,4 @@ # textlint-util-to-string

SourceMap mean that could revert `position` in plain text to `position` in Node.
This library is for [textlint](https://github.com/textlint/textlint "textlint") and [textstat](https://github.com/azu/textstat "textstat").

@@ -14,2 +16,16 @@

### `Constructor(rootNode): source`
Return instance of Source.
### `source.originalIndexFor(generatedIndex): number`
Return original index of the `generatedIndex`.
### `source.originalPositionFor(generatedPosition): position`
`position` is a object that has `line` and `column` properties.
Return original position object of `generatedPosition`
```js

@@ -29,3 +45,10 @@ import assert from "power-assert"

// originalText[9];// "E"
assert.equal(source.originalPositionFor(index1), 9);
assert.equal(source.originalIndexFor(index1), 9);
assert.deepEqual(source.originalPositionFor({
line: 1,
column:8
}), {
line: 1,
column: 9
);
let index2 = result.indexOf("!?");

@@ -35,5 +58,20 @@ assert.equal(index2, 15);

// originalText[16];// "!"
assert.equal(source.originalPositionFor(index2), 16);
assert.equal(source.originalIndexFor(index2), 16);
```
## FAQ
### Why return relative position from rootNode?
```js
let AST = ....
let rootNode = AST.children[10];
let source = new StringSource(rootNode);
source.originalIndexFor(0); // should be 0
```
To return relative position easy to compute position(We think).
One space has a single absolute position, The other should be relative position.
## Tests

@@ -40,0 +78,0 @@

@@ -97,2 +97,10 @@ // LICENSE : MIT

_nodeRangeAsRelative(node) {
// relative from root
return [
node.range[0] - this.rootNode.range[0],
node.range[1] - this.rootNode.range[0]
]
}
_valueOf(node, parent) {

@@ -117,4 +125,4 @@ if (!node) {

return {
original: node.range,
intermediate: node.range,
original: this._nodeRangeAsRelative(node),
intermediate: this._nodeRangeAsRelative(node),
value: value

@@ -131,3 +139,4 @@ };

let paddingRight = rawValue.length - (paddingLeft + value.length);
let originalRange = container.range;
// original range should be relative value from rootNode
let originalRange = this._nodeRangeAsRelative(container);
let intermediateRange = [

@@ -162,3 +171,3 @@ originalRange[0] + paddingLeft,

/**
* Returns the text content of a node. If the node itself
* Compute text content of a node. If the node itself
* does not expose plain-text fields, `toString` will

@@ -169,3 +178,2 @@ * recursivly try its children.

* @param {Node} [parent] - Parent Node of the `node`.
* @return {string} - Textual representation.
*/

@@ -172,0 +180,0 @@ _stringify(node, parent) {

Sorry, the diff of this file is not supported yet

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