forked from gaearon/react-devtools
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnodeMatchesText.js
More file actions
37 lines (34 loc) · 1.08 KB
/
nodeMatchesText.js
File metadata and controls
37 lines (34 loc) · 1.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
/**
* Copyright (c) 2015-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
* @flow
*/
'use strict';
import type {Map} from 'immutable';
import type Store from './Store';
function nodeMatchesText(node: Map, needle: string, key: string, store: Store): boolean {
var name = node.get('name');
if (node.get('nodeType') === 'Native' && store.get(store.getParent(key)).get('nodeType') === 'NativeWrapper') {
return false;
}
if (name) {
if (node.get('nodeType') !== 'Wrapper' && name.toLowerCase().indexOf(needle) !== -1) {
return true;
}
}
var text = node.get('text');
if (text && text.toLowerCase().indexOf(needle) !== -1) {
return true;
}
var children = node.get('children');
if (typeof children === 'string' && children.toLowerCase().indexOf(needle) !== -1) {
return true;
}
return false;
}
module.exports = nodeMatchesText;