Skip to content

Commit 27ffcf4

Browse files
authored
Enabling import
Added support to import the library via import statement
2 parents 5d9ab76 + 66c1a25 commit 27ffcf4

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

63 files changed

+693
-35
lines changed

.idea/.gitignore

+8
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/functionality.js.iml

+8
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/modules.xml

+8
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/vcs.xml

+6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/functionality.min.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

gulpfile.js

+17-8
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,13 @@ var pug = require("gulp-pug");
1111
var livereload = require("gulp-livereload");
1212
var zip = require("gulp-zip");
1313
var sourcemaps = require("gulp-sourcemaps");
14-
var browserify = require("browserify");
15-
var source = require("vinyl-source-stream");
16-
var tsify = require("tsify");
17-
var sourcemaps = require("gulp-sourcemaps");
18-
var buffer = require("vinyl-buffer");
1914

2015
// HTML Task
2116
gulp.task("html", () => {
2217
require("./server.js");
2318
return gulp
2419
.src(["./project/html/*.pug", "./project/html/pages/*.pug"])
25-
.pipe(pug({ pretty: false }))
20+
.pipe(pug({pretty: false}))
2621
.pipe(gulp.dest("./website"))
2722
.pipe(livereload());
2823
});
@@ -64,11 +59,17 @@ gulp.task("scripts", () => {
6459
.pipe(livereload());
6560
});
6661

62+
// Functionalty.js File Task
6763
// var ts = require("gulp-typescript");
6864
// var tsProject = ts.createProject("tsconfig.json");
6965

70-
// Main Library Task
7166
gulp.task("functionality", () => {
67+
var browserify = require("browserify");
68+
var source = require("vinyl-source-stream");
69+
var tsify = require("tsify");
70+
var sourcemaps = require("gulp-sourcemaps");
71+
var buffer = require("vinyl-buffer");
72+
7273
livereload.listen();
7374
require("./server.js");
7475
return browserify({
@@ -89,6 +90,13 @@ gulp.task("functionality", () => {
8990
.pipe(uglify())
9091
.pipe(gulp.dest("dist"));
9192
});
93+
gulp.task("functionality.npm-lib", () => {
94+
var ts = require("gulp-typescript");
95+
var tsProject = ts.createProject("tsconfig.npm.json");
96+
97+
livereload.listen();
98+
return tsProject.src().pipe(tsProject()).js.pipe(gulp.dest("lib"));
99+
});
92100

93101
// Compressing The Dist Folder For The User
94102
gulp.task("compress", () => {
@@ -114,5 +122,6 @@ gulp.task("watch", () => {
114122
gulp.series("scripts")
115123
);
116124

117-
gulp.watch("./project/ts/functionality/*.ts", gulp.series("functionality"));
125+
gulp.watch("./project/ts/functionality/**/*.ts", gulp.series("functionality"));
126+
gulp.watch("./project/ts/functionality/**/*.ts", gulp.series("functionality.npm-lib"));
118127
});

index.js

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export {default as functionality} from './lib/main.js';
File renamed without changes.
File renamed without changes.

lib/array/filterArray.js

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/**
2+
* Filter an array depending on the given value
3+
*
4+
* @param {any[]} array
5+
* @param {any} value
6+
* @returns {any[]}
7+
*/
8+
export default function filterArray(array, value) {
9+
if (!Array.isArray(array)) {
10+
throw new TypeError("Expected an array but got " + typeof array);
11+
}
12+
return array.filter((e) => e != value);
13+
}

lib/array/getFactors.js

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/**
2+
* returns the factors of the given number
3+
*
4+
* @param {number} number
5+
* @returns {number[]}
6+
*/
7+
export default function getFactors(number) {
8+
if (typeof number !== "number") {
9+
throw new TypeError("Expected a number but got " + typeof number);
10+
}
11+
return [...Array(number + 1).keys()].filter((i) => number % i === 0);
12+
}

lib/array/maxArray.js

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/**
2+
* Get maximum value in array
3+
*
4+
* @param {number[]} array
5+
* @returns {number}
6+
*/
7+
export default function maxArray(array) {
8+
if (!Array.isArray(array)) {
9+
throw new TypeError("Expected an array but got " + typeof array);
10+
}
11+
return Math.max(...array); // using math.max() to get maximum value in array is faster than using a for loop
12+
}

lib/array/minArray.js

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/**
2+
* Get minimum value in array
3+
*
4+
* @param {number[]} array - Array of numbers
5+
* @returns {number}
6+
*/
7+
export default function minArray(array) {
8+
if (!Array.isArray(array)) {
9+
throw new TypeError("Expected an array but got " + typeof array);
10+
}
11+
return Math.min(...array); // using math.min() to get minimum value in array is faster than using a for loop
12+
}

lib/array/randomElementFrom.js

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/**
2+
* Get a random element from an array
3+
*
4+
* @param {any[]} array
5+
* @returns {any}
6+
*/
7+
export default function randomElementFrom(array) {
8+
if (!Array.isArray(array)) {
9+
throw new TypeError("Expected an array but got " + typeof array);
10+
}
11+
return array[Math.floor(Math.random() * array.length)];
12+
}

lib/array/removeDuplicate.js

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/**
2+
* Remove duplicated Elemets in array
3+
*
4+
* @param {any[]} array
5+
* @returns {any[]}
6+
*/
7+
export default function removeDuplicate(array) {
8+
if (!Array.isArray(array)) {
9+
throw new TypeError("Expected an array but got " + typeof array);
10+
}
11+
array.filter(function (ele, index) {
12+
return [...new Set(array)];
13+
});
14+
}

lib/array/shuffle.js

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/**
2+
* sort the array randomly
3+
*
4+
* @param {any[]} array array of anything
5+
* @returns {array} sort of the array
6+
*/
7+
export default function shuffle(array) {
8+
if (!Array.isArray(array)) {
9+
throw new TypeError("Expected an array");
10+
}
11+
return array.sort((a, b) => 0.5 - Math.random());
12+
}

lib/array/sumOfArray.js

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/**
2+
* Get sum of all numbers in array
3+
*
4+
* @param {number[]} array array of numbers
5+
* @returns {number} sum of all numbers in array
6+
*/
7+
export default function sumOfArray(array) {
8+
if (!Array.isArray(array) || array.some((ele) => typeof ele !== "number")) {
9+
throw new TypeError("Expected an array of numbers but got " +
10+
(Array.isArray(array) ? "array" : typeof array));
11+
}
12+
return array.reduce((a, b) => a + b, 0);
13+
}

lib/colors/randomBoolean.js

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
/**
2+
* returns a random boolean (true or false)
3+
*
4+
* @returns {boolean}
5+
*/
6+
export default function randomBoolean() {
7+
return Math.random() >= 0.5;
8+
}

lib/colors/randomColor.js

+158
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,158 @@
1+
/**
2+
* displays a random color
3+
*
4+
* @returns {string}
5+
*/
6+
export default function randomColor() {
7+
const CSS_COLOR_NAMES = [
8+
"AliceBlue",
9+
"AntiqueWhite",
10+
"Aqua",
11+
"Aquamarine",
12+
"Azure",
13+
"Beige",
14+
"Bisque",
15+
"Black",
16+
"BlanchedAlmond",
17+
"Blue",
18+
"BlueViolet",
19+
"Brown",
20+
"BurlyWood",
21+
"CadetBlue",
22+
"Chartreuse",
23+
"Chocolate",
24+
"Coral",
25+
"CornflowerBlue",
26+
"Cornsilk",
27+
"Crimson",
28+
"Cyan",
29+
"DarkBlue",
30+
"DarkCyan",
31+
"DarkGoldenRod",
32+
"DarkGray",
33+
"DarkGrey",
34+
"DarkGreen",
35+
"DarkKhaki",
36+
"DarkMagenta",
37+
"DarkOliveGreen",
38+
"DarkOrange",
39+
"DarkOrchid",
40+
"DarkRed",
41+
"DarkSalmon",
42+
"DarkSeaGreen",
43+
"DarkSlateBlue",
44+
"DarkSlateGray",
45+
"DarkSlateGrey",
46+
"DarkTurquoise",
47+
"DarkViolet",
48+
"DeepPink",
49+
"DeepSkyBlue",
50+
"DimGray",
51+
"DimGrey",
52+
"DodgerBlue",
53+
"FireBrick",
54+
"FloralWhite",
55+
"ForestGreen",
56+
"Fuchsia",
57+
"Gainsboro",
58+
"GhostWhite",
59+
"Gold",
60+
"GoldenRod",
61+
"Gray",
62+
"Grey",
63+
"Green",
64+
"GreenYellow",
65+
"HoneyDew",
66+
"HotPink",
67+
"IndianRed",
68+
"Indigo",
69+
"Ivory",
70+
"Khaki",
71+
"Lavender",
72+
"LavenderBlush",
73+
"LawnGreen",
74+
"LemonChiffon",
75+
"LightBlue",
76+
"LightCoral",
77+
"LightCyan",
78+
"LightGoldenRodYellow",
79+
"LightGray",
80+
"LightGrey",
81+
"LightGreen",
82+
"LightPink",
83+
"LightSalmon",
84+
"LightSeaGreen",
85+
"LightSkyBlue",
86+
"LightSlateGray",
87+
"LightSlateGrey",
88+
"LightSteelBlue",
89+
"LightYellow",
90+
"Lime",
91+
"LimeGreen",
92+
"Linen",
93+
"Magenta",
94+
"Maroon",
95+
"MediumAquaMarine",
96+
"MediumBlue",
97+
"MediumOrchid",
98+
"MediumPurple",
99+
"MediumSeaGreen",
100+
"MediumSlateBlue",
101+
"MediumSpringGreen",
102+
"MediumTurquoise",
103+
"MediumVioletRed",
104+
"MidnightBlue",
105+
"MintCream",
106+
"MistyRose",
107+
"Moccasin",
108+
"NavajoWhite",
109+
"Navy",
110+
"OldLace",
111+
"Olive",
112+
"OliveDrab",
113+
"Orange",
114+
"OrangeRed",
115+
"Orchid",
116+
"PaleGoldenRod",
117+
"PaleGreen",
118+
"PaleTurquoise",
119+
"PaleVioletRed",
120+
"PapayaWhip",
121+
"PeachPuff",
122+
"Peru",
123+
"Pink",
124+
"Plum",
125+
"PowderBlue",
126+
"Purple",
127+
"RebeccaPurple",
128+
"Red",
129+
"RosyBrown",
130+
"RoyalBlue",
131+
"SaddleBrown",
132+
"Salmon",
133+
"SandyBrown",
134+
"SeaGreen",
135+
"SeaShell",
136+
"Sienna",
137+
"Silver",
138+
"SkyBlue",
139+
"SlateBlue",
140+
"SlateGray",
141+
"SlateGrey",
142+
"Snow",
143+
"SpringGreen",
144+
"SteelBlue",
145+
"Tan",
146+
"Teal",
147+
"Thistle",
148+
"Tomato",
149+
"Turquoise",
150+
"Violet",
151+
"Wheat",
152+
"White",
153+
"WhiteSmoke",
154+
"Yellow",
155+
"YellowGreen",
156+
];
157+
return CSS_COLOR_NAMES[Math.floor(Math.random() * CSS_COLOR_NAMES.length)];
158+
}

lib/colors/randomHex.js

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
/**
2+
* returns a random hex color e.g #f35a00
3+
*
4+
* @returns {string}
5+
*/
6+
export default function randomHex() {
7+
return `#${Math.floor(Math.random() * 0xffffff)
8+
.toString(16)
9+
.padEnd(6, "0")}`;
10+
}

lib/colors/randomHsl.js

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
/**
2+
* displays a random hsl color
3+
*
4+
* @returns {string}
5+
*/
6+
export default function randomHsl() {
7+
const h = Math.floor(Math.random() * 360);
8+
const s = Math.floor(Math.random() * 100);
9+
const l = Math.floor(Math.random() * 100);
10+
return `hsl(${h}, ${s}%, ${l}%)`;
11+
}

0 commit comments

Comments
 (0)