Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

textlint-util-to-string

Package Overview
Dependencies
Maintainers
3
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 3.3.2 to 3.3.3

25

dist/StringSource.d.ts

@@ -1,2 +0,2 @@

import type { TxtNode, TxtParentNode } from "@textlint/ast-node-types";
import type { TxtNode, TxtNodeLocation, TxtNodeRange } from "@textlint/ast-node-types";
import { SourcePosition } from "structured-source";

@@ -13,5 +13,24 @@ import type { Node as UnistNode } from "unist";

};
export type StringSourceTxtParentNodeLikeNode = TxtParentNode | (Omit<TxtParentNode, "type"> & {
/**
* TxtTxtNode-like definition
* It is intentionally loose definition to accept sentences-splitter's node and unist node.
*/
export type StringSourceTxtTxtNode = {
type: string;
});
raw: string;
range: TxtNodeRange;
loc: TxtNodeLocation;
value?: string | null | undefined;
};
/**
* TxtParentNode-like definition
* It is intentionally loose definition to accept sentences-splitter's node and unist node.
*/
export type StringSourceTxtParentNodeLikeNode = {
type: string;
raw: string;
range: TxtNodeRange;
loc: TxtNodeLocation;
children: (StringSourceTxtTxtNode | StringSourceTxtParentNodeLikeNode)[];
};
export declare class StringSource {

@@ -18,0 +37,0 @@ private rootNode;

18

package.json
{
"name": "textlint-util-to-string",
"version": "3.3.2",
"version": "3.3.3",
"description": "textlint utility that convert Paragraph Node to text with SourceMap.",

@@ -37,3 +37,3 @@ "homepage": "https://github.com/textlint/textlint-util-to-string",

"dependencies": {
"@textlint/ast-node-types": "^13.0.5",
"@textlint/ast-node-types": "^13.4.1",
"rehype-parse": "^6.0.1",

@@ -44,14 +44,14 @@ "structured-source": "^4.0.0",

"devDependencies": {
"@textlint/markdown-to-ast": "^13.2.0",
"@types/mocha": "^10.0.1",
"@types/node": "^18.11.18",
"@textlint/markdown-to-ast": "^13.4.1",
"@types/mocha": "^10.0.6",
"@types/node": "^20.10.0",
"cross-env": "^7.0.3",
"lint-staged": "^13.1.0",
"lint-staged": "^15.1.0",
"microbundle": "^0.15.1",
"mocha": "^10.2.0",
"prettier": "^2.8.3",
"sentence-splitter": "^4.1.0",
"prettier": "^3.1.0",
"sentence-splitter": "^5.0.0",
"ts-node": "^10.9.1",
"ts-node-test-register": "^10.0.0",
"typescript": "^4.9.4"
"typescript": "^5.3.2"
},

@@ -58,0 +58,0 @@ "email": "azuciao@gmail.com",

@@ -158,5 +158,5 @@ # textlint-util-to-string [![Actions Status: test](https://github.com/textlint/textlint-util-to-string/workflows/test/badge.svg)](https://github.com/textlint/textlint-util-to-string/actions?query=workflow%3A"test")

- [azu/textlint-rule-first-sentence-length: textlint rule that limit maximum length of First sentence of the section.](https://github.com/azu/textlint-rule-first-sentence-length)
- [azu/textlint-rule-en-max-word-count: textlint rule that specify the maximum word count of a sentence.](https://github.com/azu/textlint-rule-en-max-word-count)
- [nodaguti/textlint-rule-spellchecker: textlint rule to check spellings with native spellchecker](https://github.com/nodaguti/textlint-rule-spellchecker)
- [textlint-rule-first-sentence-length: textlint rule that limit maximum length of First sentence of the section.](https://github.com/textlint-rule/textlint-rule-first-sentence-length)
- [textlint-rule-en-max-word-count: textlint rule that specify the maximum word count of a sentence.](https://github.com/textlint-rule/textlint-rule-en-max-word-count)
- [textlint-rule-spellchecker: textlint rule to check spellings with native spellchecker](https://github.com/nodaguti/textlint-rule-spellchecker)

@@ -179,2 +179,6 @@

## Related Libraries
- <https://github.com/textlint/textlint/wiki/Collection-of-textlint-rule#rule-libraries>
## Tests

@@ -181,0 +185,0 @@

@@ -37,3 +37,3 @@ import { TxtNode } from "@textlint/ast-node-types";

if (command.type === "StringSourceReplacerEmptyValueCommand") {
if (node.value === undefined) {
if (!("value" in node)) {
return node;

@@ -46,3 +46,3 @@ }

} else if (command.type === "StringSourceReplacerMaskValueCommand") {
if (node.value === undefined) {
if (!("value" in node) || typeof node.value !== "string") {
throw new Error(

@@ -49,0 +49,0 @@ `Can not masking. ${node.type} node does not have value property: ` + JSON.stringify(node, null, 4)

@@ -1,2 +0,2 @@

import type { TxtNode, TxtParentNode } from "@textlint/ast-node-types";
import type { TxtHtmlNode, TxtNode, TxtNodeLocation, TxtNodeRange } from "@textlint/ast-node-types";
import { SourcePosition, StructuredSource } from "structured-source";

@@ -12,3 +12,5 @@ import type { Node as UnistNode } from "unist";

};
const isHtmlNode = (node: StringSourceTxtParentNodeLikeNode | StringSourceTxtTxtNode): node is TxtHtmlNode => {
return node.type === "Html";
};
const htmlProcessor = unified().use(parse, { fragment: true });

@@ -19,3 +21,5 @@ const html2hast = (html: string) => {

const isParentNode = (node: TxtNode | StringSourceTxtParentNodeLikeNode): node is StringSourceTxtParentNodeLikeNode => {
const isParentNode = (
node: UnistNode | TxtNode | StringSourceTxtParentNodeLikeNode
): node is StringSourceTxtParentNodeLikeNode => {
return "children" in node;

@@ -58,3 +62,24 @@ };

};
export type StringSourceTxtParentNodeLikeNode = TxtParentNode | (Omit<TxtParentNode, "type"> & { type: string });
/**
* TxtTxtNode-like definition
* It is intentionally loose definition to accept sentences-splitter's node and unist node.
*/
export type StringSourceTxtTxtNode = {
type: string;
raw: string;
range: TxtNodeRange;
loc: TxtNodeLocation;
value?: string | null | undefined;
};
/**
* TxtParentNode-like definition
* It is intentionally loose definition to accept sentences-splitter's node and unist node.
*/
export type StringSourceTxtParentNodeLikeNode = {
type: string;
raw: string;
range: TxtNodeRange;
loc: TxtNodeLocation;
children: (StringSourceTxtTxtNode | StringSourceTxtParentNodeLikeNode)[];
};

@@ -224,7 +249,8 @@ export class StringSource {

private _getValue(node: TxtNode | UnistNode): string | undefined {
if (node.value) {
if ("value" in node && typeof node.value === "string") {
return node.value;
} else if (node.alt) {
} else if ("alt" in node && typeof node.alt === "string") {
return node.alt;
} else if (node.title) {
} else if ("title" in node) {
// Ignore link title e.g.) [text](url "title")
// See https://github.com/azu/textlint-rule-sentence-length/issues/6

@@ -234,2 +260,5 @@ if (node.type === "Link") {

}
if (typeof node.title !== "string") {
return;
}
return node.title;

@@ -338,8 +367,7 @@ } else {

}: {
node: TxtNode | StringSourceTxtParentNodeLikeNode;
node: StringSourceTxtParentNodeLikeNode | StringSourceTxtTxtNode;
parent?: StringSourceTxtParentNodeLikeNode;
options: StringSourceOptions;
}): void | StringSourceIR {
const isHTML = node.type === "Html";
const currentNode = isHTML ? html2hast(node.value) : node;
const currentNode = isHtmlNode(node) ? html2hast(node.value) : node;
const value = this._valueOf({ node: currentNode, parent: parent, options });

@@ -349,10 +377,14 @@ if (value) {

}
if (!isParentNode(node)) {
if (!isParentNode(currentNode)) {
return;
}
currentNode.children.forEach((childNode: TxtNode) => {
currentNode.children.forEach((childNode) => {
if (!isParentNode(node)) {
return;
}
const tokenMap = this._stringify({ node: childNode, parent: node, options });
const tokenMap = this._stringify({
node: childNode,
parent: node,
options
});
if (tokenMap) {

@@ -359,0 +391,0 @@ this._addTokenMap(tokenMap);

Sorry, the diff of this file is too big to display

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

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

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