1.0.2 • Published 10 months ago

@accuser/unist-util-flatmap v1.0.2

Weekly downloads
-
License
MIT
Repository
github
Last release
10 months ago

unist-util-flatmap

npm version

Create a new unist tree by mapping over all nodes and flattening the result without mutating the original tree.

Installation

npm install @accuser/unist-util-flatmap

Usage

import flatmap from '@accuser/unist-util-flatmap';

const tree = {
  type: 'root',
  children: [
	{
	  type: 'paragraph',
	  children: [
		{ type: 'text', value: 'Hello, World!' },
	  ]
	}
  ]
};

const result = flatmap(tree, (node) => {
  if (node.type === 'text') {
	return [
	  { type: 'text', value: node.value.toUpperCase() }
	];
  }

  return [node];
});

console.log(result);

Output:

{ type: 'root',	children: [{ type: 'paragraph',	children: [{ type: 'text', value: 'HELLO, WORLD!' }] }] }

Tests

npm test

License

MIT

1.0.2

10 months ago

1.0.1

10 months ago

1.0.0

10 months ago