mirror of https://github.com/lukechilds/node.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
42 lines
710 B
42 lines
710 B
/**
|
|
* @author Titus Wormer
|
|
* @copyright 2016 Titus Wormer
|
|
* @license MIT
|
|
* @module unist:util:remove-position
|
|
* @fileoverview Remove `position`s from a unist tree.
|
|
*/
|
|
|
|
'use strict';
|
|
|
|
/* eslint-env commonjs */
|
|
|
|
/* Dependencies. */
|
|
var visit = require('unist-util-visit');
|
|
|
|
/* Expose. */
|
|
module.exports = removePosition;
|
|
|
|
/**
|
|
* Remove `position`s from `tree`.
|
|
*
|
|
* @param {Node} tree - Node.
|
|
* @return {Node} - Node without `position`s.
|
|
*/
|
|
function removePosition(node, force) {
|
|
visit(node, force ? hard : soft);
|
|
return node;
|
|
}
|
|
|
|
/**
|
|
* Delete `position`.
|
|
*/
|
|
function hard(node) {
|
|
delete node.position;
|
|
}
|
|
|
|
/**
|
|
* Remove `position` softly.
|
|
*/
|
|
function soft(node) {
|
|
node.position = undefined;
|
|
}
|
|
|