Skip to content

Commit 8a1f350

Browse files
authored
Merge branch 'main' into feature/update-docs
2 parents 50ebd81 + 631d3b6 commit 8a1f350

File tree

3 files changed

+320
-115
lines changed

3 files changed

+320
-115
lines changed

CONTRIBUTING.md

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
Whether you are a pro or a someone who is just starting their Open-Source journey, everyone can contribute to make this package better. To make things consistent, please follow the below mentioned points.
2+
3+
# Guidelines
4+
5+
- Please be sure you have your branch in sync with the `main` branch.
6+
- Please follow `snake_case` convention wherever possible.
7+
- Do go through the list of already implemented functions to avoid duplication.
8+
- The PR you make should have the following points
9+
- New function name
10+
- Short Description
11+
- References (documentation, links, etc.)
12+
- Limitations (If it has any edge cases)
13+
- The function code should also carry appropriate JSDOC comments and a small example displaying both input and output of your function.
14+
15+
# Example PR
16+
17+
```javascript
18+
// index.js
19+
/**
20+
* Some small description
21+
*
22+
* @param array param
23+
* @return array
24+
*/
25+
function some_new_function(param) {
26+
// Your Logic
27+
return value;
28+
}
29+
```
30+
31+
```javascript
32+
// README.md
33+
import { some_new_function } from @hetarth02/js-array-helpers;
34+
35+
console.log(some_new_function(param)); // Output
36+
```
37+
38+
- some_new_function
39+
- This function does this thing.
40+
- param can only be array

README.md

Lines changed: 50 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,34 +9,71 @@ Array Helper functions for your quick use.
99
npm 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

1418
In 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

2025
let arr = [1, 2];
2126
console.log(is_array(arr)); // true
22-
```
2327

24-
### object_to_array
25-
```js
2628
const 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

Comments
 (0)