source: node_modules/es-toolkit/dist/compat/array/some.js

Last change on this file was a762898, checked in by istevanoska <ilinastevanoska@…>, 5 months ago

Added visualizations

  • Property mode set to 100644
File size: 2.8 KB
RevLine 
[a762898]1'use strict';
2
3Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
4
5const identity = require('../../function/identity.js');
6const property = require('../object/property.js');
7const matches = require('../predicate/matches.js');
8const matchesProperty = require('../predicate/matchesProperty.js');
9
10function some(source, predicate, guard) {
11 if (!source) {
12 return false;
13 }
14 if (guard != null) {
15 predicate = undefined;
16 }
17 if (predicate == null) {
18 predicate = identity.identity;
19 }
20 const values = Array.isArray(source) ? source : Object.values(source);
21 switch (typeof predicate) {
22 case 'function': {
23 if (!Array.isArray(source)) {
24 const keys = Object.keys(source);
25 for (let i = 0; i < keys.length; i++) {
26 const key = keys[i];
27 const value = source[key];
28 if (predicate(value, key, source)) {
29 return true;
30 }
31 }
32 return false;
33 }
34 for (let i = 0; i < source.length; i++) {
35 if (predicate(source[i], i, source)) {
36 return true;
37 }
38 }
39 return false;
40 }
41 case 'object': {
42 if (Array.isArray(predicate) && predicate.length === 2) {
43 const key = predicate[0];
44 const value = predicate[1];
45 const matchFunc = matchesProperty.matchesProperty(key, value);
46 if (Array.isArray(source)) {
47 for (let i = 0; i < source.length; i++) {
48 if (matchFunc(source[i])) {
49 return true;
50 }
51 }
52 return false;
53 }
54 return values.some(matchFunc);
55 }
56 else {
57 const matchFunc = matches.matches(predicate);
58 if (Array.isArray(source)) {
59 for (let i = 0; i < source.length; i++) {
60 if (matchFunc(source[i])) {
61 return true;
62 }
63 }
64 return false;
65 }
66 return values.some(matchFunc);
67 }
68 }
69 case 'number':
70 case 'symbol':
71 case 'string': {
72 const propFunc = property.property(predicate);
73 if (Array.isArray(source)) {
74 for (let i = 0; i < source.length; i++) {
75 if (propFunc(source[i])) {
76 return true;
77 }
78 }
79 return false;
80 }
81 return values.some(propFunc);
82 }
83 }
84}
85
86exports.some = some;
Note: See TracBrowser for help on using the repository browser.