You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
consterrorPetName=animals.notExist.name//errror: Cannot read property 'name' of undefined
38
+
//with getinto package
38
39
constpetName=into(animals)
39
40
.into('notExist')
40
41
.get('name')
41
-
console.log(petName) //log: undefined
42
+
console.log(petName) //log: undefined. Never a error.
42
43
```
43
44
44
-
###Installation
45
+
## Installation
45
46
```sh
46
47
$ npm install getinto
47
48
or
48
49
$ yarn add getinto
49
50
```
50
51
51
-
###Usage
52
-
I suggest the following way to import
52
+
## Usage
53
+
I suggest the following import:
53
54
```js
54
55
constinto=require('getinto')
55
56
```
56
-
You can write a chan of 'into'. The first into comes from import and receive an object (or a function, see in 'More examples' or in 'API' for details). The next intos come from previous into. The latter statement must be 'get'.
57
+
You can write a chan of 'into'. The first into comes from import and receive an object (or a function, see in 'More examples' or in 'API' for details).
58
+
The nexts intos come from previous into. The latter statement must be 'get'.
59
+
THe get method always return an array, function, string, object... or undefined. Never a error (if you use the correct syntax).
57
60
```js
58
-
constinto=require('getinto')
59
61
constvalue=into(object)
60
-
.into('objectPropertie')
61
-
.into('nextObjectPropertie')
62
+
.into('objectProperty')
63
+
.into('nextObjectProperty')
62
64
...
63
65
...
64
-
.into('otherPropertie')
65
-
.get('returnedPropertie')
66
-
console.log(value) //log: returnedPropertie
66
+
.into('aIndex')
67
+
.get('returnedProperty')
68
+
console.log(value) //log: valueOfreturnedProperty
69
+
```
70
+
## Typescript Usage
71
+
I suggest the following import:
72
+
```ts
73
+
importintofrom'getinto'
74
+
```
75
+
getinto has the same usage for Typescript but, you can to specify the return type on get method.
76
+
```ts
77
+
into(someObject)
78
+
.get('someProperty')<T>
67
79
```
68
-
### Typescript Usage
69
-
Writing
70
-
71
-
### API
72
-
writing the compleate API documentation
73
80
74
-
###More Examples
81
+
## More Examples
75
82
```js
76
83
constinto=require('getinto')
77
84
constbusiness= {
@@ -89,61 +96,103 @@ const business = {
89
96
}
90
97
]
91
98
}
92
-
93
-
business[0].stories.notExist.techs[0] //error: Cannot read property 'techs' of undefined
99
+
100
+
business.notExist.techs[0] //error: Cannot read property 'techs' of undefined
- if entry is an object or any dictionary, you can select a property to continue the chain passing its name as string in params;
144
+
- if entry is an array, you can select an item to continue the chain passsaing its position as number or string in params;
145
+
- if entry is a function, you can select the function return to continue the chain passaing one param or many params in an array for the function be execute. Use [] (empty array) to execute with no one param.
- key can be a property name as string or can be a index as string or number;
152
+
- if the key return an object or any dictionary, you can select a property to continue the chain passing its name as string in params;
153
+
- if the key return an array, you can select an item to continue the chain passsaing its position as number or string in params;
154
+
- if the key return a function, you can select the function return to continue the chain passaing param or array of params for the function be execute. Use [] (empty array) to execute with no one param.
155
+
#### • get
156
+
#
157
+
```ts
158
+
get<T>(key: string|number, params?:any|any[], callback?: (gotten:T) =>any): T
159
+
```
160
+
- key can be a property name as string or can be a index as string or number
161
+
- if the key return an object or any dictionary, you can get a property passing its name as string in params;
162
+
- if the key return an array, you can get an item passsaing its position as number or string in params.
163
+
- if you are using typescript, can to specify the type of get return
164
+
- if the key return a function, you can get the function return to continue the chain passaing param or array of params for the function be execute. Use [] (empty array) to execute with no one param.
0 commit comments