Skip to content

Commit a39f86a

Browse files
authored
Update README.md
1 parent 0f29114 commit a39f86a

File tree

1 file changed

+35
-1
lines changed

1 file changed

+35
-1
lines changed

README.md

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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

2525
let arr = [1, 2];
2626
console.log(is_array(arr)); // true
@@ -35,4 +35,38 @@ console.log(object_to_array(objectX)); // ['Apple', 'Microsoft', 'Google']
3535
const mang = ['Microsoft', 'apple', 'netflix', 'Google'];
3636
const result = search_in_array("app", mang);
3737
console.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

Comments
 (0)