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

mdast-util-to-string

Package Overview
Dependencies
Maintainers
1
Versions
17
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

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

Comparing version 1.0.2 to 1.0.3

52

index.js

@@ -1,44 +0,22 @@

/**
* @author Titus Wormer
* @copyright 2015 Titus Wormer
* @license MIT
* @module mdast:util:to-string
* @fileoverview Utility to get the plain text content of a node.
*/
'use strict';
/* eslint-env node */
/* Expose. */
module.exports = toString;
/**
* Get the value of `node`. Checks, `value`,
* `alt`, and `title`, in that order.
*
* @param {Node} node - Node to get the internal value of.
* @return {string} - Textual representation.
*/
function valueOf(node) {
return node &&
(node.value ? node.value :
(node.alt ? node.alt : node.title)) || '';
}
/**
* Returns the text content of a node. If the node itself
/* Get the text content of a node. If the node itself
* does not expose plain-text fields, `toString` will
* recursivly try its children.
*
* @param {Node} node - Node to transform to a string.
* @return {string} - Textual representation.
*/
* recursivly try its children. */
function toString(node) {
return valueOf(node) ||
(node.children && node.children.map(toString).join('')) ||
'';
return valueOf(node) ||
(node.children && node.children.map(toString).join('')) ||
'';
}
/*
* Expose.
*/
module.exports = toString;
/* Get the value of `node`. Checks, `value`,
* `alt`, and `title`, in that order. */
function valueOf(node) {
if (!node) {
return '';
}
return node.value ? node.value : (node.alt ? node.alt : node.title) || '';
}
{
"name": "mdast-util-to-string",
"version": "1.0.2",
"version": "1.0.3",
"description": "Utility to get the plain text content of a node",

@@ -15,7 +15,4 @@ "license": "MIT",

],
"repository": {
"type": "git",
"url": "https://github.com/wooorm/mdast-util-to-string.git"
},
"bugs": "https://github.com/wooorm/mdast-util-to-string/issues",
"repository": "https://github.com/syntax-tree/mdast-util-to-string",
"bugs": "https://github.com/syntax-tree/mdast-util-to-string/issues",
"author": "Titus Wormer <tituswormer@gmail.com> (http://wooorm.com)",

@@ -28,30 +25,42 @@ "contributors": [

],
"dependencies": {},
"dependencies": {
"eslint-plugin-ava": "^4.2.0"
},
"devDependencies": {
"browserify": "^13.0.0",
"eslint": "^2.0.0",
"browserify": "^14.0.0",
"esmangle": "^1.0.0",
"istanbul": "^0.4.0",
"jscs": "^3.0.0",
"jscs-jsdoc": "^2.0.0",
"remark-cli": "^1.0.0",
"remark-comment-config": "^4.0.0",
"remark-github": "^5.0.0",
"remark-lint": "^4.0.0",
"remark-slug": "^4.0.0",
"remark-validate-links": "^4.0.0",
"tape": "^4.4.0"
"nyc": "^11.0.0",
"remark-cli": "^3.0.0",
"remark-preset-wooorm": "^3.0.0",
"tape": "^4.4.0",
"xo": "^0.18.2"
},
"scripts": {
"build-md": "remark . --quiet --frail",
"build-md": "remark . --quiet --frail --output",
"build-bundle": "browserify index.js --no-builtins -s mdastUtilToString > mdast-util-to-string.js",
"build-mangle": "esmangle mdast-util-to-string.js > mdast-util-to-string.min.js",
"build": "npm run build-md && npm run build-bundle && npm run build-mangle",
"lint-api": "eslint .",
"lint-style": "jscs --reporter inline .",
"lint": "npm run lint-api && npm run lint-style",
"lint": "xo",
"test-api": "node test.js",
"test-coverage": "istanbul cover test.js",
"test-coverage": "nyc --reporter lcov tape test.js",
"test": "npm run build && npm run lint && npm run test-coverage"
},
"xo": {
"space": true,
"esnext": false,
"ignore": [
"mdast-util-to-string.js"
]
},
"nyc": {
"check-coverage": true,
"lines": 100,
"functions": 100,
"branches": 100
},
"remarkConfig": {
"plugins": [
"preset-wooorm"
]
}
}
# mdast-util-to-string [![Build Status][build-badge]][build-status] [![Coverage Status][coverage-badge]][coverage-status] [![Chat][chat-badge]][chat]
<!--lint disable list-item-spacing heading-increment list-item-indent-->
Get the plain text content of an [MDAST][] node.

@@ -15,27 +13,13 @@

**mdast-util-to-string** is also available as an AMD, CommonJS, and
globals module, [uncompressed and compressed][releases].
## Usage
Dependencies:
```js
var remark = require('remark');
var toString = require('mdast-util-to-string');
```
Parse:
var tree = remark().parse('Some _emphasis_, **importance**, and `code`.');
```js
var ast = remark().parse('Some *emphasis*, **strongness**, and `code`.');
console.log(toString(tree)); //=> 'Some emphasis, importance, and code.'
```
Stringify:
```js
toString(ast);
// 'Some emphasis, strongness, and code.'
```
## API

@@ -54,10 +38,11 @@

###### Parameters
## Related
* `node` ([`Node`][node]) — Node to stringify
* [`nlcst-to-string`](https://github.com/syntax-tree/nlcst-to-string)
— Get text content in NLCST
* [`hast-util-to-string`](https://github.com/wooorm/rehype-minify/tree/master/packages/hast-util-to-string)
— Get text content in HAST
* [`hast-util-from-string`](https://github.com/wooorm/rehype-minify/tree/master/packages/hast-util-from-string)
— Set text content in HAST
###### Returns
`string` — text representation of `node`.
## License

@@ -69,9 +54,9 @@

[build-badge]: https://img.shields.io/travis/wooorm/mdast-util-to-string.svg
[build-badge]: https://img.shields.io/travis/syntax-tree/mdast-util-to-string.svg
[build-status]: https://travis-ci.org/wooorm/mdast-util-to-string
[build-status]: https://travis-ci.org/syntax-tree/mdast-util-to-string
[coverage-badge]: https://img.shields.io/codecov/c/github/wooorm/mdast-util-to-string.svg
[coverage-badge]: https://img.shields.io/codecov/c/github/syntax-tree/mdast-util-to-string.svg
[coverage-status]: https://codecov.io/github/wooorm/mdast-util-to-string
[coverage-status]: https://codecov.io/github/syntax-tree/mdast-util-to-string

@@ -82,4 +67,2 @@ [chat-badge]: https://img.shields.io/gitter/room/wooorm/remark.svg

[releases]: https://github.com/wooorm/mdast-util-to-string/releases
[license]: LICENSE

@@ -91,6 +74,4 @@

[mdast]: https://github.com/wooorm/mdast
[mdast]: https://github.com/syntax-tree/mdast
[node]: https://github.com/wooorm/mdast#node
[strip-markdown]: https://github.com/wooorm/strip-markdown
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