@antv/util 2.0.15 → 3.0.0-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (348) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +15 -241
  3. package/dist/util.min.js +1 -0
  4. package/esm/color/arr2rgb.d.ts +12 -0
  5. package/esm/color/arr2rgb.js +18 -0
  6. package/esm/color/arr2rgb.js.map +1 -0
  7. package/esm/color/gradient.d.ts +6 -0
  8. package/esm/color/gradient.js +45 -0
  9. package/esm/color/gradient.js.map +1 -0
  10. package/esm/color/index.d.ts +4 -0
  11. package/esm/color/index.js +6 -0
  12. package/esm/color/index.js.map +1 -0
  13. package/esm/color/rgb2arr.d.ts +6 -0
  14. package/esm/color/rgb2arr.js +9 -0
  15. package/esm/color/rgb2arr.js.map +1 -0
  16. package/esm/color/tocssgradient.d.ts +1 -0
  17. package/esm/color/tocssgradient.js +37 -0
  18. package/esm/color/tocssgradient.js.map +1 -0
  19. package/esm/color/torgb.d.ts +6 -0
  20. package/esm/color/torgb.js +36 -0
  21. package/esm/color/torgb.js.map +1 -0
  22. package/esm/helper/index.d.ts +2 -0
  23. package/esm/helper/index.js +3 -0
  24. package/esm/helper/index.js.map +1 -0
  25. package/esm/helper/mod.d.ts +1 -0
  26. package/esm/helper/mod.js +4 -0
  27. package/esm/helper/mod.js.map +1 -0
  28. package/esm/helper/to-radian.d.ts +1 -0
  29. package/esm/helper/to-radian.js +5 -0
  30. package/esm/helper/to-radian.js.map +1 -0
  31. package/esm/index.d.ts +3 -0
  32. package/esm/index.js +4 -0
  33. package/esm/index.js.map +1 -0
  34. package/esm/matrix/index.d.ts +27 -0
  35. package/esm/matrix/index.js +97 -0
  36. package/esm/matrix/index.js.map +1 -0
  37. package/esm/path/catmull-rom-2-bezier.d.ts +10 -0
  38. package/esm/path/catmull-rom-2-bezier.js +115 -0
  39. package/esm/path/catmull-rom-2-bezier.js.map +1 -0
  40. package/esm/path/fill-path-by-diff.d.ts +5 -0
  41. package/esm/path/fill-path-by-diff.js +110 -0
  42. package/esm/path/fill-path-by-diff.js.map +1 -0
  43. package/esm/path/fill-path.d.ts +1 -0
  44. package/esm/path/fill-path.js +129 -0
  45. package/esm/path/fill-path.js.map +1 -0
  46. package/esm/path/format-path.d.ts +1 -0
  47. package/esm/path/format-path.js +139 -0
  48. package/esm/path/format-path.js.map +1 -0
  49. package/esm/path/get-arc-params.d.ts +17 -0
  50. package/esm/path/get-arc-params.js +90 -0
  51. package/esm/path/get-arc-params.js.map +1 -0
  52. package/esm/path/get-line-intersect.d.ts +14 -0
  53. package/esm/path/get-line-intersect.js +33 -0
  54. package/esm/path/get-line-intersect.js.map +1 -0
  55. package/esm/path/index.d.ts +16 -0
  56. package/esm/path/index.js +17 -0
  57. package/esm/path/index.js.map +1 -0
  58. package/esm/path/is-polygons-intersect.d.ts +1 -0
  59. package/esm/path/is-polygons-intersect.js +81 -0
  60. package/esm/path/is-polygons-intersect.js.map +1 -0
  61. package/esm/path/parse-path-array.d.ts +1 -0
  62. package/esm/path/parse-path-array.js +5 -0
  63. package/esm/path/parse-path-array.js.map +1 -0
  64. package/esm/path/parse-path-string.d.ts +1 -0
  65. package/esm/path/parse-path-string.js +57 -0
  66. package/esm/path/parse-path-string.js.map +1 -0
  67. package/esm/path/parse-path.d.ts +1 -0
  68. package/esm/path/parse-path.js +33 -0
  69. package/esm/path/parse-path.js.map +1 -0
  70. package/esm/path/path-2-absolute.d.ts +1 -0
  71. package/esm/path/path-2-absolute.js +124 -0
  72. package/esm/path/path-2-absolute.js.map +1 -0
  73. package/esm/path/path-2-curve.d.ts +2 -0
  74. package/esm/path/path-2-curve.js +63 -0
  75. package/esm/path/path-2-curve.js.map +1 -0
  76. package/esm/path/path-2-segments.d.ts +1 -0
  77. package/esm/path/path-2-segments.js +138 -0
  78. package/esm/path/path-2-segments.js.map +1 -0
  79. package/esm/path/path-intersection.d.ts +9 -0
  80. package/esm/path/path-intersection.js +366 -0
  81. package/esm/path/path-intersection.js.map +1 -0
  82. package/esm/path/point-in-polygon.d.ts +5 -0
  83. package/esm/path/point-in-polygon.js +49 -0
  84. package/esm/path/point-in-polygon.js.map +1 -0
  85. package/esm/path/process/arc-2-cubic.d.ts +1 -0
  86. package/esm/path/process/arc-2-cubic.js +140 -0
  87. package/esm/path/process/arc-2-cubic.js.map +1 -0
  88. package/esm/path/process/line-2-cubic.d.ts +1 -0
  89. package/esm/path/process/line-2-cubic.js +35 -0
  90. package/esm/path/process/line-2-cubic.js.map +1 -0
  91. package/esm/path/process/quad-2-cubic.d.ts +1 -0
  92. package/esm/path/process/quad-2-cubic.js +13 -0
  93. package/esm/path/process/quad-2-cubic.js.map +1 -0
  94. package/esm/path/process/segment-2-cubic.d.ts +2 -0
  95. package/esm/path/process/segment-2-cubic.js +37 -0
  96. package/esm/path/process/segment-2-cubic.js.map +1 -0
  97. package/esm/path/rect-path.d.ts +4 -0
  98. package/esm/path/rect-path.js +19 -0
  99. package/esm/path/rect-path.js.map +1 -0
  100. package/esm/path/types.d.ts +25 -0
  101. package/esm/path/types.js +2 -0
  102. package/esm/path/types.js.map +1 -0
  103. package/lib/color/arr2rgb.d.ts +12 -0
  104. package/lib/color/arr2rgb.js +23 -0
  105. package/lib/color/arr2rgb.js.map +1 -0
  106. package/lib/color/gradient.d.ts +6 -0
  107. package/lib/color/gradient.js +49 -0
  108. package/lib/color/gradient.js.map +1 -0
  109. package/lib/color/index.d.ts +4 -0
  110. package/lib/color/index.js +13 -0
  111. package/lib/color/index.js.map +1 -0
  112. package/lib/color/rgb2arr.d.ts +6 -0
  113. package/lib/color/rgb2arr.js +13 -0
  114. package/lib/color/rgb2arr.js.map +1 -0
  115. package/lib/color/tocssgradient.d.ts +1 -0
  116. package/lib/color/tocssgradient.js +41 -0
  117. package/lib/color/tocssgradient.js.map +1 -0
  118. package/lib/color/torgb.d.ts +6 -0
  119. package/lib/color/torgb.js +40 -0
  120. package/lib/color/torgb.js.map +1 -0
  121. package/lib/helper/index.d.ts +2 -0
  122. package/lib/helper/index.js +8 -0
  123. package/lib/helper/index.js.map +1 -0
  124. package/lib/helper/mod.d.ts +1 -0
  125. package/lib/helper/mod.js +8 -0
  126. package/lib/helper/mod.js.map +1 -0
  127. package/lib/helper/to-radian.d.ts +1 -0
  128. package/lib/helper/to-radian.js +9 -0
  129. package/lib/helper/to-radian.js.map +1 -0
  130. package/lib/index.d.ts +3 -0
  131. package/lib/index.js +16 -0
  132. package/lib/index.js.map +1 -0
  133. package/lib/matrix/index.d.ts +27 -0
  134. package/lib/matrix/index.js +104 -0
  135. package/lib/matrix/index.js.map +1 -0
  136. package/lib/path/catmull-rom-2-bezier.d.ts +10 -0
  137. package/lib/path/catmull-rom-2-bezier.js +119 -0
  138. package/lib/path/catmull-rom-2-bezier.js.map +1 -0
  139. package/lib/path/fill-path-by-diff.d.ts +5 -0
  140. package/lib/path/fill-path-by-diff.js +117 -0
  141. package/lib/path/fill-path-by-diff.js.map +1 -0
  142. package/lib/path/fill-path.d.ts +1 -0
  143. package/lib/path/fill-path.js +133 -0
  144. package/lib/path/fill-path.js.map +1 -0
  145. package/lib/path/format-path.d.ts +1 -0
  146. package/lib/path/format-path.js +143 -0
  147. package/lib/path/format-path.js.map +1 -0
  148. package/lib/path/get-arc-params.d.ts +17 -0
  149. package/lib/path/get-arc-params.js +95 -0
  150. package/lib/path/get-arc-params.js.map +1 -0
  151. package/lib/path/get-line-intersect.d.ts +14 -0
  152. package/lib/path/get-line-intersect.js +37 -0
  153. package/lib/path/get-line-intersect.js.map +1 -0
  154. package/lib/path/index.d.ts +16 -0
  155. package/lib/path/index.js +36 -0
  156. package/lib/path/index.js.map +1 -0
  157. package/lib/path/is-polygons-intersect.d.ts +1 -0
  158. package/lib/path/is-polygons-intersect.js +85 -0
  159. package/lib/path/is-polygons-intersect.js.map +1 -0
  160. package/lib/path/parse-path-array.d.ts +1 -0
  161. package/lib/path/parse-path-array.js +9 -0
  162. package/lib/path/parse-path-array.js.map +1 -0
  163. package/lib/path/parse-path-string.d.ts +1 -0
  164. package/lib/path/parse-path-string.js +61 -0
  165. package/lib/path/parse-path-string.js.map +1 -0
  166. package/lib/path/parse-path.d.ts +1 -0
  167. package/lib/path/parse-path.js +37 -0
  168. package/lib/path/parse-path.js.map +1 -0
  169. package/lib/path/path-2-absolute.d.ts +1 -0
  170. package/lib/path/path-2-absolute.js +128 -0
  171. package/lib/path/path-2-absolute.js.map +1 -0
  172. package/lib/path/path-2-curve.d.ts +2 -0
  173. package/lib/path/path-2-curve.js +67 -0
  174. package/lib/path/path-2-curve.js.map +1 -0
  175. package/lib/path/path-2-segments.d.ts +1 -0
  176. package/lib/path/path-2-segments.js +142 -0
  177. package/lib/path/path-2-segments.js.map +1 -0
  178. package/lib/path/path-intersection.d.ts +9 -0
  179. package/lib/path/path-intersection.js +370 -0
  180. package/lib/path/path-intersection.js.map +1 -0
  181. package/lib/path/point-in-polygon.d.ts +5 -0
  182. package/lib/path/point-in-polygon.js +53 -0
  183. package/lib/path/point-in-polygon.js.map +1 -0
  184. package/lib/path/process/arc-2-cubic.d.ts +1 -0
  185. package/lib/path/process/arc-2-cubic.js +144 -0
  186. package/lib/path/process/arc-2-cubic.js.map +1 -0
  187. package/lib/path/process/line-2-cubic.d.ts +1 -0
  188. package/lib/path/process/line-2-cubic.js +39 -0
  189. package/lib/path/process/line-2-cubic.js.map +1 -0
  190. package/lib/path/process/quad-2-cubic.d.ts +1 -0
  191. package/lib/path/process/quad-2-cubic.js +17 -0
  192. package/lib/path/process/quad-2-cubic.js.map +1 -0
  193. package/lib/path/process/segment-2-cubic.d.ts +2 -0
  194. package/lib/path/process/segment-2-cubic.js +41 -0
  195. package/lib/path/process/segment-2-cubic.js.map +1 -0
  196. package/lib/path/rect-path.d.ts +4 -0
  197. package/lib/path/rect-path.js +23 -0
  198. package/lib/path/rect-path.js.map +1 -0
  199. package/lib/path/types.d.ts +25 -0
  200. package/lib/path/types.js +3 -0
  201. package/lib/path/types.js.map +1 -0
  202. package/package.json +77 -36
  203. package/src/color/arr2rgb.ts +19 -0
  204. package/src/color/gradient.ts +55 -0
  205. package/src/color/index.ts +5 -0
  206. package/src/color/rgb2arr.ts +8 -0
  207. package/src/color/tocssgradient.ts +43 -0
  208. package/src/color/torgb.ts +45 -0
  209. package/src/helper/index.ts +2 -0
  210. package/src/helper/mod.ts +3 -0
  211. package/src/helper/to-radian.ts +5 -0
  212. package/src/index.ts +3 -130
  213. package/src/matrix/index.ts +108 -0
  214. package/src/path/catmull-rom-2-bezier.ts +141 -0
  215. package/src/path/fill-path-by-diff.ts +116 -0
  216. package/src/path/fill-path.ts +129 -0
  217. package/src/path/format-path.ts +142 -0
  218. package/src/path/get-arc-params.ts +102 -0
  219. package/src/path/get-line-intersect.ts +46 -0
  220. package/src/path/index.ts +16 -0
  221. package/src/path/is-polygons-intersect.ts +95 -0
  222. package/src/path/parse-path-array.ts +5 -0
  223. package/src/path/parse-path-string.ts +63 -0
  224. package/src/path/parse-path.ts +34 -0
  225. package/src/path/path-2-absolute.ts +132 -0
  226. package/src/path/path-2-curve.ts +69 -0
  227. package/src/path/path-2-segments.ts +142 -0
  228. package/src/path/path-intersection.ts +419 -0
  229. package/src/path/point-in-polygon.ts +56 -0
  230. package/src/path/process/arc-2-cubic.ts +221 -0
  231. package/src/path/process/line-2-cubic.ts +37 -0
  232. package/src/path/process/quad-2-cubic.ts +12 -0
  233. package/src/path/process/segment-2-cubic.ts +44 -0
  234. package/src/path/rect-path.ts +22 -0
  235. package/src/path/types.ts +25 -0
  236. package/src/augment.ts +0 -16
  237. package/src/cache.ts +0 -31
  238. package/src/clamp.ts +0 -10
  239. package/src/clear-animation-frame.ts +0 -11
  240. package/src/clone.ts +0 -31
  241. package/src/contains.ts +0 -10
  242. package/src/debounce.ts +0 -22
  243. package/src/deep-mix.ts +0 -39
  244. package/src/difference.ts +0 -17
  245. package/src/each.ts +0 -28
  246. package/src/ends-with.ts +0 -10
  247. package/src/every.ts +0 -14
  248. package/src/extend.ts +0 -36
  249. package/src/filter.ts +0 -18
  250. package/src/find-index.ts +0 -12
  251. package/src/find.ts +0 -29
  252. package/src/first-value.ts +0 -21
  253. package/src/fixed-base.ts +0 -14
  254. package/src/flatten-deep.ts +0 -24
  255. package/src/flatten.ts +0 -23
  256. package/src/for-in.ts +0 -3
  257. package/src/get-ellipsis-text.ts +0 -75
  258. package/src/get-range.ts +0 -35
  259. package/src/get-type.ts +0 -7
  260. package/src/get-wrap-behavior.ts +0 -13
  261. package/src/get.ts +0 -18
  262. package/src/group-by.ts +0 -35
  263. package/src/group-to-map.ts +0 -30
  264. package/src/group.ts +0 -14
  265. package/src/has-key.ts +0 -2
  266. package/src/has-value.ts +0 -4
  267. package/src/has.ts +0 -1
  268. package/src/head.ts +0 -8
  269. package/src/identity.ts +0 -1
  270. package/src/index-of.ts +0 -22
  271. package/src/is-arguments.ts +0 -13
  272. package/src/is-array-like.ts +0 -11
  273. package/src/is-array.ts +0 -7
  274. package/src/is-boolean.ts +0 -13
  275. package/src/is-date.ts +0 -7
  276. package/src/is-decimal.ts +0 -7
  277. package/src/is-element.ts +0 -8
  278. package/src/is-empty.ts +0 -39
  279. package/src/is-equal-with.ts +0 -31
  280. package/src/is-equal.ts +0 -46
  281. package/src/is-error.ts +0 -13
  282. package/src/is-even.ts +0 -7
  283. package/src/is-finite.ts +0 -11
  284. package/src/is-function.ts +0 -10
  285. package/src/is-integer.ts +0 -7
  286. package/src/is-match.ts +0 -17
  287. package/src/is-negative.ts +0 -7
  288. package/src/is-nil.ts +0 -10
  289. package/src/is-null.ts +0 -5
  290. package/src/is-number-equal.ts +0 -5
  291. package/src/is-number.ts +0 -10
  292. package/src/is-object-like.ts +0 -11
  293. package/src/is-object.ts +0 -10
  294. package/src/is-odd.ts +0 -7
  295. package/src/is-plain-object.ts +0 -24
  296. package/src/is-positive.ts +0 -7
  297. package/src/is-prototype.ts +0 -9
  298. package/src/is-reg-exp.ts +0 -7
  299. package/src/is-segment-equal.ts +0 -15
  300. package/src/is-string.ts +0 -5
  301. package/src/is-type.ts +0 -5
  302. package/src/is-undefined.ts +0 -5
  303. package/src/keys.ts +0 -14
  304. package/src/last.ts +0 -9
  305. package/src/lower-case.ts +0 -7
  306. package/src/lower-first.ts +0 -8
  307. package/src/map-values.ts +0 -19
  308. package/src/map.ts +0 -17
  309. package/src/max-by.ts +0 -37
  310. package/src/max.ts +0 -28
  311. package/src/measure-text-width.ts +0 -25
  312. package/src/memoize.ts +0 -31
  313. package/src/merge.ts +0 -12
  314. package/src/min-by.ts +0 -38
  315. package/src/min.ts +0 -28
  316. package/src/mix.ts +0 -15
  317. package/src/mod.ts +0 -5
  318. package/src/noop.ts +0 -1
  319. package/src/number2color.ts +0 -17
  320. package/src/omit.ts +0 -15
  321. package/src/parse-radius.ts +0 -45
  322. package/src/pick.ts +0 -32
  323. package/src/pull-at.ts +0 -23
  324. package/src/pull.ts +0 -16
  325. package/src/reduce.ts +0 -17
  326. package/src/remove.ts +0 -30
  327. package/src/request-animation-frame.ts +0 -13
  328. package/src/set.ts +0 -29
  329. package/src/size.ts +0 -12
  330. package/src/some.ts +0 -14
  331. package/src/sort-by.ts +0 -42
  332. package/src/starts-with.ts +0 -10
  333. package/src/substitute.ts +0 -17
  334. package/src/throttle.ts +0 -48
  335. package/src/to-array.ts +0 -5
  336. package/src/to-degree.ts +0 -7
  337. package/src/to-integer.ts +0 -1
  338. package/src/to-radian.ts +0 -7
  339. package/src/to-string.ts +0 -6
  340. package/src/types/index.ts +0 -3
  341. package/src/union.ts +0 -7
  342. package/src/uniq.ts +0 -15
  343. package/src/unique-id.ts +0 -11
  344. package/src/upper-case.ts +0 -7
  345. package/src/upper-first.ts +0 -8
  346. package/src/values-of-key.ts +0 -29
  347. package/src/values.ts +0 -15
  348. package/src/wrap-behavior.ts +0 -20
package/src/get-range.ts DELETED
@@ -1,35 +0,0 @@
1
- import isArray from './is-array';
2
- import { default as getMax } from './max';
3
- import { default as getMin } from './min';
4
-
5
- export interface RangeType {
6
- readonly min: number;
7
- readonly max: number;
8
- }
9
-
10
- const getRange = function (values: number[]): RangeType {
11
- // 存在 NaN 时,min,max 判定会出问题
12
- let filterValues = values.filter((v) => !isNaN(v));
13
- if (!filterValues.length) {
14
- // 如果没有数值则直接返回0
15
- return {
16
- min: 0,
17
- max: 0,
18
- };
19
- }
20
- if (isArray(values[0])) {
21
- let tmp = [];
22
- for (let i = 0; i < values.length; i++) {
23
- tmp = tmp.concat(values[i]);
24
- }
25
- filterValues = tmp;
26
- }
27
- const max = getMax(filterValues);
28
- const min = getMin(filterValues);
29
- return {
30
- min,
31
- max,
32
- };
33
- };
34
-
35
- export default getRange;
package/src/get-type.ts DELETED
@@ -1,7 +0,0 @@
1
- const toString = {}.toString;
2
-
3
- const getType = function(value: any): string {
4
- return toString.call(value).replace(/^\[object /, '').replace(/]$/, '');
5
- };
6
-
7
- export default getType;
@@ -1,13 +0,0 @@
1
-
2
- /**
3
- * 获取封装的事件
4
- * @protected
5
- * @param {Object} obj 对象
6
- * @param {String} action 事件名称
7
- * @return {Function} 返回事件处理函数
8
- */
9
- function getWrapBehavior(obj: object, action: string): Function {
10
- return obj['_wrap_' + action];
11
- }
12
-
13
- export default getWrapBehavior;
package/src/get.ts DELETED
@@ -1,18 +0,0 @@
1
- import isString from './is-string';
2
- /**
3
- * https://github.com/developit/dlv/blob/master/index.js
4
- * @param obj
5
- * @param key
6
- * @param defaultValue
7
- */
8
- export default (obj: any, key: string | any[], defaultValue?: any): any => {
9
- let p = 0;
10
-
11
- const keyArr = isString(key) ? key.split('.') : key;
12
-
13
- while (obj && p < keyArr.length) {
14
- obj = obj[keyArr[p++]];
15
- }
16
-
17
- return (obj === undefined || p < keyArr.length) ? defaultValue : obj;
18
- }
package/src/group-by.ts DELETED
@@ -1,35 +0,0 @@
1
- import isArray from './is-array';
2
- import isFunction from './is-function';
3
-
4
- const hasOwnProperty = Object.prototype.hasOwnProperty;
5
-
6
- export interface ObjectType<T> {
7
- [key: string]: T[];
8
- }
9
-
10
- function groupBy<T>(data: T[], condition: (item: T) => string): ObjectType<T>;
11
- function groupBy<T>(data: T[], condition: string): ObjectType<T>;
12
- function groupBy<T>(data: T[], condition: ((item: T) => string) | string): ObjectType<T> {
13
- if (!condition || !isArray(data)) {
14
- return {};
15
- }
16
- const result: ObjectType<T> = {};
17
-
18
- // 兼容方法和 字符串的写法
19
- const predicate = isFunction(condition) ? condition : (item) => item[condition];
20
-
21
- let key: string;
22
- for (let i = 0; i < data.length; i++) {
23
- const item = data[i];
24
- key = predicate(item);
25
- if (hasOwnProperty.call(result, key)) {
26
- result[key].push(item);
27
- } else {
28
- result[key] = [ item ];
29
- }
30
- }
31
-
32
- return result;
33
- }
34
-
35
- export default groupBy;
@@ -1,30 +0,0 @@
1
- import isArray from './is-array';
2
- import isFunction from './is-function';
3
- import groupBy from './group-by';
4
-
5
- /**
6
- * 将数据分组成 map
7
- * @param data
8
- * @param condition
9
- */
10
- export default function groupToMap(data: any, condition: string[] | string | ((row: any) => string)) {
11
- if (!condition) {
12
- return {
13
- 0: data,
14
- };
15
- }
16
- if (!isFunction(condition)) {
17
- // 如果是字符串,则按照 a*b 风格成数组
18
- const paramscondition = isArray(condition) ? condition : condition.replace(/\s+/g, '').split('*');
19
- condition = function (row) {
20
- let unique = '_'; // 避免出现数字作为Key的情况,会进行按照数字的排序
21
-
22
- // 根据字段列表的值,拼接成 key
23
- for (let i = 0, l = paramscondition.length; i < l; i++) {
24
- unique += row[paramscondition[i]] && row[paramscondition[i]].toString();
25
- }
26
- return unique;
27
- };
28
- }
29
- return groupBy(data, condition);
30
- }
package/src/group.ts DELETED
@@ -1,14 +0,0 @@
1
- import groupToMap from './group-to-map';
2
-
3
- export default <T>(data: T[], condition: ((v: T) => string) | string | string[]): T[][] => {
4
- if (!condition) {
5
- // 没有条件,则自身改成数组
6
- return [ data ];
7
- }
8
- const groups = groupToMap(data, condition) as { [key: string]: T };
9
- const array = [];
10
- for (const i in groups) {
11
- array.push(groups[i]);
12
- }
13
- return array;
14
- };
package/src/has-key.ts DELETED
@@ -1,2 +0,0 @@
1
- import has from './has';
2
- export default has;
package/src/has-value.ts DELETED
@@ -1,4 +0,0 @@
1
- import contains from './contains';
2
- import values from './values';
3
-
4
- export default (obj: object, value: any): boolean => contains(values(obj), value);
package/src/has.ts DELETED
@@ -1 +0,0 @@
1
- export default (obj: object, key: any): boolean => obj.hasOwnProperty(key);
package/src/head.ts DELETED
@@ -1,8 +0,0 @@
1
- import isArrayLike from './is-array-like';
2
-
3
- export default function head(o: unknown) {
4
- if (isArrayLike(o)) {
5
- return (<ArrayLike<any>>o)[0];
6
- }
7
- return undefined;
8
- }
package/src/identity.ts DELETED
@@ -1 +0,0 @@
1
- export default <T>(v: T): T => v;
package/src/index-of.ts DELETED
@@ -1,22 +0,0 @@
1
- import isArrayLike from './is-array-like';
2
-
3
- const indexOf = function<T> (arr: T[], obj: T): number {
4
- if (!isArrayLike(arr)) {
5
- return -1;
6
- }
7
- const m = Array.prototype.indexOf;
8
- if (m) {
9
- return m.call(arr, obj);
10
- }
11
- let index = -1;
12
-
13
- for (let i = 0; i < arr.length; i++) {
14
- if (arr[i] === obj) {
15
- index = i;
16
- break;
17
- }
18
- }
19
- return index;
20
- };
21
-
22
- export default indexOf;
@@ -1,13 +0,0 @@
1
- /**
2
- * 是否是参数类型
3
- *
4
- * @param {Object} value 测试的值
5
- * @return {Boolean}
6
- */
7
- import isType from './is-type';
8
-
9
- const isArguments = function(value: any): boolean {
10
- return isType(value, 'Arguments');
11
- };
12
-
13
- export default isArguments;
@@ -1,11 +0,0 @@
1
- const isArrayLike = function(value: any): boolean {
2
- /**
3
- * isArrayLike([1, 2, 3]) => true
4
- * isArrayLike(document.body.children) => true
5
- * isArrayLike('abc') => true
6
- * isArrayLike(Function) => false
7
- */
8
- return value !== null && typeof value !== 'function' && isFinite(value.length);
9
- };
10
-
11
- export default isArrayLike;
package/src/is-array.ts DELETED
@@ -1,7 +0,0 @@
1
- import isType from './is-type';
2
-
3
- export default (value: any): value is Array<any> => {
4
- return Array.isArray ?
5
- Array.isArray(value) :
6
- isType(value, 'Array');
7
- }
package/src/is-boolean.ts DELETED
@@ -1,13 +0,0 @@
1
- /**
2
- * 是否是布尔类型
3
- *
4
- * @param {Object} value 测试的值
5
- * @return {Boolean}
6
- */
7
- import isType from './is-type';
8
-
9
- const isBoolean = function(value: any): value is boolean {
10
- return isType(value, 'Boolean');
11
- };
12
-
13
- export default isBoolean;
package/src/is-date.ts DELETED
@@ -1,7 +0,0 @@
1
- import isType from './is-type';
2
-
3
- const isDate = function(value: any): value is Date {
4
- return isType(value, 'Date');
5
- };
6
-
7
- export default isDate;
package/src/is-decimal.ts DELETED
@@ -1,7 +0,0 @@
1
- import isNumber from './is-number';
2
-
3
- const isDecimal = function(num: any): boolean {
4
- return isNumber(num) && num % 1 !== 0;
5
- };
6
-
7
- export default isDecimal;
package/src/is-element.ts DELETED
@@ -1,8 +0,0 @@
1
- /**
2
- * 判断是否HTML元素
3
- * @return {Boolean} 是否HTML元素
4
- */
5
- const isElement = function(o: any): boolean {
6
- return o instanceof Element || o instanceof HTMLDocument;
7
- };
8
- export default isElement;
package/src/is-empty.ts DELETED
@@ -1,39 +0,0 @@
1
- import isNil from './is-nil';
2
- import isArrayLike from './is-array-like';
3
- import getType from './get-type';
4
- import isPrototype from './is-prototype';
5
-
6
- const hasOwnProperty = Object.prototype.hasOwnProperty;
7
-
8
- function isEmpty(value: any): boolean {
9
- /**
10
- * isEmpty(null) => true
11
- * isEmpty() => true
12
- * isEmpty(true) => true
13
- * isEmpty(1) => true
14
- * isEmpty([1, 2, 3]) => false
15
- * isEmpty('abc') => false
16
- * isEmpty({ a: 1 }) => false
17
- */
18
- if (isNil(value)) {
19
- return true;
20
- }
21
- if (isArrayLike(value)) {
22
- return !value.length;
23
- }
24
- const type = getType(value);
25
- if (type === 'Map' || type === 'Set') {
26
- return !value.size;
27
- }
28
- if (isPrototype(value)) {
29
- return !Object.keys(value).length;
30
- }
31
- for (const key in value) {
32
- if (hasOwnProperty.call(value, key)) {
33
- return false;
34
- }
35
- }
36
- return true;
37
- }
38
-
39
- export default isEmpty;
@@ -1,31 +0,0 @@
1
- import isFunction from './is-function';
2
- import isEqual from './is-equal';
3
- /**
4
- * @param {*} value The value to compare.
5
- * @param {*} other The other value to compare.
6
- * @param {Function} [fn] The function to customize comparisons.
7
- * @returns {boolean} Returns `true` if the values are equivalent, else `false`.
8
- * @example
9
- *
10
- * function isGreeting(value) {
11
- * return /^h(?:i|ello)$/.test(value);
12
- * }
13
- *
14
- * function customizer(objValue, othValue) {
15
- * if (isGreeting(objValue) && isGreeting(othValue)) {
16
- * return true;
17
- * }
18
- * }
19
- *
20
- * var array = ['hello', 'goodbye'];
21
- * var other = ['hi', 'goodbye'];
22
- *
23
- * isEqualWith(array, other, customizer); // => true
24
- */
25
-
26
- export default <T>(value: T, other: T, fn: (v1: T, v2: T) => boolean): boolean => {
27
- if (!isFunction(fn)) {
28
- return isEqual(value, other);
29
- }
30
- return !!fn(value, other);
31
- };
package/src/is-equal.ts DELETED
@@ -1,46 +0,0 @@
1
- import isObjectLike from './is-object-like';
2
- import isArrayLike from './is-array-like';
3
- import isString from './is-string';
4
-
5
- const isEqual = (value: any, other: any): boolean => {
6
- if (value === other) {
7
- return true;
8
- }
9
- if (!value || !other) {
10
- return false;
11
- }
12
- if (isString(value) || isString(other)) {
13
- return false;
14
- }
15
- if (isArrayLike(value) || isArrayLike(other)) {
16
- if (value.length !== other.length) {
17
- return false;
18
- }
19
- let rst = true;
20
- for (let i = 0; i < value.length; i++) {
21
- rst = isEqual(value[i], other[i]);
22
- if (!rst) {
23
- break;
24
- }
25
- }
26
- return rst;
27
- }
28
- if (isObjectLike(value) || isObjectLike(other)) {
29
- const valueKeys = Object.keys(value);
30
- const otherKeys = Object.keys(other);
31
- if (valueKeys.length !== otherKeys.length) {
32
- return false;
33
- }
34
- let rst = true;
35
- for (let i = 0; i < valueKeys.length; i++) {
36
- rst = isEqual(value[valueKeys[i]], other[valueKeys[i]]);
37
- if (!rst) {
38
- break;
39
- }
40
- }
41
- return rst;
42
- }
43
- return false;
44
- };
45
-
46
- export default isEqual;
package/src/is-error.ts DELETED
@@ -1,13 +0,0 @@
1
- /**
2
- * 是否是参数类型
3
- *
4
- * @param {Object} value 测试的值
5
- * @return {Boolean}
6
- */
7
- import isType from './is-type';
8
-
9
- const isError = function(value: any): value is Error {
10
- return isType(value, 'Error');
11
- };
12
-
13
- export default isError;
package/src/is-even.ts DELETED
@@ -1,7 +0,0 @@
1
- import isNumber from './is-number';
2
-
3
- const isEven = function(num: any): boolean {
4
- return isNumber(num) && num % 2 === 0;
5
- };
6
-
7
- export default isEven;
package/src/is-finite.ts DELETED
@@ -1,11 +0,0 @@
1
- /**
2
- * 判断是否为有限数
3
- * @return {Boolean}
4
- */
5
- import isNumber from './is-number';
6
-
7
- export default function(value: any) : value is number {
8
- return isNumber(value) && isFinite(value)
9
- }
10
-
11
-
@@ -1,10 +0,0 @@
1
- /**
2
- * 是否为函数
3
- * @param {*} fn 对象
4
- * @return {Boolean} 是否函数
5
- */
6
- import isType from './is-type';
7
-
8
- export default (value: any): value is Function => {
9
- return isType(value, 'Function');
10
- };
package/src/is-integer.ts DELETED
@@ -1,7 +0,0 @@
1
- import isNumber from './is-number';
2
-
3
- const isInteger = Number.isInteger ? Number.isInteger : function(num: any): boolean {
4
- return isNumber(num) && num % 1 === 0;
5
- };
6
-
7
- export default isInteger;
package/src/is-match.ts DELETED
@@ -1,17 +0,0 @@
1
- import isNil from './is-nil';
2
- import keys from './keys';
3
-
4
- function isMatch(obj: any, attrs: any): boolean {
5
- const _keys = keys(attrs);
6
- const length = _keys.length;
7
- if (isNil(obj)) return !length;
8
- for (let i = 0; i < length; i += 1) {
9
- const key = _keys[i];
10
- if (attrs[key] !== obj[key] || !(key in obj)) {
11
- return false;
12
- }
13
- }
14
- return true;
15
- }
16
-
17
- export default isMatch;
@@ -1,7 +0,0 @@
1
- import isNumber from './is-number';
2
-
3
- const isNegative = function(num: any): boolean {
4
- return isNumber(num) && num < 0;
5
- };
6
-
7
- export default isNegative;
package/src/is-nil.ts DELETED
@@ -1,10 +0,0 @@
1
- // isFinite,
2
- const isNil = function(value: any): value is null | undefined {
3
- /**
4
- * isNil(null) => true
5
- * isNil() => true
6
- */
7
- return value === null || value === undefined;
8
- };
9
-
10
- export default isNil;
package/src/is-null.ts DELETED
@@ -1,5 +0,0 @@
1
- const isNull = function(value): value is null {
2
- return value === null;
3
- };
4
-
5
- export default isNull;
@@ -1,5 +0,0 @@
1
- const PRECISION = 0.00001; // numbers less than this is considered as 0
2
-
3
- export default function isNumberEqual(a: number, b: number, precision: number = PRECISION): boolean {
4
- return Math.abs((a - b)) < precision;
5
- };
package/src/is-number.ts DELETED
@@ -1,10 +0,0 @@
1
- /**
2
- * 判断是否数字
3
- * @return {Boolean} 是否数字
4
- */
5
- import isType from './is-type';
6
-
7
- const isNumber = function(value: any): value is number {
8
- return isType(value, 'Number');
9
- };
10
- export default isNumber;
@@ -1,11 +0,0 @@
1
- const isObjectLike = function(value: any): value is object {
2
- /**
3
- * isObjectLike({}) => true
4
- * isObjectLike([1, 2, 3]) => true
5
- * isObjectLike(Function) => false
6
- * isObjectLike(null) => false
7
- */
8
- return typeof value === 'object' && value !== null;
9
- };
10
-
11
- export default isObjectLike;
package/src/is-object.ts DELETED
@@ -1,10 +0,0 @@
1
- export default <T = object>(value: any): value is T => {
2
- /**
3
- * isObject({}) => true
4
- * isObject([1, 2, 3]) => true
5
- * isObject(Function) => true
6
- * isObject(null) => false
7
- */
8
- const type = typeof value;
9
- return value !== null && type === 'object' || type === 'function';
10
- };
package/src/is-odd.ts DELETED
@@ -1,7 +0,0 @@
1
- import isNumber from './is-number';
2
-
3
- const isOdd = function(num: any): boolean {
4
- return isNumber(num) && num % 2 !== 0;
5
- };
6
-
7
- export default isOdd;
@@ -1,24 +0,0 @@
1
- import isObjectLike from './is-object-like';
2
- import isType from './is-type';
3
-
4
- const isPlainObject = function(value: any): value is object {
5
- /**
6
- * isObjectLike(new Foo) => false
7
- * isObjectLike([1, 2, 3]) => false
8
- * isObjectLike({ x: 0, y: 0 }) => true
9
- * isObjectLike(Object.create(null)) => true
10
- */
11
- if (!isObjectLike(value) || !isType(value, 'Object')) {
12
- return false;
13
- }
14
- if (Object.getPrototypeOf(value) === null) {
15
- return true;
16
- }
17
- let proto = value;
18
- while (Object.getPrototypeOf(proto) !== null) {
19
- proto = Object.getPrototypeOf(proto);
20
- }
21
- return Object.getPrototypeOf(value) === proto;
22
- };
23
-
24
- export default isPlainObject;
@@ -1,7 +0,0 @@
1
- import isNumber from './is-number';
2
-
3
- const isPositive = function(num: any): boolean {
4
- return isNumber(num) && num > 0;
5
- };
6
-
7
- export default isPositive;
@@ -1,9 +0,0 @@
1
- const objectProto = Object.prototype;
2
-
3
- const isPrototype = function(value: any): boolean {
4
- const Ctor = value && value.constructor;
5
- const proto = (typeof Ctor === 'function' && Ctor.prototype) || objectProto;
6
- return value === proto;
7
- };
8
-
9
- export default isPrototype;
package/src/is-reg-exp.ts DELETED
@@ -1,7 +0,0 @@
1
- import isType from './is-type';
2
-
3
- const isRegExp = function(str: any): str is RegExp {
4
- return isType(str, 'RegExp');
5
- };
6
-
7
- export default isRegExp;
@@ -1,15 +0,0 @@
1
- import each from './each';
2
-
3
- export default (obj1: any, obj2: any): boolean => {
4
- if (obj1.length !== obj2.length) {
5
- return false;
6
- }
7
- let result = true;
8
- each(obj1, (item, i) => {
9
- if (item !== obj2[i]) {
10
- result = false;
11
- return false;
12
- }
13
- });
14
- return result;
15
- };
package/src/is-string.ts DELETED
@@ -1,5 +0,0 @@
1
- import isType from './is-type';
2
-
3
- export default (str: any): str is string => {
4
- return isType(str, 'String');
5
- }
package/src/is-type.ts DELETED
@@ -1,5 +0,0 @@
1
- const toString = {}.toString;
2
-
3
- const isType = (value: any, type: string): boolean => toString.call(value) === '[object ' + type + ']';
4
-
5
- export default isType;
@@ -1,5 +0,0 @@
1
- const isUndefined = function(value: any): value is undefined {
2
- return value === undefined;
3
- };
4
-
5
- export default isUndefined;