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

mdast-range

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mdast-range - npm Package Compare versions

Comparing version 1.0.1 to 2.0.0

55

package.json
{
"name": "mdast-range",
"version": "1.0.1",
"description": "Patch index-based ranges on mdast nodes",
"license": "MIT",
"keywords": [
"range",
"location",
"position",
"node",
"mdast"
],
"dependencies": {
"unist-util-visit": "^1.0.0"
},
"repository": {
"type": "git",
"url": "https://github.com/wooorm/mdast-range.git"
},
"author": "Titus Wormer <tituswormer@gmail.com>",
"files": [
"index.js",
"LICENSE"
],
"devDependencies": {
"browserify": "^11.0.0",
"eslint": "^1.0.0",
"esmangle": "^1.0.0",
"istanbul": "^0.3.0",
"jscs": "^2.0.0",
"jscs-jsdoc": "^1.0.0",
"mdast": "^1.0.0",
"mdast-github": "^1.0.0",
"mdast-lint": "^1.0.0",
"mdast-toc": "^1.0.0",
"mdast-usage": "^1.0.0",
"mdast-comment-config": "^1.0.0",
"mocha": "^2.0.0"
},
"scripts": {
"test-api": "mocha --check-leaks test.js",
"test-coverage": "istanbul cover _mocha -- test.js",
"test-travis": "npm run test-coverage",
"test": "npm run test-api",
"lint-api": "eslint .",
"lint-style": "jscs --reporter inline .",
"lint": "npm run lint-api && npm run lint-style",
"make": "npm run lint && npm run test-coverage",
"bundle": "browserify --no-builtins index.js -s mdastRange > mdast-range.js",
"postbundle": "esmangle mdast-range.js > mdast-range.min.js",
"build-md": "mdast . --quiet",
"build": "npm run bundle && npm run build-md"
}
}
"version": "2.0.0",
"description": "Renamed to remark-range"
}

@@ -1,342 +0,3 @@

# mdast-range [![Build Status](https://img.shields.io/travis/wooorm/mdast-range.svg)](https://travis-ci.org/wooorm/mdast-range) [![Coverage Status](https://img.shields.io/codecov/c/github/wooorm/mdast-range.svg)](https://codecov.io/github/wooorm/mdast-range)
# mdast-range
Patch index-based ranges on **mdast** nodes, so you can slice sources!
## Installation
[npm](https://docs.npmjs.com/cli/install)
```bash
npm install mdast-range
```
[Component.js](https://github.com/componentjs/component)
```bash
component install wooorm/mdast-range
```
[Bower](http://bower.io/#install-packages)
```bash
bower install mdast-range
```
[Duo](http://duojs.org/#getting-started)
```javascript
var range = require('wooorm/mdast-range');
```
UMD: globals, AMD, and CommonJS ([uncompressed](mdast-range.js) and [compressed](mdast-range.min.js)):
```html
<script src="path/to/mdast.js"></script>
<script src="path/to/mdast-range.js"></script>
<script>
mdast.use(mdastRange);
</script>
```
## Table of Contents
* [Usage](#usage)
* [API](#api)
* [mdast.use(range)](#mdastuserange)
* [License](#license)
## Usage
Dependencies and input:
```javascript
var range = require('mdast-range');
var mdast = require('mdast').use(range);
var doc = 'Some *emphasis*,\n**strongness**,\nand `code`.';
```
And when the plugin is run, the ast looks as follows:
```javascript
mdast.process(doc);
```
Note the `offset` properties.
```json
{
"type": "root",
"children": [
{
"type": "paragraph",
"children": [
{
"type": "text",
"value": "Some ",
"position": {
"start": {
"line": 1,
"column": 1,
"offset": 0
},
"end": {
"line": 1,
"column": 6,
"offset": 5
},
"indent": []
}
},
{
"type": "emphasis",
"children": [
{
"type": "text",
"value": "emphasis",
"position": {
"start": {
"line": 1,
"column": 7,
"offset": 6
},
"end": {
"line": 1,
"column": 15,
"offset": 14
},
"indent": []
}
}
],
"position": {
"start": {
"line": 1,
"column": 6,
"offset": 5
},
"end": {
"line": 1,
"column": 16,
"offset": 15
},
"indent": []
}
},
{
"type": "text",
"value": ",\n",
"position": {
"start": {
"line": 1,
"column": 16,
"offset": 15
},
"end": {
"line": 2,
"column": 1,
"offset": 17
},
"indent": [
1
]
}
},
{
"type": "strong",
"children": [
{
"type": "text",
"value": "strongness",
"position": {
"start": {
"line": 2,
"column": 3,
"offset": 19
},
"end": {
"line": 2,
"column": 13,
"offset": 29
},
"indent": []
}
}
],
"position": {
"start": {
"line": 2,
"column": 1,
"offset": 17
},
"end": {
"line": 2,
"column": 15,
"offset": 31
},
"indent": []
}
},
{
"type": "text",
"value": ",\nand ",
"position": {
"start": {
"line": 2,
"column": 15,
"offset": 31
},
"end": {
"line": 3,
"column": 5,
"offset": 37
},
"indent": [
1
]
}
},
{
"type": "inlineCode",
"value": "code",
"position": {
"start": {
"line": 3,
"column": 5,
"offset": 37
},
"end": {
"line": 3,
"column": 11,
"offset": 43
},
"indent": []
}
},
{
"type": "text",
"value": ".",
"position": {
"start": {
"line": 3,
"column": 11,
"offset": 43
},
"end": {
"line": 3,
"column": 12,
"offset": 44
},
"indent": []
}
}
],
"position": {
"start": {
"line": 1,
"column": 1,
"offset": 0
},
"end": {
"line": 3,
"column": 12,
"offset": 44
},
"indent": [
1,
1
]
}
}
],
"position": {
"start": {
"line": 1,
"column": 1,
"offset": 0
},
"end": {
"line": 3,
"column": 12,
"offset": 44
}
}
}
```
## API
### [mdast](https://github.com/wooorm/mdast#api).[use](https://github.com/wooorm/mdast#mdastuseplugin-options)(range)
Adds `offset` to each node’s [**Position**](https://github.com/wooorm/mdast/blob/master/doc/Nodes.md#location).
Where normally nodes have a line based positional information, such as:
```json
{
"type": "break",
"position": {
"start": {
"line": 2,
"column": 5
},
"end": {
"line": 3,
"column": 1
}
}
}
```
...this plugin adds absolute positional information:
```json
{
"type": "break",
"position": {
"start": {
"line": 2,
"column": 5,
"offset": 25
},
"end": {
"line": 3,
"column": 1,
"offset": 26
}
}
}
```
...so you can slice (or syntax highlight) the source:
```javascript
var line = doc.slice(node.position.start.offset, node.position.end.offset);
// Yields: `"\n"`
```
To reverse an `offset` into a position, pass it into `file.offsetToPosition()`:
```javascript
mdast.use(range).process('foo', function (err, doc, file) {
file.offsetToPosition(0);
// Yields: `{line: 1, column: 1}`
});
```
To turn any position object, use `file.positionToOffset()`:
```javascript
mdast.use(range).process('foo', function (err, doc, file) {
var pos = file.offsetToPosition(0);
file.positionToOffset(pos);
// Yields: `0`.
});
```
## License
[MIT](LICENSE) © [Titus Wormer](http://wooorm.com)
Renamed to [remark-range](http://npmjs.com/remark-range).
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