mdast-util-to-string
Advanced tools
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 |
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
No bug tracker
MaintenancePackage does not have a linked bug tracker in package.json.
Found 1 instance in 1 package
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
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
No bug tracker
MaintenancePackage does not have a linked bug tracker in package.json.
Found 1 instance in 1 package
7
5316
1
4
19
73
1
+ Addedeslint-plugin-ava@^4.2.0
+ Added@eslint-community/eslint-utils@4.4.1(transitive)
+ Added@eslint-community/regexpp@4.12.1(transitive)
+ Added@eslint/config-array@0.18.0(transitive)
+ Added@eslint/core@0.7.0(transitive)
+ Added@eslint/eslintrc@3.1.0(transitive)
+ Added@eslint/js@9.14.0(transitive)
+ Added@eslint/object-schema@2.1.4(transitive)
+ Added@eslint/plugin-kit@0.2.2(transitive)
+ Added@humanfs/core@0.19.1(transitive)
+ Added@humanfs/node@0.16.6(transitive)
+ Added@humanwhocodes/module-importer@1.0.1(transitive)
+ Added@humanwhocodes/retry@0.3.10.4.1(transitive)
+ Added@types/estree@1.0.6(transitive)
+ Added@types/json-schema@7.0.15(transitive)
+ Addedacorn@3.3.05.7.48.14.0(transitive)
+ Addedacorn-jsx@3.0.15.3.2(transitive)
+ Addedajv@6.12.6(transitive)
+ Addedansi-styles@4.3.0(transitive)
+ Addedargparse@2.0.1(transitive)
+ Addedarray-differ@1.0.0(transitive)
+ Addedarray-union@1.0.2(transitive)
+ Addedarray-uniq@1.0.3(transitive)
+ Addedarrify@1.0.1(transitive)
+ Addedbalanced-match@1.0.2(transitive)
+ Addedbrace-expansion@1.1.11(transitive)
+ Addedbuf-compare@1.0.1(transitive)
+ Addedcallsites@3.1.0(transitive)
+ Addedchalk@4.1.2(transitive)
+ Addedcolor-convert@2.0.1(transitive)
+ Addedcolor-name@1.1.4(transitive)
+ Addedconcat-map@0.0.1(transitive)
+ Addedcore-assert@0.2.1(transitive)
+ Addedcore-js@2.6.12(transitive)
+ Addedcross-spawn@7.0.5(transitive)
+ Addeddebug@4.3.7(transitive)
+ Addeddeep-is@0.1.4(transitive)
+ Addeddeep-strict-equal@0.2.0(transitive)
+ Addedenhance-visitors@1.0.0(transitive)
+ Addedescape-string-regexp@4.0.0(transitive)
+ Addedeslint@9.14.0(transitive)
+ Addedeslint-plugin-ava@4.5.1(transitive)
+ Addedeslint-scope@8.2.0(transitive)
+ Addedeslint-visitor-keys@3.4.34.2.0(transitive)
+ Addedespree@10.3.03.5.4(transitive)
+ Addedespurify@1.8.1(transitive)
+ Addedesquery@1.6.0(transitive)
+ Addedesrecurse@4.3.0(transitive)
+ Addedestraverse@5.3.0(transitive)
+ Addedesutils@2.0.3(transitive)
+ Addedfast-deep-equal@3.1.3(transitive)
+ Addedfast-json-stable-stringify@2.1.0(transitive)
+ Addedfast-levenshtein@2.0.6(transitive)
+ Addedfile-entry-cache@8.0.0(transitive)
+ Addedfind-up@2.1.05.0.0(transitive)
+ Addedflat-cache@4.0.1(transitive)
+ Addedflatted@3.3.1(transitive)
+ Addedglob-parent@6.0.2(transitive)
+ Addedglobals@14.0.0(transitive)
+ Addedhas-flag@4.0.0(transitive)
+ Addedignore@5.3.2(transitive)
+ Addedimport-fresh@3.3.0(transitive)
+ Addedimport-modules@1.1.0(transitive)
+ Addedimurmurhash@0.1.4(transitive)
+ Addedis-error@2.2.2(transitive)
+ Addedis-extglob@2.1.1(transitive)
+ Addedis-glob@4.0.3(transitive)
+ Addedisexe@2.0.0(transitive)
+ Addedjs-yaml@4.1.0(transitive)
+ Addedjson-buffer@3.0.1(transitive)
+ Addedjson-schema-traverse@0.4.1(transitive)
+ Addedjson-stable-stringify-without-jsonify@1.0.1(transitive)
+ Addedkeyv@4.5.4(transitive)
+ Addedlevn@0.4.1(transitive)
+ Addedlocate-path@2.0.06.0.0(transitive)
+ Addedlodash@4.17.21(transitive)
+ Addedlodash.merge@4.6.2(transitive)
+ Addedminimatch@3.1.2(transitive)
+ Addedms@2.1.3(transitive)
+ Addedmultimatch@2.1.0(transitive)
+ Addednatural-compare@1.4.0(transitive)
+ Addedoptionator@0.9.4(transitive)
+ Addedp-limit@1.3.03.1.0(transitive)
+ Addedp-locate@2.0.05.0.0(transitive)
+ Addedp-try@1.0.0(transitive)
+ Addedparent-module@1.0.1(transitive)
+ Addedpath-exists@3.0.04.0.0(transitive)
+ Addedpath-key@3.1.1(transitive)
+ Addedpkg-up@2.0.0(transitive)
+ Addedprelude-ls@1.2.1(transitive)
+ Addedpunycode@2.3.1(transitive)
+ Addedresolve-from@4.0.0(transitive)
+ Addedshebang-command@2.0.0(transitive)
+ Addedshebang-regex@3.0.0(transitive)
+ Addedstrip-json-comments@3.1.1(transitive)
+ Addedsupports-color@7.2.0(transitive)
+ Addedtext-table@0.2.0(transitive)
+ Addedtype-check@0.4.0(transitive)
+ Addeduri-js@4.4.1(transitive)
+ Addedwhich@2.0.2(transitive)
+ Addedword-wrap@1.2.5(transitive)
+ Addedyocto-queue@0.1.0(transitive)