Skip to content

Commit 02801ce

Browse files
committed
✨ update Readme
1 parent ac30dec commit 02801ce

File tree

1 file changed

+67
-10
lines changed

1 file changed

+67
-10
lines changed

README.md

Lines changed: 67 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
# missing-native-JS-functions
22

3-
mnJSf that should be the base lib for every JS project
3+
mnJSf that should be the base lib for every JS project whether for browser or nodejs
44

5-
This library extends the property of `Array`, `Object` and `Array`
5+
This library extends the properties of `Array`, `Object`, `Promise`, `Global` and `String`
66

77
## Installation
88

@@ -19,12 +19,18 @@ ES5 import
1919
require("missing-native-js-functions");
2020
```
2121

22-
or ES6 import
22+
ES6 import
2323

2424
```js
2525
import "missing-native-js-functions";
2626
```
2727

28+
use in Browser
29+
```html
30+
<script src="https://cdn.jsdelivr.net/npm/missing-native-js-functions/dist/mnjsf.min.js"></script>
31+
```
32+
33+
2834
## [Reference](/dist/index.d.ts)
2935

3036
### [Array](/dist/Array.d.ts)
@@ -41,6 +47,8 @@ Array {
4147
shuffle(): T[]; // shuffles the current array
4248
insert(elem: T, index: number): T[]; // insert an element at a specified index
4349
count(search: RegExp | any): number; // returns total of found items for specified search
50+
similarities(arr: T[]): T[]; // returns a new array with elements that are both in this array and in the comparison array
51+
missing(arr: T[]): T[]; // returns a new array with elements that are in this array, but are missing in the comparison array
4452
}
4553
```
4654

@@ -55,7 +63,7 @@ Object {
5563
keys(): string[]; //returns keys of object itself
5664
values(): any[]; // returns values of object itself
5765
entries(): Array<[string, any]>; // returns a nested array of key and corresponding value of object itself
58-
merge(obj: any): any // returns a new object deeply merged with obj, the current will overwrite obj, if obj has the same property
66+
merge(obj: any): any // returns a new object deeply merged with obj, the current will overwrite obj, if obj has the same property. Notice will not merge classes
5967
}
6068
```
6169

@@ -67,12 +75,29 @@ String {
6775
replaceAll(search: string, replace: string): string; // Replace all occurrences of search with replace
6876
similarity(compare: string): number; // Returns a value between 0 (different) and 1 (same) indicating how similar the string is to compare
6977
join(iterate: string[]): string; // Returns the array values seperated by the given divider as a string
70-
partition(): string[]; // Returns split array, but includes separators
78+
partition(separator: string): string[]; // Returns split array, but includes separators
7179
toNumber(): number; // converts string to number, if not a number returns NaN
7280
toBigInt(): number; // converts string to BigInt, if not a number returns NaN
7381
count(countString: RegExp | any): number; // returns total of found items for specified search;
74-
swapcase(): string;// Returns a swapped case string
75-
title(): string; // converts the string into a title string
82+
swapcase(): string;// Returns a swapped case string -> aLL CASES ARE SWAPPED
83+
title(): string; // converts the string into a title string -> This Is A Title String
84+
}
85+
```
86+
87+
### [Promise](/dist/Promise.d.ts)
88+
89+
```ts
90+
Promise {
91+
caught(): this; // catch all errors in the console without the need to specify a function, similar like promise.catch(console.error)
92+
}
93+
```
94+
95+
### [Global](/dist/Global.d.ts)
96+
97+
```ts
98+
Global {
99+
function atob(data: string): string; // Converts a Base64 encoded string back to UTF-8
100+
function btoa(data: string): string; // Converts a UTF-8 string to a Base64 encoded string
76101
}
77102
```
78103

@@ -125,6 +150,18 @@ console.log(array.count("test"));
125150
// -> 3
126151
console.log(array.count(15));
127152
// -> 1
153+
154+
console.log("last number divisable by 2: " + arr.findLast((x) => x % 2 == 0));
155+
// -> 8
156+
console.log("index of it: " + arr.findLastIndex((x) => x % 2 == 0));
157+
// -> 7
158+
159+
console.log("Similarities between to arrays", [0, 1, 2, 3, 4].similarities([0, 2, 4, 6, 8, 10]));
160+
// -> [ 0, 2, 4 ]
161+
162+
console.log("Missing values in comparison array", [0, 1, 2, 3, 4, 5].missing([0, 5]));
163+
// -> [ 1, 2, 3, 4 ]
164+
128165
```
129166

130167
### Object
@@ -182,17 +219,37 @@ console.log(", ".join(words));
182219
// -> test, hello, 1234
183220

184221
const wordList = "test.hello.1234";
185-
console.log(wordList.partition());
222+
console.log(wordList.partition("."));
186223
// -> ["test", ".", "hello", ".", "1234"]
187224

188225
"25".toNumber();
189-
// -> 25: number
226+
// -> 25
227+
190228
"25".toBigInt();
191-
// -> 25n:
229+
// -> 25n
192230

193231
"This is a Thonk Text".swapcase();
194232
// -> tHIS IS A tHONK tEXT
195233

196234
"this is a test".title();
197235
// -> This Is A Test
198236
```
237+
238+
### Promise
239+
```js
240+
new Promise((res, rej) => {
241+
rej("Promised rejected, but caught in console.error");
242+
}).caught();
243+
// -> will not throw the promise, but log the error in the console
244+
```
245+
246+
### Global
247+
```js
248+
const convert = "this string will be base64 encoded";
249+
const converted = btoa("this string was base64 encoded");
250+
console.log(convert, btoa(convert));
251+
// -> this string will be base64 encoded dGhpcyBzdHJpbmcgd2lsbCBiZSBiYXNlNjQgZW5jb2RlZA==
252+
253+
console.log(atob(converted), converted);
254+
// -> this string was base64 encoded dGhpcyBzdHJpbmcgd2FzIGJhc2U2NCBlbmNvZGVk
255+
```

0 commit comments

Comments
 (0)