[add] typescript logic
Christian Fraß authored 3 years ago
|
source/helpers/string.ts 1) namespace helpers.string
source/helpers/string.ts 2) {
source/helpers/string.ts 3)
source/helpers/string.ts 4) /**
source/helpers/string.ts 5) */
source/helpers/string.ts 6) export function coin
source/helpers/string.ts 7) (
source/helpers/string.ts 8) template : string,
source/helpers/string.ts 9) arguments_ : {[key : string] : string},
source/helpers/string.ts 10) open : string = "{{",
source/helpers/string.ts 11) close : string = "}}"
source/helpers/string.ts 12) ) : string
source/helpers/string.ts 13) {
source/helpers/string.ts 14) let result : string = template;
source/helpers/string.ts 15) for (let [key, value] of Object.entries(arguments_))
source/helpers/string.ts 16) {
source/helpers/string.ts 17) const pattern : string = (open + key + close);
source/helpers/string.ts 18) result = result.replace(new RegExp(pattern, "g"), value);
source/helpers/string.ts 19) }
source/helpers/string.ts 20) return result;
source/helpers/string.ts 21) }
source/helpers/string.ts 22)
|
[mod] makefile
Christian Fraß authored 3 years ago
|
source/helpers/string.ts 23)
source/helpers/string.ts 24) export function pad_left
source/helpers/string.ts 25) (
source/helpers/string.ts 26) subject : string,
source/helpers/string.ts 27) length : int,
source/helpers/string.ts 28) filler : string
source/helpers/string.ts 29) ) : string
source/helpers/string.ts 30) {
source/helpers/string.ts 31) let result : string = subject;
source/helpers/string.ts 32) while (result.length < length)
source/helpers/string.ts 33) {
source/helpers/string.ts 34) result = (filler + result);
source/helpers/string.ts 35) }
source/helpers/string.ts 36) return result;
source/helpers/string.ts 37) }
source/helpers/string.ts 38)
|