Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
N
NodeSharedCode
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
External wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Dojo Project (HES-SO)
Projects
Shared
NodeSharedCode
Commits
7a38696e
Commit
7a38696e
authored
2 years ago
by
michael.minelli
Browse files
Options
Downloads
Patches
Plain Diff
Add set of useful functions
parent
9aa0523e
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
Toolbox.ts
+44
-0
44 additions, 0 deletions
Toolbox.ts
with
44 additions
and
0 deletions
Toolbox.ts
0 → 100644
+
44
−
0
View file @
7a38696e
class
Toolbox
{
private
static
_instance
:
Toolbox
;
private
constructor
()
{
}
public
static
get
instance
():
Toolbox
{
if
(
!
Toolbox
.
_instance
)
{
Toolbox
.
_instance
=
new
Toolbox
();
}
return
Toolbox
.
_instance
;
}
public
randomString
(
length
:
number
)
{
let
result
=
''
;
let
characters
=
'
abcdefghjklmnopqrstuvwxyzABCDEFGHJKLMNOPQRSTUVWXYZ0123456789
'
;
let
charactersLength
=
characters
.
length
;
for
(
let
i
=
0
;
i
<
length
;
i
++
)
{
result
+=
characters
.
charAt
(
Math
.
floor
(
Math
.
random
()
*
charactersLength
));
}
return
result
;
}
public
capitalizingFirstLetter
(
word
:
string
):
string
{
return
word
.
charAt
(
0
).
toUpperCase
()
+
word
.
slice
(
1
);
}
public
capitalizeName
(
name
:
string
)
{
return
name
.
trim
().
replace
(
/
(?:
^|
\s
|-
)\S
/g
,
s
=>
s
.
toUpperCase
());
}
public
formatHour
(
hour
:
string
):
string
{
let
hourElements
=
hour
.
split
(
'
:
'
);
return
hourElements
[
0
]
+
'
h
'
+
hourElements
[
1
];
}
public
async
sleep
(
ms
:
number
)
{
await
new
Promise
(
r
=>
setTimeout
(
r
,
ms
));
}
}
export
default
Toolbox
.
instance
;
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment