SB-6.1-PRE
This commit is contained in:
1 parent
690169a409
commit
358a25f522
3760 files changed
+300059
-36
No files matched your search
+57
@@ -0,0 +1,57 @@
|
||||
/**
|
||||
* Converts a string to an array of string chars
|
||||
* @param {string} str The string to turn into array
|
||||
* @returns {string[]}
|
||||
*/
|
||||
export declare function toArray(str: string): string[];
|
||||
/**
|
||||
* Returns the length of a string
|
||||
*
|
||||
* @export
|
||||
* @param {string} str
|
||||
* @returns {number}
|
||||
*/
|
||||
export declare function length(str: string): number;
|
||||
/**
|
||||
* Returns a substring by providing start and end position
|
||||
*
|
||||
* @export
|
||||
* @param {string} str
|
||||
* @param {number} [begin=0] Starting position
|
||||
* @param {number} end End position
|
||||
* @returns {string}
|
||||
*/
|
||||
export declare function substring(str: string, begin?: number, end?: number): string;
|
||||
/**
|
||||
* Returns a substring by providing start position and length
|
||||
*
|
||||
* @export
|
||||
* @param {string} str
|
||||
* @param {number} [begin=0] Starting position
|
||||
* @param {number} len Desired length
|
||||
* @returns {string}
|
||||
*/
|
||||
export declare function substr(str: string, begin?: number, len?: number): string;
|
||||
/**
|
||||
* Enforces a string to be a certain length by
|
||||
* adding or removing characters
|
||||
*
|
||||
* @export
|
||||
* @param {string} str
|
||||
* @param {number} [limit=16] Limit
|
||||
* @param {string} [padString='#'] The Pad String
|
||||
* @param {string} [padPosition='right'] The Pad Position
|
||||
* @returns {string}
|
||||
*/
|
||||
export declare function limit(str: string, limit?: number, padString?: string, padPosition?: string): string;
|
||||
/**
|
||||
* Returns the index of the first occurrence of a given string
|
||||
*
|
||||
* @export
|
||||
* @param {string} str
|
||||
* @param {string} [searchStr] the string to search
|
||||
* @param {number} [pos] starting position
|
||||
* @returns {number}
|
||||
*/
|
||||
export declare function indexOf(str: string, searchStr: string, pos?: number): number;
|
||||
//# sourceMappingURL=index.d.ts.map
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAGA;;;;GAIG;AACH,wBAAgB,OAAO,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,EAAE,CAK7C;AAED;;;;;;GAMG;AACH,wBAAgB,MAAM,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAQ1C;AAED;;;;;;;;GAQG;AACH,wBAAgB,SAAS,CACvB,GAAG,EAAE,MAAM,EACX,KAAK,GAAE,MAAU,EACjB,GAAG,CAAC,EAAE,MAAM,GACX,MAAM,CAmBR;AAED;;;;;;;;GAQG;AACH,wBAAgB,MAAM,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,GAAE,MAAU,EAAE,GAAG,CAAC,EAAE,MAAM,GAAG,MAAM,CAwC3E;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,KAAK,CACnB,GAAG,EAAE,MAAM,EACX,KAAK,GAAE,MAAW,EAClB,SAAS,GAAE,MAAY,EACvB,WAAW,GAAE,MAAgB,GAC5B,MAAM,CA2BR;AAED;;;;;;;;GAQG;AACH,wBAAgB,OAAO,CACrB,GAAG,EAAE,MAAM,EACX,SAAS,EAAE,MAAM,EACjB,GAAG,GAAE,MAAU,GACd,MAAM,CAgDR"}
|
||||
+199
@@ -0,0 +1,199 @@
|
||||
"use strict";
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
// @ts-ignore
|
||||
var char_regex_1 = __importDefault(require("char-regex"));
|
||||
/**
|
||||
* Converts a string to an array of string chars
|
||||
* @param {string} str The string to turn into array
|
||||
* @returns {string[]}
|
||||
*/
|
||||
function toArray(str) {
|
||||
if (typeof str !== 'string') {
|
||||
throw new Error('A string is expected as input');
|
||||
}
|
||||
return str.match(char_regex_1.default()) || [];
|
||||
}
|
||||
exports.toArray = toArray;
|
||||
/**
|
||||
* Returns the length of a string
|
||||
*
|
||||
* @export
|
||||
* @param {string} str
|
||||
* @returns {number}
|
||||
*/
|
||||
function length(str) {
|
||||
// Check for input
|
||||
if (typeof str !== 'string') {
|
||||
throw new Error('Input must be a string');
|
||||
}
|
||||
var match = str.match(char_regex_1.default());
|
||||
return match === null ? 0 : match.length;
|
||||
}
|
||||
exports.length = length;
|
||||
/**
|
||||
* Returns a substring by providing start and end position
|
||||
*
|
||||
* @export
|
||||
* @param {string} str
|
||||
* @param {number} [begin=0] Starting position
|
||||
* @param {number} end End position
|
||||
* @returns {string}
|
||||
*/
|
||||
function substring(str, begin, end) {
|
||||
if (begin === void 0) { begin = 0; }
|
||||
// Check for input
|
||||
if (typeof str !== 'string') {
|
||||
throw new Error('Input must be a string');
|
||||
}
|
||||
// Even though negative numbers work here, theyre not in the spec
|
||||
if (typeof begin !== 'number' || begin < 0) {
|
||||
begin = 0;
|
||||
}
|
||||
if (typeof end === 'number' && end < 0) {
|
||||
end = 0;
|
||||
}
|
||||
var match = str.match(char_regex_1.default());
|
||||
if (!match)
|
||||
return '';
|
||||
return match.slice(begin, end).join('');
|
||||
}
|
||||
exports.substring = substring;
|
||||
/**
|
||||
* Returns a substring by providing start position and length
|
||||
*
|
||||
* @export
|
||||
* @param {string} str
|
||||
* @param {number} [begin=0] Starting position
|
||||
* @param {number} len Desired length
|
||||
* @returns {string}
|
||||
*/
|
||||
function substr(str, begin, len) {
|
||||
if (begin === void 0) { begin = 0; }
|
||||
// Check for input
|
||||
if (typeof str !== 'string') {
|
||||
throw new Error('Input must be a string');
|
||||
}
|
||||
var strLength = length(str);
|
||||
// Fix type
|
||||
if (typeof begin !== 'number') {
|
||||
begin = parseInt(begin, 10);
|
||||
}
|
||||
// Return zero-length string if got oversize number.
|
||||
if (begin >= strLength) {
|
||||
return '';
|
||||
}
|
||||
// Calculating postive version of negative value.
|
||||
if (begin < 0) {
|
||||
begin += strLength;
|
||||
}
|
||||
var end;
|
||||
if (typeof len === 'undefined') {
|
||||
end = strLength;
|
||||
}
|
||||
else {
|
||||
// Fix type
|
||||
if (typeof len !== 'number') {
|
||||
len = parseInt(len, 10);
|
||||
}
|
||||
end = len >= 0 ? len + begin : begin;
|
||||
}
|
||||
var match = str.match(char_regex_1.default());
|
||||
if (!match)
|
||||
return '';
|
||||
return match.slice(begin, end).join('');
|
||||
}
|
||||
exports.substr = substr;
|
||||
/**
|
||||
* Enforces a string to be a certain length by
|
||||
* adding or removing characters
|
||||
*
|
||||
* @export
|
||||
* @param {string} str
|
||||
* @param {number} [limit=16] Limit
|
||||
* @param {string} [padString='#'] The Pad String
|
||||
* @param {string} [padPosition='right'] The Pad Position
|
||||
* @returns {string}
|
||||
*/
|
||||
function limit(str, limit, padString, padPosition) {
|
||||
if (limit === void 0) { limit = 16; }
|
||||
if (padString === void 0) { padString = '#'; }
|
||||
if (padPosition === void 0) { padPosition = 'right'; }
|
||||
// Input should be a string, limit should be a number
|
||||
if (typeof str !== 'string' || typeof limit !== 'number') {
|
||||
throw new Error('Invalid arguments specified');
|
||||
}
|
||||
// Pad position should be either left or right
|
||||
if (['left', 'right'].indexOf(padPosition) === -1) {
|
||||
throw new Error('Pad position should be either left or right');
|
||||
}
|
||||
// Pad string can be anything, we convert it to string
|
||||
if (typeof padString !== 'string') {
|
||||
padString = String(padString);
|
||||
}
|
||||
// Calculate string length considering astral code points
|
||||
var strLength = length(str);
|
||||
if (strLength > limit) {
|
||||
return substring(str, 0, limit);
|
||||
}
|
||||
else if (strLength < limit) {
|
||||
var padRepeats = padString.repeat(limit - strLength);
|
||||
return padPosition === 'left' ? padRepeats + str : str + padRepeats;
|
||||
}
|
||||
return str;
|
||||
}
|
||||
exports.limit = limit;
|
||||
/**
|
||||
* Returns the index of the first occurrence of a given string
|
||||
*
|
||||
* @export
|
||||
* @param {string} str
|
||||
* @param {string} [searchStr] the string to search
|
||||
* @param {number} [pos] starting position
|
||||
* @returns {number}
|
||||
*/
|
||||
function indexOf(str, searchStr, pos) {
|
||||
if (pos === void 0) { pos = 0; }
|
||||
if (typeof str !== 'string') {
|
||||
throw new Error('Input must be a string');
|
||||
}
|
||||
if (str === '') {
|
||||
if (searchStr === '') {
|
||||
return 0;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
// fix type
|
||||
pos = Number(pos);
|
||||
pos = isNaN(pos) ? 0 : pos;
|
||||
searchStr = String(searchStr);
|
||||
var strArr = toArray(str);
|
||||
if (pos >= strArr.length) {
|
||||
if (searchStr === '') {
|
||||
return strArr.length;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
if (searchStr === '') {
|
||||
return pos;
|
||||
}
|
||||
var searchArr = toArray(searchStr);
|
||||
var finded = false;
|
||||
var index;
|
||||
for (index = pos; index < strArr.length; index += 1) {
|
||||
var searchIndex = 0;
|
||||
while (searchIndex < searchArr.length &&
|
||||
searchArr[searchIndex] === strArr[index + searchIndex]) {
|
||||
searchIndex += 1;
|
||||
}
|
||||
if (searchIndex === searchArr.length &&
|
||||
searchArr[searchIndex - 1] === strArr[index + searchIndex - 1]) {
|
||||
finded = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return finded ? index : -1;
|
||||
}
|
||||
exports.indexOf = indexOf;
|
||||
Reference in new issue
Block a user