-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Sv443
committed
Jan 25, 2021
1 parent
4debb6e
commit f143a6e
Showing
10 changed files
with
295 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
function insertValues(str, ...values) | ||
{ | ||
if(typeof str != "string") | ||
throw new TypeError(`Parameter "${str}" is not of type "string" (got "${typeof str}")`); | ||
|
||
if(!str.match(/%[0-9]+/g)) | ||
return str; | ||
|
||
values.forEach((arg, i) => { | ||
let rex = new RegExp(`%${i + 1}`); | ||
|
||
if(typeof arg !== "string" && typeof arg.toString == "function") | ||
arg = arg.toString(); | ||
|
||
if(str.match(rex)) | ||
{ | ||
try | ||
{ | ||
str = str.replace(rex, arg); | ||
} | ||
catch(err) | ||
{ | ||
throw new TypeError(`Value "${arg}" at index ${i} could not be inserted: ${err}`); | ||
} | ||
} | ||
}); | ||
|
||
return str; | ||
} | ||
|
||
module.exports = insertValues; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
/** | ||
* Sets the terminal window's title (supports Windows and *nix) | ||
* @param {String} title | ||
*/ | ||
function setWindowTitle(title) | ||
{ | ||
if(typeof title !== "string") | ||
{ | ||
if(typeof title.toString == "function") | ||
title = title.toString(); | ||
else | ||
throw new TypeError(`Parameter "title" is not of type string (got "${typeof title}")`); | ||
} | ||
|
||
if(process.platform != "win32") | ||
process.stdout.write(`\x1b]2;${title}\x1b\x5c`); // *nix doesn't have a "nice" way to set the window title but this escape sequence should be able to do it (for reference search "OSC control sequences" on this page: https://man7.org/linux/man-pages/man4/console_codes.4.html) | ||
else | ||
process.title = title; // This should work only on Windows | ||
} | ||
|
||
module.exports = setWindowTitle; |
Oops, something went wrong.