Skip to content

Commit 3dbc7dd

Browse files
committed
Adds comments ; Updates Readme
1 parent 9306ed5 commit 3dbc7dd

26 files changed

+1347
-481
lines changed

README.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,20 @@
11
# Ludivine - A TypeScript Boilerplate [![Build Status](https://travis-ci.org/acadet/ludivine.svg?branch=master)](https://travis-ci.org/acadet/ludivine)
22

3+
Inspired from C#.
4+
5+
# In brief
6+
7+
A great way to start your TS projects. Wraps delicious tools and structures such as:
8+
9+
* Collections
10+
- ArrayList, LinkedList, SortedList
11+
- Dictionary
12+
- Stack
13+
- Queue
14+
* Lambda interfaces
15+
* Core classes
16+
- Timers
17+
- Log
18+
- Exception
19+
20+
and other fantastic stuff! Feel free to browse the [Wiki](https://github.com/acadet/ludivine/wiki)!

src/Action.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,45 @@
11
/// <reference path="ref.ts" />
22

3+
/**
4+
* Actions are shortcuts for typing functions with no outcome
5+
*/
6+
7+
/**
8+
* @class Action0
9+
* @brief Action with no args
10+
*/
311
interface Action0 {
412
() : void;
513
}
614

15+
/**
16+
* @class Action
17+
* @brief Action expecting a single arg
18+
*/
719
interface Action<T> {
820
(t : T) : void;
921
}
1022

23+
/**
24+
* @class Action2
25+
* @brief Action expecting two args
26+
*/
1127
interface Action2<T, U> {
1228
(t : T, u : U) : void;
1329
}
1430

31+
/**
32+
* @class Action3
33+
* @brief Action expecting 3 args
34+
*/
1535
interface Action3<T, U, V> {
1636
(t : T, u : U, v : V) : void;
1737
}
1838

39+
/**
40+
* @class Action4
41+
* @type Action expecting 4 args
42+
*/
1943
interface Action4<T, U, V, W> {
2044
(t : T, u : U, v : V, w : W) : void;
2145
}

src/Exception.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,17 @@
11
/// <reference path="ref.ts" />
22

3+
/**
4+
* @class Exception
5+
* @brief Wraps any error.
6+
* @description User can extend this class to create his custom
7+
* exception.
8+
*/
39
class Exception {
410
//region Fields
511

12+
/**
13+
* Wrapped error
14+
*/
615
private _error : any;
716

817
//endregion Fields
@@ -24,18 +33,34 @@ class Exception {
2433

2534
//region Public Methods
2635

36+
/**
37+
* Gets inner message
38+
* @return {string} Inner message
39+
*/
2740
getMessage() : string {
2841
return this._error.message;
2942
}
3043

44+
/**
45+
* Gets name of exception
46+
* @return {string} Name of exception
47+
*/
3148
getName() : string {
3249
return this._error.name;
3350
}
3451

52+
/**
53+
* Gets stack trace
54+
* @return {string} Stack trace
55+
*/
3556
getStackTrace() : string {
3657
return this._error.stack;
3758
}
3859

60+
/**
61+
* Stringifies error
62+
* @return {string} [description]
63+
*/
3964
toString() : string {
4065
return this._error.name + ': ' + this._error.message;
4166
}

src/Func.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,45 @@
11
/// <reference path="ref.ts" />
22

3+
/**
4+
* Shortcuts for typing functions
5+
*/
6+
7+
/**
8+
* @class Func0
9+
* @brief Function with no args
10+
*/
311
interface Func0<U> {
412
() : U;
513
}
614

15+
/**
16+
* @class Func
17+
* @brief Function expecting a single arg
18+
*/
719
interface Func<T, U> {
820
(t: T) : U;
921
}
1022

23+
/**
24+
* @class Func2
25+
* @brief Function expecting 2 args
26+
*/
1127
interface Func2<T, U, V> {
1228
(t : T, u : U) : V;
1329
}
1430

31+
/**
32+
* @class Func3
33+
* @brief Function expecting 3 args
34+
*/
1535
interface Func3<T, U, V, W> {
1636
(t : T, u : U, v : V) : W
1737
}
1838

39+
/**
40+
* @class Func4
41+
* @brief Function expecting 4 args
42+
*/
1943
interface Func4<T, U, V, W, X> {
2044
(t : T, u : U, v : V, w : W) : X
2145
}

src/Guid.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
/// <reference path="ref.ts" />
22

3+
/**
4+
* @class Guid
5+
* @brief Procudes unique Guid
6+
*/
37
class Guid {
48
//region Fields
59

@@ -13,14 +17,19 @@ class Guid {
1317

1418
//region Private Methods
1519

20+
/**
21+
* Returns a random string using provided charset
22+
* @param {number} length Desired length
23+
* @return {string} Random string
24+
*/
1625
static _randomString(length : number) : string {
1726
if (length < 1) {
1827
return null;
1928
} else {
2029
var charSet : string = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
2130
var outcome : string = '';
2231

23-
for(var i = 0; i < length; i++) {
32+
for (var i = 0; i < length; i++) {
2433
var index : number;
2534

2635
index = Math.floor(Math.random() * charSet.length);
@@ -35,6 +44,10 @@ class Guid {
3544

3645
//region Public Methods
3746

47+
/**
48+
* Produces a new guid
49+
* @return {string} [description]
50+
*/
3851
static newGuid() : string {
3952
var outcome : StringBuffer;
4053

src/KeyValuePair.ts

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,32 @@
11
/// <reference path="ref.ts" />
22

3+
/**
4+
* @class KeyValuePair
5+
* @brief Pairs key and value
6+
*/
37
class KeyValuePair<T, U> {
48
//region Fields
59

10+
/**
11+
* Inner key
12+
*/
613
private _key : T;
14+
15+
/**
16+
* Inner value
17+
*/
718
private _value : U;
819

920
//endregion Fields
1021

1122
//region Constructors
1223

13-
constructor(key : T = null, value : U = null) {
24+
/**
25+
* Builds a new pair
26+
* @param {T} key Optional key
27+
* @param {U} value Optional value
28+
*/
29+
constructor(key? : T, value? : U) {
1430
this._key = key;
1531
this._value = value;
1632
}
@@ -25,18 +41,34 @@ class KeyValuePair<T, U> {
2541

2642
//region Public Methods
2743

44+
/**
45+
* Returns key
46+
* @return {T} [description]
47+
*/
2848
getKey() : T {
2949
return this._key;
3050
}
3151

52+
/**
53+
* Sets key
54+
* @param {T} key [description]
55+
*/
3256
setKey(key : T) : void {
3357
this._key = key;
3458
}
3559

60+
/**
61+
* Gets value
62+
* @return {U} [description]
63+
*/
3664
getValue() : U {
3765
return this._value;
3866
}
3967

68+
/**
69+
* Returns value
70+
* @param {U} value [description]
71+
*/
4072
setValue(value : U) : void {
4173
this._value = value;
4274
}

src/Log.ts

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
/// <reference path="ref.ts" />
2+
3+
/**
4+
* @class LogLevel
5+
* @brief Available levels of log
6+
*/
7+
enum LogLevel {
8+
Debug = 0, // all messages
9+
Test = 1, // only inform, warnings & errors
10+
Production = 2, // only warnings & erros
11+
Opaque = 3 // only errors
12+
}
13+
14+
/**
15+
* @class Log
16+
* @brief Simple log
17+
*/
18+
class Log {
19+
//region Fields
20+
21+
/**
22+
* Current level of log. Default value to Debug
23+
*/
24+
private static _currentLevel : LogLevel = LogLevel.Debug;
25+
26+
//endregion Fields
27+
28+
//region Constructors
29+
30+
//endregion Constructors
31+
32+
//region Methods
33+
34+
//region Private Methods
35+
36+
//endregion Private Methods
37+
38+
//region Public Methods
39+
40+
/**
41+
* Sets current level of log
42+
* @param {LogLevel} level Desired level
43+
*/
44+
static setLevel(level : LogLevel) : void {
45+
Log._currentLevel = level;
46+
}
47+
48+
/**
49+
* Prints a debug message
50+
* @param {string} msg Message
51+
*/
52+
static debug(msg : string) : void {
53+
if (this._currentLevel <= LogLevel.Debug) {
54+
console.log('DEBUG: ' + msg);
55+
}
56+
}
57+
58+
/**
59+
* Prints information
60+
* @param {string} msg Message
61+
*/
62+
static inform(msg : string) : void {
63+
if (this._currentLevel <= LogLevel.Test) {
64+
console.log('%cINFORM: ' + msg, 'color: DeepSkyBlue;');
65+
}
66+
}
67+
68+
/**
69+
* Prints warning
70+
* @param {string} msg Message
71+
*/
72+
static warn(msg : string) : void {
73+
if (this._currentLevel <= LogLevel.Production) {
74+
console.log('%cWARN: ' + msg, 'color: orange;');
75+
}
76+
}
77+
78+
/**
79+
* Prints an error
80+
* @param {Exception} error Exception
81+
*/
82+
static error(error : Exception) : void {
83+
console.error('Error: ' + error.toString());
84+
}
85+
86+
//endregion Public Methods
87+
88+
//endregion Methods
89+
}

0 commit comments

Comments
 (0)