UNPKG

@becomes/cms-cloud-client

Version:

SDK for accessing BCMS Cloud API

132 lines (131 loc) 3.87 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.StringUtility = void 0; class StringUtility { static verifyEmail(email) { if (!email) { return false; } const emailParts = email.split('@'); if (emailParts.length !== 2) { return false; } const domainParts = emailParts[1].split('.'); return domainParts.filter((e) => e).length > 1; } } exports.StringUtility = StringUtility; // export function useStringUtility(): StringUtility { // if (stringUtility) { // return stringUtility; // } // stringUtility = { // verifyEmail(email) { // if (!email) { // return false; // } // const emailParts = email.split('@'); // if (emailParts.length !== 2) { // return false; // } // const domainParts = emailParts[1].split('.'); // return domainParts.filter((e) => e).length > 1; // }, // padStart(text, length, padValue) { // return String(text).padStart(length || 2, padValue || '0'); // }, // toPretty(s) { // if (s.indexOf('_') !== -1) { // return s // .split('_') // .map((e) => { // return ( // e.substring(0, 1).toUpperCase() + // e.substring(1, e.length).toLowerCase() // ); // }) // .join(' '); // } else { // return s // .split('-') // .map((e) => { // return ( // e.substring(0, 1).toUpperCase() + // e.substring(1, e.length).toLowerCase() // ); // }) // .join(' '); // } // }, // toUri(s) { // return s // .toLowerCase() // .replace(/ /g, '-') // .replace(/_/g, '-') // .replace(/[^0-9a-z---]+/g, ''); // }, // toUriLowDash(s) { // return s // .toLowerCase() // .replace(/ /g, '_') // .replace(/-/g, '_') // .replace(/[^0-9a-z_-_]+/g, ''); // }, // toEnum(s) { // return s // .toUpperCase() // .replace(/ /g, '_') // .replace(/-/g, '_') // .replace(/[^0-9A-Z_-_]+/g, ''); // }, // toShort(s, length) { // if (s.length > length) { // const d = s.length - length; // const firstPart = s.substring(0, s.length / 2 - d / 2); // const lastPart = s.substring(s.length / 2 + d / 2); // return firstPart + ' ... ' + lastPart; // } // return s; // }, // textBetween(src, begin, end) { // const startIndex = src.indexOf(begin); // if (startIndex === -1) { // return ''; // } // const endIndex = src.indexOf(end, startIndex + begin.length); // if (endIndex === -1) { // return ''; // } // return src.substring(startIndex + begin.length, endIndex); // }, // allTextBetween(src, begin, end) { // const output: string[] = []; // const index = { // begin: src.indexOf(begin, 0), // end: 0, // }; // if (index.begin === -1) { // return []; // } // index.end = src.indexOf(end, index.begin); // if (index.end === -1) { // return []; // } // output.push(src.substring(index.begin + begin.length, index.end)); // // eslint-disable-next-line no-constant-condition // while (true) { // index.begin = src.indexOf(begin, index.end); // if (index.begin === -1) { // break; // } // index.end = src.indexOf(end, index.begin); // if (index.end === -1) { // break; // } // output.push(src.substring(index.begin + begin.length, index.end)); // } // return output; // }, // }; // return stringUtility; // }