Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: syntax-tree/unist-util-find
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 42bfcad402ba9ecaf1ac0f37db79b884800aea57
Choose a base ref
...
head repository: syntax-tree/unist-util-find
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 1200bf5c26af3dc2cf95b7534ed500220ce30959
Choose a head ref
  • 4 commits
  • 4 files changed
  • 3 contributors

Commits on Jun 30, 2016

  1. Also change title!

    blahah committed Jun 30, 2016
    Copy the full SHA
    edcce50 View commit details

Commits on Feb 27, 2017

  1. Update docs, dev-dependencies

    wooorm committed Feb 27, 2017

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    bb3a7f1 View commit details
  2. Merge pull request #1 from blahah/ch-ch-changes

    Update docs, dev-dependencies
    Richard Smith-Unna authored Feb 27, 2017

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    f7fb623 View commit details

Commits on Nov 10, 2020

  1. Release v1.0.2.

    Rik Smith-Unna committed Nov 10, 2020
    Copy the full SHA
    1200bf5 View commit details
Showing with 36 additions and 40 deletions.
  1. +2 −2 README.md
  2. +1 −1 example.js
  3. +3 −3 package.json
  4. +30 −34 test.js
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# unist-find [![Travis](https://img.shields.io/travis/blahah/unist-util-find.svg)](https://travis-ci.org/blahah/unist-util-find)
# unist-util-find [![Travis](https://img.shields.io/travis/blahah/unist-util-find.svg)](https://travis-ci.org/blahah/unist-util-find)

[Unist](https://github.com/wooorm/unist) node finder utility. Useful for working with [remark](https://github.com/wooorm/remark), [rehype](https://github.com/wooorm/rehype) and [retext](https://github.com/wooorm/retext).

@@ -31,7 +31,7 @@ remark()
}))
}
})
.process('Some _emphasis_, **strongness**, and `code`.')
.processSync('Some _emphasis_, **strongness**, and `code`.')

```

2 changes: 1 addition & 1 deletion example.js
Original file line number Diff line number Diff line change
@@ -16,4 +16,4 @@ remark()
}))
}
})
.process('Some _emphasis_, **strongness**, and `code`.')
.processSync('Some _emphasis_, **strongness**, and `code`.')
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "unist-util-find",
"version": "1.0.1",
"version": "1.0.2",
"description": "Unist node finder utility. Useful for working with remark, rehype and retext.",
"repository": "https://github.com/blahah/unist-util-find",
"main": "index.js",
@@ -21,12 +21,12 @@
"author": "Richard Smith-Unna <rik@fathomlabs.io> @blahah",
"license": "MIT",
"devDependencies": {
"standard": "^7.1.2",
"remark": "^7.0.0",
"standard": "^8.0.0",
"tape": "^4.6.0"
},
"dependencies": {
"lodash.iteratee": "^4.5.0",
"remark": "^5.0.1",
"unist-util-visit": "^1.1.0"
}
}
64 changes: 30 additions & 34 deletions test.js
Original file line number Diff line number Diff line change
@@ -2,52 +2,48 @@ var test = require('tape')
var remark = require('remark')
var find = require('./index.js')

remark()
.use(function () { return run })
.process('Some _emphasis_, **strongness**, and `code`.')
test('unist-find', function (t) {
var tree = remark().parse('Some _emphasis_, **strongness**, and `code`.')

function run (tree) {
test('unist-find', function (t) {
t.throws(function () {
find()
}, 'should fail without tree')
t.throws(function () {
find()
}, 'should fail without tree')

t.throws(function () {
find(tree)
}, 'should fail without condition')
t.throws(function () {
find(tree)
}, 'should fail without condition')

t.test('should find with string condition', function (st) {
var result = find(tree, 'value')
t.test('should find with string condition', function (st) {
var result = find(tree, 'value')

st.equal(result, tree.children[0].children[0])
st.equal(result, tree.children[0].children[0])

st.end()
})
st.end()
})

t.test('should find with object condition', function (st) {
var result = find(tree, { type: 'emphasis' })
t.test('should find with object condition', function (st) {
var result = find(tree, { type: 'emphasis' })

st.equal(result, tree.children[0].children[1])
st.equal(result, tree.children[0].children[1])

st.end()
})
st.end()
})

t.test('should find with function condition', function (st) {
var result = find(tree, function (node) {
return node.type === 'inlineCode'
})
t.test('should find with function condition', function (st) {
var result = find(tree, function (node) {
return node.type === 'inlineCode'
})

st.equal(result, tree.children[0].children[5])
st.equal(result, tree.children[0].children[5])

st.end()
})
st.end()
})

t.test('should return undefined if no matches', function (st) {
var result = find(tree, 'nope, nope, nope')
t.test('should return undefined if no matches', function (st) {
var result = find(tree, 'nope, nope, nope')

st.equal(result, undefined)
st.equal(result, undefined)

st.end()
})
st.end()
})
}
})