BetterNode
Installation
Import is as any other library.
;
Yes. That's it all.
Arrays
1. Chunk
Split an array of element in to groups with the same size.
let arr = 1 2 3 4 5 6 7 8 9 10;console; // Output: [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ], [ 7, 8 ], [ 9, 10 ] ]console; // Output: [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ], [ 10 ] ]console; // Output: [ [ 1, 2, 3, 4 ], [ 5, 6, 7, 8 ], [ 9, 10 ] ]
2. Compact
Remove all falsey values from an array
let arr = 1 false 3 null "5" 0 7 "text"console; // Output: [ 1, 3, '5', 7 ]
3. Difference
Creates an array of values not included in the other given array
let arr1 = 1 2 4 5;let arr2 = 1 3 5 6; console; // Output: [ 2, 4 ]
4. Drop Slice an array in the specified position from the beginning
let arr = 1 2 3 4 5 6 7 8;console; // Output: [ 2, 3, 4, 5, 6, 7, 8 ]console; // Output: [ 3, 4, 5, 6, 7, 8 ]console; // Output: [ 4, 5, 6, 7, 8 ]
5. Drop Right
Slice an array in the specified position from the end
let arr = 1 2 3 4 5 6 7 8;console; // Output: [ 1, 2, 3, 4, 5, 6, 7 ]console; // Output: [ 1, 2, 3, 4, 5, 6 ]console; // Output: [ 1, 2, 3, 4, 5 ]
6. DropIf
Remove an item of the array if the condition is true
let arr = "rock" "plane" "apple" "rise" "banana" "red"; console
7. First
Get the first element of the array
let arr = "blue" "green" "red" "yellow"console; // Output: blue
8. Last
Get the last element of the array
let arr = "blue" "green" "red" "yellow"console; // Output: yellow
9. Remove
Removes an object from the array
let arr = "blue" "green" "red" "yellow"console; // Output: ["blue", "red", "yellow"]
10. Take Take values from the array starting at the specified position from the beginning
let arr = "rock" "plane" "apple" "rise" "banana" "red";console; // Output: [ 'rock', 'plane' ]
11. Take Right
Take values from the array starting at the specified position from the end
let arr = "rock" "plane" "apple" "rise" "banana" "red";console; // Output: [ 'banana', 'red' ]
12. Take If
Take elements of an array from the beginning while the callback condition is true
let arr = "rock" "plane" "apple" "rise" "banana" "red"; console
13. Union
Create an array of unique values from other or multiple arrays
let arr = "airplane" "bed" "cow" "dog";let arr2 = "pig" "apple" "dog" "apple"; console; // Output: [ 'airplane', 'bed', 'cow', 'dog', 'pig', 'apple' ]
14. Unique
Create an array from the unique values of the original array
let arr = 1 2 1 3 4 5 3 6 2; console; // Output: [ 1, 2, 3, 4, 5, 6 ]
Numbers
1. Clamp
Find a value between two values
let number = 12; console; // Output: 7console; // Output: 12console; // Output: 14
2. Cos
Returns the cos of a number
let number = 5;console; // Output: 0.28366218546322625
3. isEven
Return true if the number is event
let number = 12;console; // Output: true
4. Lerp
Interpolate between two values
let number = 5;console; // Output: -2.5
5. Percentage
Get the percentage of a number
let number = 500;console; // Output: 125
6. Pow Pow a number y a exponent
let number = 3;console; // Output: 8console; // Output: 27
7. Sin
Returns the sin of a number
let number = 2;console; // Output: 0.9092974268256817
8. Sqrt
Get square root of a number
let number = 25;console; // Output: 5
9. Tan
Returns the tan of a number
let number = 6;console; // Output: -0.29100619138474915
Objects
1. Get Field
Finds a field in the object with a string and returns the result
let obj = "a": "b": "c": "Hello world" console; // Output: Hello world
Strings
1. Capitalize
Capitalize the first character of the string
let str = "hello my friend";console; // Output: Hello my friend
2. Capitalize All
Set all characters to lowercase except first character of each word
let str = "hello my friend";console; // Output: Hello My Friend
3. Escape HTML
Escapes HTML string
let str = "<a>Hello & Welcome</a>";console; // Output: <a>Hello & Welcome</a>
4. Is Empty Returns true if string is empty or whitespaces
let str = "";console; // Output: true
5. Is Lowercase
Check if the string is uppercase
let str = "hello";console; // Output: true let str2 = "Hello";console; // Output: false
6. Is Uppercase
Check if the string is uppercase
let str = "HELLO";console; // Output: true let str2 = "HELLo";console; // Output: false
7. Print
Log in the console a string
let str = "hello world";str; // Output: hello world
8. Normalize Spaces
Normalize doublespaces
let str = "hello world to my friends !";console; // Output: "hello world to my friends !"
9. Replace All
Replace all in a string
let str = "the car is red, red is the car";console
10. To Bool
Parse to Boolean a string
let str = "true";console; // Output: true; let str2 = "false";console; // Output: false; let str3 = "a text";console; // Output: null;
11. To Float
Parse to Float a string
let str = "3.141592";console; // Output: 3.141592
12. To Integer
Parse to Integer a string
let str = "45";console; // Output: 45
13. To JSON
Parse to JSON a string
let str = "{\"hello\": \"world\"}";console; // Output: { hello: 'world' }
14. Truncate
Truncate a text and make it more shortly
let str = "hello world";console; // Output: hello w...
15. Words
Get array of words in a string
let str = "the apple is red";console; // Output: ["the", "apple", "is", "red"]