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

hast-util-to-string

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

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

Comparing version 1.0.1 to 1.0.2

46

index.js
/**
* @fileoverview
* Get the plain-text value of a HAST node.
* Get the plain-text value of a hast node.
* @longdescription
* ## Usage
* ## Use
*
* ```javascript
* var h = require('hastscript');
* var toString = require('hast-util-to-string');
* ```js
* var h = require('hastscript')
* var toString = require('hast-util-to-string')
*
* toString(h('p', 'Alpha'));
* toString(h('p', 'Alpha'))
* //=> 'Alpha'
* toString(h('div', [h('b', 'Bold'), ' and ', h('i', 'italic'), '.']));
* toString(h('div', [h('b', 'Bold'), ' and ', h('i', 'italic'), '.']))
* //=> 'Bold and italic.'

@@ -21,18 +21,18 @@ * ```

*
* Transform a node to string.
* Transform a node to a string.
*/
'use strict';
'use strict'
module.exports = toString;
module.exports = toString
function toString(node) {
/* “The concatenation of data of all the Text node descendants
* of the context object, in tree order.” */
// “The concatenation of data of all the Text node descendants of the context
// object, in tree order.”
if ('children' in node) {
return all(node);
return all(node)
}
/* “Context object’s data.” */
return 'value' in node ? node.value : '';
// “Context object’s data.”
return 'value' in node ? node.value : ''
}

@@ -42,19 +42,19 @@

if (node.type === 'text') {
return node.value;
return node.value
}
return node.children ? all(node) : '';
return node.children ? all(node) : ''
}
function all(node) {
var children = node.children;
var length = children.length;
var index = -1;
var result = [];
var children = node.children
var length = children.length
var index = -1
var result = []
while (++index < length) {
result[index] = one(children[index]);
result[index] = one(children[index])
}
return result.join('');
return result.join('')
}
{
"name": "hast-util-to-string",
"version": "1.0.1",
"description": "Get the plain-text value of a node",
"version": "1.0.2",
"description": "hast utility to get the plain-text value of a node",
"license": "MIT",
"keywords": [
"unified",
"rehype",

@@ -11,5 +12,5 @@ "hast",

],
"repository": "https://github.com/wooorm/rehype-minify/tree/master/packages/hast-util-to-string",
"bugs": "https://github.com/wooorm/rehype-minify/issues",
"author": "Titus Wormer <tituswormer@gmail.com> (http://wooorm.com)",
"repository": "https://github.com/rehypejs/rehype-minify/tree/master/packages/hast-util-to-string",
"bugs": "https://github.com/rehypejs/rehype-minify/issues",
"author": "Titus Wormer <tituswormer@gmail.com> (https://wooorm.com)",
"contributors": [

@@ -16,0 +17,0 @@ "Titus Wormer <tituswormer@gmail.com>"

@@ -5,6 +5,16 @@ <!--This file is generated by `build-packages.js`-->

Get the plain-text value of a HAST node.
[![Build][build-badge]][build]
[![Coverage][coverage-badge]][coverage]
[![Downloads][downloads-badge]][downloads]
[![Size][size-badge]][size]
[![Sponsors][sponsors-badge]][collective]
[![Backers][backers-badge]][collective]
[![Chat][chat-badge]][chat]
Get the plain-text value of a hast node.
## Install
[npm][]:
```sh

@@ -14,11 +24,11 @@ npm install hast-util-to-string

## Usage
## Use
```javascript
var h = require('hastscript');
var toString = require('hast-util-to-string');
```js
var h = require('hastscript')
var toString = require('hast-util-to-string')
toString(h('p', 'Alpha'));
toString(h('p', 'Alpha'))
//=> 'Alpha'
toString(h('div', [h('b', 'Bold'), ' and ', h('i', 'italic'), '.']));
toString(h('div', [h('b', 'Bold'), ' and ', h('i', 'italic'), '.']))
//=> 'Bold and italic.'

@@ -31,6 +41,56 @@ ```

Transform a node to string.
Transform a node to a string.
## Contribute
See [`contributing.md`][contributing] in [`rehypejs/.github`][health] for ways
to get started.
See [`support.md`][support] for ways to get help.
This project has a [Code of Conduct][coc].
By interacting with this repository, organisation, or community you agree to
abide by its terms.
## License
[MIT](https://github.com/wooorm/rehype-minify/blob/master/LICENSE) © [Titus Wormer](http://wooorm.com)
[MIT][license] © [Titus Wormer][author]
[build-badge]: https://img.shields.io/travis/rehypejs/rehype-minify.svg
[build]: https://travis-ci.org/rehypejs/rehype-minify
[coverage-badge]: https://img.shields.io/codecov/c/github/rehypejs/rehype-minify.svg
[coverage]: https://codecov.io/github/rehypejs/rehype-minify
[downloads-badge]: https://img.shields.io/npm/dm/hast-util-to-string.svg
[downloads]: https://www.npmjs.com/package/hast-util-to-string
[size-badge]: https://img.shields.io/bundlephobia/minzip/hast-util-to-string.svg
[size]: https://bundlephobia.com/result?p=hast-util-to-string
[sponsors-badge]: https://opencollective.com/unified/sponsors/badge.svg
[backers-badge]: https://opencollective.com/unified/backers/badge.svg
[collective]: https://opencollective.com/unified
[chat-badge]: https://img.shields.io/badge/join%20the%20community-on%20spectrum-7b16ff.svg
[chat]: https://spectrum.chat/unified/syntax-tree
[npm]: https://docs.npmjs.com/cli/install
[health]: https://github.com/rehypejs/.github
[contributing]: https://github.com/rehypejs/.github/blob/master/contributing.md
[support]: https://github.com/rehypejs/.github/blob/master/support.md
[coc]: https://github.com/rehypejs/.github/blob/master/code-of-conduct.md
[license]: https://github.com/rehypejs/rehype-minify/blob/master/license
[author]: https://wooorm.com
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