extra-random-addon 1.0.0 → 1.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +19 -0
- package/index.js +33 -0
- package/package.json +19 -5
- package/desktop.ini +0 -2
package/README.md
CHANGED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
extra-random-addon
|
|
2
|
+
a simple package with simple "random" functions.
|
|
3
|
+
How to Install
|
|
4
|
+
In your specified terminal:
|
|
5
|
+
npm install extra-random-addon
|
|
6
|
+
Usage
|
|
7
|
+
import { randint ,minimum, maximum, randrandint, rand_colour_rgb, rand_colour_hex, choice } from "extra-random-addon"
|
|
8
|
+
API
|
|
9
|
+
randint(min,max) // returns an integer in between min and max (both included)
|
|
10
|
+
minimum // shorthand for -999999999999999
|
|
11
|
+
maximum // shorthand for 999999999999999
|
|
12
|
+
randrandint() // randint(min,max), but the min and max are both decided with a randint() function
|
|
13
|
+
rand_colour_rgb()¹ // returns three values that are all decided with randint(0,255)
|
|
14
|
+
rand_colour_hex()¹ // returns a random 7-character hex code
|
|
15
|
+
choice(array) // returns a random item inside the array
|
|
16
|
+
License
|
|
17
|
+
ISC
|
|
18
|
+
|
|
19
|
+
¹ yes it's spelt 'colour' not 'color'
|
package/index.js
CHANGED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
export function randint(min, max) {
|
|
2
|
+
if (typeof min === "number" && typeof max === "number"){
|
|
3
|
+
return Math.floor(Math.random() * (max - min + 1) ) + min;
|
|
4
|
+
}
|
|
5
|
+
else {
|
|
6
|
+
console.error("Error: one or both of the parameters are not numbers.")
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
export let minimum = -999999999999999
|
|
10
|
+
export let maximum = 999999999999999
|
|
11
|
+
export function randrandint(){
|
|
12
|
+
let min = randint(minimum,maximum)
|
|
13
|
+
let max = randint(minimum,maximum)
|
|
14
|
+
while (min>max){
|
|
15
|
+
min = randint(minimum,maximum)
|
|
16
|
+
max = randint(minimum,maximum)
|
|
17
|
+
}
|
|
18
|
+
return randint(min,max)
|
|
19
|
+
}
|
|
20
|
+
export function rand_colour_rgb(){
|
|
21
|
+
return ""+randint(0,255)+" "+randint(0,255)+" "+randint(0,255)+""
|
|
22
|
+
}
|
|
23
|
+
export function choice(array){
|
|
24
|
+
if (typeof array == "object"){
|
|
25
|
+
return array[randint(0,array.length-1)]
|
|
26
|
+
}
|
|
27
|
+
else {
|
|
28
|
+
console.error("Error: parameter is not an array")
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
export function rand_colour_hex(){
|
|
32
|
+
return "#"+choice([0,1,2,3,4,5,6,7,8,9,'a','b','c','d','e','f'])+""+choice([0,1,2,3,4,5,6,7,8,9,'a','b','c','d','e','f'])+""+choice([0,1,2,3,4,5,6,7,8,9,'a','b','c','d','e','f'])+""+choice([0,1,2,3,4,5,6,7,8,9,'a','b','c','d','e','f'])+""+choice([0,1,2,3,4,5,6,7,8,9,'a','b','c','d','e','f'])+""+choice([0,1,2,3,4,5,6,7,8,9,'a','b','c','d','e','f'])+""
|
|
33
|
+
}
|
package/package.json
CHANGED
|
@@ -1,13 +1,27 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "extra-random-addon",
|
|
3
|
-
"version": "1.0.
|
|
4
|
-
"description": "",
|
|
5
|
-
"main": "index.js",
|
|
3
|
+
"version": "1.0.2",
|
|
4
|
+
"description": "Some extra 'random' features to make coders' lives easier.",
|
|
5
|
+
"main": "./index.js",
|
|
6
|
+
"files": [
|
|
7
|
+
"index.js",
|
|
8
|
+
"README.md"
|
|
9
|
+
],
|
|
6
10
|
"scripts": {
|
|
7
11
|
"test": "echo \"Error: no test specified\" && exit 1"
|
|
8
12
|
},
|
|
9
|
-
"
|
|
13
|
+
"exports": {
|
|
14
|
+
".": "./index.js"
|
|
15
|
+
},
|
|
16
|
+
"keywords": [
|
|
17
|
+
"extra",
|
|
18
|
+
"random",
|
|
19
|
+
"rng"
|
|
20
|
+
],
|
|
10
21
|
"author": "",
|
|
11
22
|
"license": "ISC",
|
|
12
|
-
"type": "
|
|
23
|
+
"type": "module",
|
|
24
|
+
"dependencies": {
|
|
25
|
+
"extra-random-addon": "^1.0.1"
|
|
26
|
+
}
|
|
13
27
|
}
|
package/desktop.ini
DELETED