@@ -20,7 +20,7 @@ In your `package.json` add the following, `"type": "module"`.
2020# Example Usage
2121
2222``` js
23- import { is_array , object_to_array , search_in_array } from " @hetarth02/js-array-helpers" ;
23+ import { is_array , object_to_array , search_in_array , sanitize_array } from " @hetarth02/js-array-helpers" ;
2424
2525let arr = [1 , 2 ];
2626console .log (is_array (arr)); // true
@@ -35,4 +35,38 @@ console.log(object_to_array(objectX)); // ['Apple', 'Microsoft', 'Google']
3535const mang = [' Microsoft' , ' apple' , ' netflix' , ' Google' ];
3636const result = search_in_array (" app" , mang);
3737console .log (result); // ['apple']
38+
39+ // Corrupted Data array with diff data types
40+ const my_array = [
41+ {name: ' sam' ,age: null ,isEmployed: ' false' },
42+ {name: ' a' ,age: 456 ,isEmployed: false },
43+ {name: ' c' ,age: undefined ,isEmployed: 00 } ,
44+ {name: null ,age: 123 ,isEmployed: true } ,
45+ {name: ' asd' ,age: 123 ,isEmployed: false } ,
46+ {name: 00 ,age: 123 ,isEmployed: null } ,
47+ {name: ' sam' ,age: ' 123' ,isEmployed: undefined }
48+ ]
49+
50+ // Santized array Example
51+
52+ // Given schema for correct data types
53+ const my_schema = {
54+ " name" : ' string' ,
55+ " age" : ' number' ,
56+ " isEmployed" : ' boolean'
57+ }
58+
59+ // Run sanitize_array with array and schema
60+ console .log (sanitize_array (my_array,my_schema))
61+
62+ // Sanitized Output
63+ // [ { name: 'sam', age: 0, isEmployed: false },
64+ // { name: 'a', age: 456, isEmployed: false },
65+ // { name: 'c', age: 0, isEmployed: true },
66+ // { name: 'null', age: 123, isEmployed: true },
67+ // { name: 'asd', age: 123, isEmployed: false },
68+ // { name: '0', age: 123, isEmployed: false },
69+ // { name: 'sam', age: 123, isEmployed: false }
70+ // ]
71+
3872```
0 commit comments