Software zum Installieren eines Smart-Mirror Frameworks , zum Nutzen von hochschulrelevanten Informationen, auf einem Raspberry-Pi.
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.

readme.md 5.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. # unist-util-is
  2. [![Build][build-badge]][build]
  3. [![Coverage][coverage-badge]][coverage]
  4. [![Downloads][downloads-badge]][downloads]
  5. [![Size][size-badge]][size]
  6. [![Sponsors][sponsors-badge]][collective]
  7. [![Backers][backers-badge]][collective]
  8. [![Chat][chat-badge]][chat]
  9. [**unist**][unist] utility to check if a node passes a test.
  10. ## Install
  11. [npm][]:
  12. ```sh
  13. npm install unist-util-is
  14. ```
  15. ## Use
  16. ```js
  17. var is = require('unist-util-is')
  18. var node = {type: 'strong'}
  19. var parent = {type: 'paragraph', children: [node]}
  20. function test(node, n) {
  21. return n === 5
  22. }
  23. is() // => false
  24. is({children: []}) // => false
  25. is(node) // => true
  26. is(node, 'strong') // => true
  27. is(node, 'emphasis') // => false
  28. is(node, node) // => true
  29. is(parent, {type: 'paragraph'}) // => true
  30. is(parent, {type: 'strong'}) // => false
  31. is(node, test) // => false
  32. is(node, test, 4, parent) // => false
  33. is(node, test, 5, parent) // => true
  34. ```
  35. ## API
  36. ### `is(node[, test[, index, parent[, context]]])`
  37. ###### Parameters
  38. * `node` ([`Node`][node]) — Node to check.
  39. * `test` ([`Function`][test], `string`, `Object`, or `Array.<Test>`, optional)
  40. — When nullish, checks if `node` is a [`Node`][node].
  41. When `string`, works like passing `node => node.type === test`.
  42. When `array`, checks if any one of the subtests pass.
  43. When `object`, checks that all keys in `test` are in `node`,
  44. and that they have strictly equal values
  45. * `index` (`number`, optional) — [Index][] of `node` in `parent`
  46. * `parent` ([`Node`][node], optional) — [Parent][] of `node`
  47. * `context` (`*`, optional) — Context object to invoke `test` with
  48. ###### Returns
  49. `boolean` — Whether `test` passed *and* `node` is a [`Node`][node] (object with
  50. `type` set to a non-empty `string`).
  51. #### `function test(node[, index, parent])`
  52. ###### Parameters
  53. * `node` ([`Node`][node]) — Node to check
  54. * `index` (`number?`) — [Index][] of `node` in `parent`
  55. * `parent` ([`Node?`][node]) — [Parent][] of `node`
  56. ###### Context
  57. `*` — The to `is` given `context`.
  58. ###### Returns
  59. `boolean?` — Whether `node` matches.
  60. ### `is.convert(test)`
  61. Create a test function from `test`, that can later be called with a `node`,
  62. `index`, and `parent`.
  63. Useful if you’re going to test many nodes, for example when creating a utility
  64. where something else passes an is-compatible test.
  65. The created function is slightly faster because it expects valid input only.
  66. Therefore, passing invalid input, yields unexpected results.
  67. Can also be accessed with `require('unist-util-is/convert')`.
  68. For example:
  69. ```js
  70. var u = require('unist-builder')
  71. var convert = require('unist-util-is/convert')
  72. var test = convert('leaf')
  73. var tree = u('tree', [
  74. u('node', [u('leaf', '1')]),
  75. u('leaf', '2'),
  76. u('node', [u('leaf', '3'), u('leaf', '4')]),
  77. u('leaf', '5')
  78. ])
  79. var leafs = tree.children.filter((child, index) => test(child, index, tree))
  80. console.log(leafs)
  81. ```
  82. Yields:
  83. ```js
  84. [{type: 'leaf', value: '2'}, {type: 'leaf', value: '5'}]
  85. ```
  86. ## Related
  87. * [`unist-util-find-after`](https://github.com/syntax-tree/unist-util-find-after)
  88. — Find a node after another node
  89. * [`unist-util-find-before`](https://github.com/syntax-tree/unist-util-find-before)
  90. — Find a node before another node
  91. * [`unist-util-find-all-after`](https://github.com/syntax-tree/unist-util-find-all-after)
  92. — Find all nodes after another node
  93. * [`unist-util-find-all-before`](https://github.com/syntax-tree/unist-util-find-all-before)
  94. — Find all nodes before another node
  95. * [`unist-util-find-all-between`](https://github.com/mrzmmr/unist-util-find-all-between)
  96. — Find all nodes between two nodes
  97. * [`unist-util-filter`](https://github.com/syntax-tree/unist-util-filter)
  98. — Create a new tree with nodes that pass a check
  99. * [`unist-util-remove`](https://github.com/syntax-tree/unist-util-remove)
  100. — Remove nodes from tree
  101. ## Contribute
  102. See [`contributing.md` in `syntax-tree/.github`][contributing] for ways to get
  103. started.
  104. See [`support.md`][support] for ways to get help.
  105. This project has a [code of conduct][coc].
  106. By interacting with this repository, organization, or community you agree to
  107. abide by its terms.
  108. ## License
  109. [MIT][license] © [Titus Wormer][author]
  110. <!-- Definitions -->
  111. [build-badge]: https://github.com/syntax-tree/unist-util-is/workflows/main/badge.svg
  112. [build]: https://github.com/syntax-tree/unist-util-is/actions
  113. [coverage-badge]: https://img.shields.io/codecov/c/github/syntax-tree/unist-util-is.svg
  114. [coverage]: https://codecov.io/github/syntax-tree/unist-util-is
  115. [downloads-badge]: https://img.shields.io/npm/dm/unist-util-is.svg
  116. [downloads]: https://www.npmjs.com/package/unist-util-is
  117. [size-badge]: https://img.shields.io/bundlephobia/minzip/unist-util-is.svg
  118. [size]: https://bundlephobia.com/result?p=unist-util-is
  119. [sponsors-badge]: https://opencollective.com/unified/sponsors/badge.svg
  120. [backers-badge]: https://opencollective.com/unified/backers/badge.svg
  121. [collective]: https://opencollective.com/unified
  122. [chat-badge]: https://img.shields.io/badge/chat-discussions-success.svg
  123. [chat]: https://github.com/syntax-tree/unist/discussions
  124. [npm]: https://docs.npmjs.com/cli/install
  125. [license]: license
  126. [author]: https://wooorm.com
  127. [contributing]: https://github.com/syntax-tree/.github/blob/HEAD/contributing.md
  128. [support]: https://github.com/syntax-tree/.github/blob/HEAD/support.md
  129. [coc]: https://github.com/syntax-tree/.github/blob/HEAD/code-of-conduct.md
  130. [unist]: https://github.com/syntax-tree/unist
  131. [node]: https://github.com/syntax-tree/unist#node
  132. [parent]: https://github.com/syntax-tree/unist#parent-1
  133. [index]: https://github.com/syntax-tree/unist#index
  134. [test]: #function-testnode-index-parent