Skip to content

Commit c2d36a4

Browse files
authored
Merge branch 'main' into add-get-only-function
2 parents 562b745 + 6e3b72b commit c2d36a4

File tree

2 files changed

+247
-104
lines changed

2 files changed

+247
-104
lines changed

README.md

Lines changed: 42 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,45 @@ 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+
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'
64+
}
65+
66+
// Run sanitize_array with array and schema
67+
console.log(sanitize_array(my_array,my_schema))
68+
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+
// ]
78+
3879
```

0 commit comments

Comments
 (0)