amos-apptool 1.0.0

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 (46) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +4 -0
  3. package/apis/objectPath.md +129 -0
  4. package/index.d.ts +861 -0
  5. package/lib/_clone.js +79 -0
  6. package/lib/_deepCopy.js +30 -0
  7. package/lib/_deepEqual.js +13 -0
  8. package/lib/_fastDeepEqual.js +38 -0
  9. package/lib/_forOwn.js +17 -0
  10. package/lib/_isnode.js +7 -0
  11. package/lib/_omit.js +19 -0
  12. package/lib/_parseJson.js +17 -0
  13. package/lib/_pick.js +20 -0
  14. package/lib/_pickBy.js +19 -0
  15. package/lib/_queue.js +72 -0
  16. package/lib/_shallowCopy.js +63 -0
  17. package/lib/_stringify.js +22 -0
  18. package/lib/_trim.js +15 -0
  19. package/lib/_typeOfList.js +29 -0
  20. package/lib/_uuids.js +56 -0
  21. package/lib/encrypt/_base64.js +39 -0
  22. package/lib/encrypt/_md5.js +130 -0
  23. package/lib/encrypt/des.js +539 -0
  24. package/lib/index.js +251 -0
  25. package/lib/math/_keyColor.js +158 -0
  26. package/lib/math/addition.js +25 -0
  27. package/lib/math/amountCase.js +18 -0
  28. package/lib/math/coinFormat.js +15 -0
  29. package/lib/math/colorUtil.js +261 -0
  30. package/lib/math/dateTime.js +154 -0
  31. package/lib/math/divide.js +21 -0
  32. package/lib/math/mul.js +29 -0
  33. package/lib/math/pwdStrength.js +11 -0
  34. package/lib/math/randomColor.js +31 -0
  35. package/lib/math/subtraction.js +25 -0
  36. package/lib/merged.js +16 -0
  37. package/lib/objectPath.js +126 -0
  38. package/lib/parseText.js +15 -0
  39. package/lib/pwdPolicy.js +38 -0
  40. package/lib/random.js +33 -0
  41. package/lib/shallowEqual.js +30 -0
  42. package/lib/strUtils.js +90 -0
  43. package/lib/url/encodeUrl.js +14 -0
  44. package/lib/url/restfulUrl.js +15 -0
  45. package/lib/utils.js +341 -0
  46. package/package.json +38 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2016 ilex0208
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,4 @@
1
+ # amos-apptool
2
+
3
+
4
+
@@ -0,0 +1,129 @@
1
+ # objectPath
2
+
3
+ ## Usage
4
+
5
+ ```js
6
+ import { objectPath } from 'amos-apptool';
7
+
8
+ var obj = {
9
+ a: {
10
+ b: "d",
11
+ c: ["e", "f"],
12
+ '\u1200': 'unicode key',
13
+ 'dot.dot': 'key'
14
+ }
15
+ };
16
+
17
+ import { objectPath } from 'amos-apptool';
18
+
19
+ //get deep property
20
+ objectPath.get(obj, "a.b"); //returns "d"
21
+ objectPath.get(obj, ["a", "dot.dot"]); //returns "key"
22
+ objectPath.get(obj, 'a.\u1200'); //returns "unicode key"
23
+
24
+ //get the first non-undefined value
25
+ objectPath.coalesce(obj, ['a.z', 'a.d', ['a','b']], 'default');
26
+
27
+ //empty a given path (but do not delete it) depending on their type,so it retains reference to objects and arrays.
28
+ //functions that are not inherited from prototype are set to null.
29
+ //object instances are considered objects and just own property names are deleted
30
+ objectPath.empty(obj, 'a.b'); // obj.a.b is now ''
31
+ objectPath.empty(obj, 'a.c'); // obj.a.c is now []
32
+ objectPath.empty(obj, 'a'); // obj.a is now {}
33
+
34
+ //works also with arrays
35
+ objectPath.get(obj, "a.c.1"); //returns "f"
36
+ objectPath.get(obj, ["a","c","1"]); //returns "f"
37
+
38
+ //can return a default value with get
39
+ objectPath.get(obj, ["a.c.b"], "DEFAULT"); //returns "DEFAULT", since a.c.b path doesn't exists, if omitted, returns undefined
40
+
41
+ //set
42
+ objectPath.set(obj, "a.h", "m"); // or objectPath.set(obj, ["a","h"], "m");
43
+ objectPath.get(obj, "a.h"); //returns "m"
44
+
45
+ //set will create intermediate object/arrays
46
+ objectPath.set(obj, "a.j.0.f", "m");
47
+
48
+ //will insert values in array
49
+ objectPath.insert(obj, "a.c", "m", 1); // obj.a.c = ["e", "m", "f"]
50
+
51
+ //push into arrays (and create intermediate objects/arrays)
52
+ objectPath.push(obj, "a.k", "o");
53
+
54
+ //ensure a path exists (if it doesn't, set the default value you provide)
55
+ objectPath.ensureExists(obj, "a.k.1", "DEFAULT");
56
+ var oldVal = objectPath.ensureExists(obj, "a.b", "DEFAULT"); // oldval === "d"
57
+
58
+ //deletes a path
59
+ objectPath.del(obj, "a.b"); // obj.a.b is now undefined
60
+ objectPath.del(obj, ["a","c",0]); // obj.a.c is now ['f']
61
+
62
+ //tests path existence
63
+ objectPath.has(obj, "a.b"); // true
64
+ objectPath.has(obj, ["a","d"]); // false
65
+
66
+ //bind object
67
+ var model = objectPath({
68
+ a: {
69
+ b: "d",
70
+ c: ["e", "f"]
71
+ }
72
+ });
73
+
74
+ //now any method from above is supported directly w/o passing an object
75
+ model.get("a.b"); //returns "d"
76
+ model.get(["a.c.b"], "DEFAULT"); //returns "DEFAULT"
77
+ model.del("a.b"); // obj.a.b is now undefined
78
+ model.has("a.b"); // false
79
+
80
+ ```
81
+
82
+ ### How `object-path` deals with inherited properties
83
+
84
+ By default `object-path` will only access an object's own properties. Look at the following example:
85
+
86
+ ```js
87
+ var proto = {
88
+ notOwn: {prop: 'a'}
89
+ }
90
+ var obj = Object.create(proto);
91
+
92
+ //This will return undefined (or the default value you specified), because notOwn is
93
+ //an inherited property
94
+ objectPath.get(obj, 'notOwn.prop');
95
+
96
+ //This will set the property on the obj instance and not the prototype.
97
+ //In other words proto.notOwn.prop === 'a' and obj.notOwn.prop === 'b'
98
+ objectPath.set(obj, 'notOwn.prop', 'b');
99
+ ```
100
+
101
+ To configure `object-path` to also deal with inherited properties, you need to create a new instance and specify
102
+ the `includeInheritedProps = true` in the options object:
103
+
104
+ ```js
105
+ import { objectPath } from 'amos-apptool';
106
+ var objectPathWithInheritedProps = objectPath.create({includeInheritedProps: true})
107
+ ```
108
+
109
+ Alternatively, `object-path` exposes an instance already configured to handle inherited properties (`objectPath.withInheritedProps`):
110
+
111
+ ```js
112
+ import { objectPath } from 'amos-apptool';
113
+ var objectPathWithInheritedProps = objectPath.withInheritedProps
114
+ ```
115
+
116
+ Once you have the new instance, you can access inherited properties as you access other properties:
117
+
118
+ ```js
119
+ var proto = {
120
+ notOwn: {prop: 'a'}
121
+ }
122
+ var obj = Object.create(proto);
123
+
124
+ //This will return 'a'
125
+ objectPath.withInheritedProps.get(obj, 'notOwn.prop');
126
+
127
+ //This will set proto.notOwn.prop to 'b'
128
+ objectPath.set(obj, 'notOwn.prop', 'b');
129
+ ```