Greasy Fork

Str Lib

String helper functions

目前为 2017-02-11 提交的版本。查看 最新版本

此脚本不应直接安装,它是一个供其他脚本使用的外部库。如果您需要使用该库,请在脚本元属性加入:// @require https://update.greasyfork.icu/scripts/27278/174477/Str%20Lib.js

// region [ Str Lib ]
var Str = {};

Str.trim = function (s) {
	return s.replace(/^\s+/, '').replace(/\s+$/, '');
};

Str.padRight = function(s, padStr, totalLength){
	return s.length >= totalLength  ? s : s + Str.repeat(padStr, (totalLength-s.length)/padStr.length);
};

Str.repeat = function(s, count) {
	var newS = "", i;
	for (i=0; i<count; i++) {
		newS += s;
	}
	return newS;
};
// endregion