@@ -9,34 +9,71 @@ Array Helper functions for your quick use.
99npm i @hetarth02/js-array-helpers
1010```
1111
12+ # Contributing
13+
14+ - To conttribute please refer [ CONTRIBUTING.md] ( CONTRIBUTING.md ) .
15+
1216# How to use
1317
1418In your ` package.json ` add the following, ` "type": "module" ` .
1519
16- ### is_array()
20+ # Example Usage
21+
1722``` js
18- import { is_array } from " @hetarth02/js-array-helpers" ;
23+ import { is_array , object_to_array , search_in_array , sanitize_array } from " @hetarth02/js-array-helpers" ;
1924
2025let arr = [1 , 2 ];
2126console .log (is_array (arr)); // true
22- ```
2327
24- ### object_to_array
25- ``` js
2628const objectX = {
2729 0 : " Apple" ,
2830 1 : " Microsoft" ,
2931 2 : " Google"
32+ };
33+ console .log (object_to_array (objectX)); // ['Apple', 'Microsoft', 'Google']
34+
35+ const mang = [' Microsoft' , ' apple' , ' netflix' , ' Google' ];
36+ const result = search_in_array (" app" , mang);
37+ console .log (result); // ['apple']
38+
39+
40+
41+
42+
43+
44+ // Santized array Example
45+
46+ // Corrupted Data array with diff data types
47+ const my_array = [
48+ {name: ' sam' , age: null , isEmployed: ' false' },
49+ {name: ' a' , age: 456 , isEmployed: false },
50+ {name: ' c' , age: undefined , isEmployed: 00 } ,
51+ {name: null , age: 123 , isEmployed: true } ,
52+ {name: ' asd' , age: 123 , isEmployed: false } ,
53+ {name: 00 , age: 123 , isEmployed: null } ,
54+ {name: ' sam' , age: ' 123' , isEmployed: undefined }
55+ ]
56+
57+
58+
59+ // Given schema for correct data types
60+ const my_schema = {
61+ " name" : ' string' ,
62+ " age" : ' number' ,
63+ " isEmployed" : ' boolean'
3064}
31-
32- console .log (object_to_array (objectX)) // ['Apple', 'Microsoft', 'Google']
33- ```
3465
35- ### search_in_array
36- ``` js
37- const mang = [' Microsoft' , ' apple' , ' netflix' , ' Google' ]
66+ // Run sanitize_array with array and schema
67+ console .log (sanitize_array (my_array,my_schema))
3868
39- const result = search_in_array (" app" , mang);
69+ // Sanitized Output
70+ // [ { name: 'sam', age: 0, isEmployed: false },
71+ // { name: 'a', age: 456, isEmployed: false },
72+ // { name: 'c', age: 0, isEmployed: true },
73+ // { name: 'null', age: 123, isEmployed: true },
74+ // { name: 'asd', age: 123, isEmployed: false },
75+ // { name: '0', age: 123, isEmployed: false },
76+ // { name: 'sam', age: 123, isEmployed: false }
77+ // ]
4078
41- console .log (result); // ['apple']
4279```
0 commit comments