-
Notifications
You must be signed in to change notification settings - Fork 6
/
contains.js
executable file
·46 lines (41 loc) · 1.34 KB
/
contains.js
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
38
39
40
41
42
43
44
45
46
import Ember from 'ember';
import {
convertToArray,
convertStringToArray,
convertObjectKeysToArray,
doArraysIntersect
} from '../utils/utils';
/**
* @module
*/
/**
* Test whether value(s) are contained in other values.
*
* Value(s) to test for can be a single value or an array of values.
* All values must be present in the values being tested or the test will fail
*
* @function contains
* @param {ember/Application} [app]
* @param {Array|String|Object} underTest
* @param {Array|String|Object} testFor
* @throws {ember.assert} If parameters are not an array, string, or object
* @returns {Boolean}
*/
export default function() {
let index = ( 3 === arguments.length ) ? 1 : 0;
let underTest = arguments[ index ];
let testFor = arguments[ index + 1 ];
Ember.assert(
'First non-optional argument must be an array, string or object',
'object' === Ember.typeOf( underTest ) ||
'string' === Ember.typeOf( underTest ) ||
'array' === Ember.typeOf( underTest )
);
Ember.assert(
'Second non-optional argument must be an array, string or object',
'object' === Ember.typeOf( testFor ) ||
'string' === Ember.typeOf( testFor ) ||
'array' === Ember.typeOf( testFor )
);
return doArraysIntersect( convertToArray( underTest ), convertToArray( testFor ) );
}