@yookue/ts-lang-utils
Advanced tools
Comparing version 0.1.1 to 0.1.2
export { ArrayUtils } from './util/ArrayUtils'; | ||
export { BooleanUtils } from './util/BooleanUtils'; | ||
export { JsonUtils } from './util/JsonUtils'; | ||
export { ObjectUtils } from './util/ObjectUtils'; | ||
export { RandomUtils } from './util/RandomUtils'; | ||
export { StringUtils } from './util/StringUtils'; | ||
export { TimeUtils } from './util/TimeUtils'; | ||
export { ThreadUtils } from './util/ThreadUtils'; | ||
export { DateUtils } from './util/DateUtils'; |
@@ -24,6 +24,8 @@ var __defProp = Object.defineProperty; | ||
BooleanUtils: () => import_BooleanUtils.BooleanUtils, | ||
DateUtils: () => import_DateUtils.DateUtils, | ||
JsonUtils: () => import_JsonUtils.JsonUtils, | ||
ObjectUtils: () => import_ObjectUtils.ObjectUtils, | ||
RandomUtils: () => import_RandomUtils.RandomUtils, | ||
StringUtils: () => import_StringUtils.StringUtils, | ||
TimeUtils: () => import_TimeUtils.TimeUtils | ||
ThreadUtils: () => import_ThreadUtils.ThreadUtils | ||
}); | ||
@@ -33,6 +35,8 @@ module.exports = __toCommonJS(src_exports); | ||
var import_BooleanUtils = require("./util/BooleanUtils"); | ||
var import_JsonUtils = require("./util/JsonUtils"); | ||
var import_ObjectUtils = require("./util/ObjectUtils"); | ||
var import_RandomUtils = require("./util/RandomUtils"); | ||
var import_StringUtils = require("./util/StringUtils"); | ||
var import_TimeUtils = require("./util/TimeUtils"); | ||
var import_ThreadUtils = require("./util/ThreadUtils"); | ||
var import_DateUtils = require("./util/DateUtils"); | ||
// Annotate the CommonJS export names for ESM import in node: | ||
@@ -42,6 +46,8 @@ 0 && (module.exports = { | ||
BooleanUtils, | ||
DateUtils, | ||
JsonUtils, | ||
ObjectUtils, | ||
RandomUtils, | ||
StringUtils, | ||
TimeUtils | ||
ThreadUtils | ||
}); |
@@ -9,2 +9,9 @@ /** | ||
/** | ||
* Returns the length of the given array | ||
* | ||
* @param array the array to check | ||
* @return number the length of the given array | ||
*/ | ||
static getLength(array?: Array<any>): number; | ||
/** | ||
* Returns whether the given array is empty | ||
@@ -11,0 +18,0 @@ * |
@@ -28,2 +28,11 @@ var __defProp = Object.defineProperty; | ||
/** | ||
* Returns the length of the given array | ||
* | ||
* @param array the array to check | ||
* @return number the length of the given array | ||
*/ | ||
static getLength(array) { | ||
return array ? array.length : 0; | ||
} | ||
/** | ||
* Returns whether the given array is empty | ||
@@ -30,0 +39,0 @@ * |
@@ -9,2 +9,9 @@ /** | ||
/** | ||
* Returns the length of the given string | ||
* | ||
* @param text the source string to check | ||
* @return number the length of the given string | ||
*/ | ||
static getLength(text?: string): number; | ||
/** | ||
* Returns whether the given string is empty | ||
@@ -53,9 +60,2 @@ * | ||
/** | ||
* Returns whether all the characters in the given string is whitespace | ||
* | ||
* @param text the string to check | ||
* @returns true if all the characters in the given string is whitespace | ||
*/ | ||
static isWhitespace(text?: string): boolean; | ||
/** | ||
* Returns whether all the given texts are empty | ||
@@ -218,2 +218,31 @@ * | ||
/** | ||
* Returns the replaced string of the source string ("{}" placeholder) with the parameters | ||
* | ||
* @param text the source string to inspect | ||
* @param params the parameters to replaced with | ||
* @return string the replaced string of the source string | ||
* | ||
* @example | ||
* StringUtils.formatBraces("foo{}", "bar"); // "foobar" | ||
* StringUtils.formatBraces("foobar{}"); // "foobar{}" | ||
* StringUtils.formatBraces("hello {}, foo{}", "world", "bar"); // "hello world, foobar" | ||
*/ | ||
static formatBraces(text?: string, ...params: Array<any>): string | undefined; | ||
/** | ||
* Returns the replaced string of the source string (named placeholder) with the parameters | ||
* | ||
* @param text the source string to inspect | ||
* @param params the parameters to replaced with, in the form of key values | ||
* @return string the replaced string of the source string | ||
* | ||
* @example | ||
* StringUtils.formatPlaceholders("foo{bar}", {bar: "bar"}); // "foobar" | ||
* StringUtils.formatPlaceholders("foobar{none}"); // "foobar{none}" | ||
* StringUtils.formatPlaceholders("foobar{none}", {}); // "foobar{none}" | ||
* StringUtils.formatPlaceholders("hello {name}, foo{bar}", {name: "world", bar: "bar"}); // "hello world, foobar" | ||
*/ | ||
static formatPlaceholders(text?: string, params?: { | ||
[key: string]: any; | ||
}): string | undefined; | ||
/** | ||
* Returns whether the given text includes the comparison string | ||
@@ -220,0 +249,0 @@ * |
@@ -29,2 +29,11 @@ var __defProp = Object.defineProperty; | ||
/** | ||
* Returns the length of the given string | ||
* | ||
* @param text the source string to check | ||
* @return number the length of the given string | ||
*/ | ||
static getLength(text) { | ||
return text ? text.length : 0; | ||
} | ||
/** | ||
* Returns whether the given string is empty | ||
@@ -66,13 +75,3 @@ * | ||
static isBlank(text) { | ||
if (!text || text.length === 0) { | ||
return true; | ||
} | ||
const length = text.length; | ||
for (let i = 0; i < length; i++) { | ||
const character = text.charAt(i); | ||
if (character !== " " && character !== "\\r" && character !== "\\n") { | ||
return false; | ||
} | ||
} | ||
return true; | ||
return !text || text.length === 0 || /^\s*$/.test(text); | ||
} | ||
@@ -92,20 +91,2 @@ /** | ||
/** | ||
* Returns whether all the characters in the given string is whitespace | ||
* | ||
* @param text the string to check | ||
* @returns true if all the characters in the given string is whitespace | ||
*/ | ||
static isWhitespace(text) { | ||
if (!text || text.length === 0) { | ||
return false; | ||
} | ||
const length = text.length; | ||
for (let i = 0; i < length; i++) { | ||
if (text.charAt(i) !== " ") { | ||
return false; | ||
} | ||
} | ||
return true; | ||
} | ||
/** | ||
* Returns whether all the given texts are empty | ||
@@ -311,2 +292,49 @@ * | ||
/** | ||
* Returns the replaced string of the source string ("{}" placeholder) with the parameters | ||
* | ||
* @param text the source string to inspect | ||
* @param params the parameters to replaced with | ||
* @return string the replaced string of the source string | ||
* | ||
* @example | ||
* StringUtils.formatBraces("foo{}", "bar"); // "foobar" | ||
* StringUtils.formatBraces("foobar{}"); // "foobar{}" | ||
* StringUtils.formatBraces("hello {}, foo{}", "world", "bar"); // "hello world, foobar" | ||
*/ | ||
static formatBraces(text, ...params) { | ||
if (!text || text.length <= 2 || import_ArrayUtils.ArrayUtils.isEmpty(params)) { | ||
return text; | ||
} | ||
let result = text; | ||
for (const param of params) { | ||
result = result.replace("{}", param ? param.toString() : ""); | ||
} | ||
return result; | ||
} | ||
/** | ||
* Returns the replaced string of the source string (named placeholder) with the parameters | ||
* | ||
* @param text the source string to inspect | ||
* @param params the parameters to replaced with, in the form of key values | ||
* @return string the replaced string of the source string | ||
* | ||
* @example | ||
* StringUtils.formatPlaceholders("foo{bar}", {bar: "bar"}); // "foobar" | ||
* StringUtils.formatPlaceholders("foobar{none}"); // "foobar{none}" | ||
* StringUtils.formatPlaceholders("foobar{none}", {}); // "foobar{none}" | ||
* StringUtils.formatPlaceholders("hello {name}, foo{bar}", {name: "world", bar: "bar"}); // "hello world, foobar" | ||
*/ | ||
static formatPlaceholders(text, params) { | ||
if (!text || text.length <= 2 || !params) { | ||
return text; | ||
} | ||
let result = text; | ||
for (const param in params) { | ||
const regex = new RegExp(`\\{${param}\\}`, "gi"); | ||
const value = params[param]; | ||
result = result.replace(regex, value ? value.toString() : ""); | ||
} | ||
return result; | ||
} | ||
/** | ||
* Returns whether the given text includes the comparison string | ||
@@ -313,0 +341,0 @@ * |
export { ArrayUtils } from './util/ArrayUtils'; | ||
export { BooleanUtils } from './util/BooleanUtils'; | ||
export { JsonUtils } from './util/JsonUtils'; | ||
export { ObjectUtils } from './util/ObjectUtils'; | ||
export { RandomUtils } from './util/RandomUtils'; | ||
export { StringUtils } from './util/StringUtils'; | ||
export { TimeUtils } from './util/TimeUtils'; | ||
export { ThreadUtils } from './util/ThreadUtils'; | ||
export { DateUtils } from './util/DateUtils'; |
export { ArrayUtils } from "./util/ArrayUtils"; | ||
export { BooleanUtils } from "./util/BooleanUtils"; | ||
export { JsonUtils } from "./util/JsonUtils"; | ||
export { ObjectUtils } from "./util/ObjectUtils"; | ||
export { RandomUtils } from "./util/RandomUtils"; | ||
export { StringUtils } from "./util/StringUtils"; | ||
export { TimeUtils } from "./util/TimeUtils"; | ||
export { ThreadUtils } from "./util/ThreadUtils"; | ||
export { DateUtils } from "./util/DateUtils"; |
@@ -9,2 +9,9 @@ /** | ||
/** | ||
* Returns the length of the given array | ||
* | ||
* @param array the array to check | ||
* @return number the length of the given array | ||
*/ | ||
static getLength(array?: Array<any>): number; | ||
/** | ||
* Returns whether the given array is empty | ||
@@ -11,0 +18,0 @@ * |
@@ -9,2 +9,7 @@ import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck"; | ||
_createClass(ArrayUtils, null, [{ | ||
key: "getLength", | ||
value: function getLength(array) { | ||
return array ? array.length : 0; | ||
} | ||
}, { | ||
key: "isEmpty", | ||
@@ -11,0 +16,0 @@ value: function isEmpty(array) { |
@@ -9,2 +9,9 @@ /** | ||
/** | ||
* Returns the length of the given string | ||
* | ||
* @param text the source string to check | ||
* @return number the length of the given string | ||
*/ | ||
static getLength(text?: string): number; | ||
/** | ||
* Returns whether the given string is empty | ||
@@ -53,9 +60,2 @@ * | ||
/** | ||
* Returns whether all the characters in the given string is whitespace | ||
* | ||
* @param text the string to check | ||
* @returns true if all the characters in the given string is whitespace | ||
*/ | ||
static isWhitespace(text?: string): boolean; | ||
/** | ||
* Returns whether all the given texts are empty | ||
@@ -218,2 +218,31 @@ * | ||
/** | ||
* Returns the replaced string of the source string ("{}" placeholder) with the parameters | ||
* | ||
* @param text the source string to inspect | ||
* @param params the parameters to replaced with | ||
* @return string the replaced string of the source string | ||
* | ||
* @example | ||
* StringUtils.formatBraces("foo{}", "bar"); // "foobar" | ||
* StringUtils.formatBraces("foobar{}"); // "foobar{}" | ||
* StringUtils.formatBraces("hello {}, foo{}", "world", "bar"); // "hello world, foobar" | ||
*/ | ||
static formatBraces(text?: string, ...params: Array<any>): string | undefined; | ||
/** | ||
* Returns the replaced string of the source string (named placeholder) with the parameters | ||
* | ||
* @param text the source string to inspect | ||
* @param params the parameters to replaced with, in the form of key values | ||
* @return string the replaced string of the source string | ||
* | ||
* @example | ||
* StringUtils.formatPlaceholders("foo{bar}", {bar: "bar"}); // "foobar" | ||
* StringUtils.formatPlaceholders("foobar{none}"); // "foobar{none}" | ||
* StringUtils.formatPlaceholders("foobar{none}", {}); // "foobar{none}" | ||
* StringUtils.formatPlaceholders("hello {name}, foo{bar}", {name: "world", bar: "bar"}); // "hello world, foobar" | ||
*/ | ||
static formatPlaceholders(text?: string, params?: { | ||
[key: string]: any; | ||
}): string | undefined; | ||
/** | ||
* Returns whether the given text includes the comparison string | ||
@@ -220,0 +249,0 @@ * |
@@ -10,2 +10,7 @@ import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck"; | ||
_createClass(StringUtils, null, [{ | ||
key: "getLength", | ||
value: function getLength(text) { | ||
return text ? text.length : 0; | ||
} | ||
}, { | ||
key: "isEmpty", | ||
@@ -23,13 +28,3 @@ value: function isEmpty(text) { | ||
value: function isBlank(text) { | ||
if (!text || text.length === 0) { | ||
return true; | ||
} | ||
var length = text.length; | ||
for (var i = 0; i < length; i++) { | ||
var character = text.charAt(i); | ||
if (character !== ' ' && character !== '\\r' && character !== '\\n') { | ||
return false; | ||
} | ||
} | ||
return true; | ||
return !text || text.length === 0 || /^\s*$/.test(text); | ||
} | ||
@@ -42,16 +37,2 @@ }, { | ||
}, { | ||
key: "isWhitespace", | ||
value: function isWhitespace(text) { | ||
if (!text || text.length === 0) { | ||
return false; | ||
} | ||
var length = text.length; | ||
for (var i = 0; i < length; i++) { | ||
if (text.charAt(i) !== ' ') { | ||
return false; | ||
} | ||
} | ||
return true; | ||
} | ||
}, { | ||
key: "allEmpty", | ||
@@ -193,2 +174,32 @@ value: function allEmpty() { | ||
}, { | ||
key: "formatBraces", | ||
value: function formatBraces(text) { | ||
for (var _len9 = arguments.length, params = new Array(_len9 > 1 ? _len9 - 1 : 0), _key9 = 1; _key9 < _len9; _key9++) { | ||
params[_key9 - 1] = arguments[_key9]; | ||
} | ||
if (!text || text.length <= 2 || ArrayUtils.isEmpty(params)) { | ||
return text; | ||
} | ||
var result = text; | ||
for (var _i = 0, _params = params; _i < _params.length; _i++) { | ||
var param = _params[_i]; | ||
result = result.replace('{}', param ? param.toString() : ''); | ||
} | ||
return result; | ||
} | ||
}, { | ||
key: "formatPlaceholders", | ||
value: function formatPlaceholders(text, params) { | ||
if (!text || text.length <= 2 || !params) { | ||
return text; | ||
} | ||
var result = text; | ||
for (var param in params) { | ||
var regex = new RegExp("\\{".concat(param, "\\}"), 'gi'); | ||
var value = params[param]; | ||
result = result.replace(regex, value ? value.toString() : ''); | ||
} | ||
return result; | ||
} | ||
}, { | ||
key: "includes", | ||
@@ -195,0 +206,0 @@ value: function includes(text, comparison) { |
@@ -1,1 +0,1 @@ | ||
!function(t,n){"object"==typeof exports&&"object"==typeof module?module.exports=n():"function"==typeof define&&define.amd?define([],n):"object"==typeof exports?exports.TsLangUtils=n():t.TsLangUtils=n()}(self,(function(){return function(){var t={486:function(t){t.exports=function(t,n){if(!(t instanceof n))throw new TypeError("Cannot call a class as a function")},t.exports.__esModule=!0,t.exports.default=t.exports},702:function(t,n,e){var r=e(281);function o(t,n){for(var e=0;e<n.length;e++){var o=n[e];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(t,r(o.key),o)}}t.exports=function(t,n,e){return n&&o(t.prototype,n),e&&o(t,e),Object.defineProperty(t,"prototype",{writable:!1}),t},t.exports.__esModule=!0,t.exports.default=t.exports},224:function(t,n,e){var r=e(944).default;t.exports=function(t,n){if("object"!==r(t)||null===t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var o=e.call(t,n||"default");if("object"!==r(o))return o;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===n?String:Number)(t)},t.exports.__esModule=!0,t.exports.default=t.exports},281:function(t,n,e){var r=e(944).default,o=e(224);t.exports=function(t){var n=o(t,"string");return"symbol"===r(n)?n:String(n)},t.exports.__esModule=!0,t.exports.default=t.exports},944:function(t){function n(e){return t.exports=n="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},t.exports.__esModule=!0,t.exports.default=t.exports,n(e)}t.exports=n,t.exports.__esModule=!0,t.exports.default=t.exports}},n={};function e(r){var o=n[r];if(void 0!==o)return o.exports;var u=n[r]={exports:{}};return t[r](u,u.exports,e),u.exports}e.n=function(t){var n=t&&t.__esModule?function(){return t.default}:function(){return t};return e.d(n,{a:n}),n},e.d=function(t,n){for(var r in n)e.o(n,r)&&!e.o(t,r)&&Object.defineProperty(t,r,{enumerable:!0,get:n[r]})},e.o=function(t,n){return Object.prototype.hasOwnProperty.call(t,n)},e.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})};var r={};return function(){"use strict";e.r(r),e.d(r,{ArrayUtils:function(){return s},BooleanUtils:function(){return y},ObjectUtils:function(){return a},RandomUtils:function(){return c},StringUtils:function(){return f},TimeUtils:function(){return v}});var t=e(486),n=e.n(t),o=e(702),u=e.n(o),i=e(944),l=e.n(i),a=function(){function t(){n()(this,t)}return u()(t,null,[{key:"isNil",value:function(t){return null==t}},{key:"isNotNil",value:function(t){return!this.isNil(t)}},{key:"isNull",value:function(t){return null===t}},{key:"isNotNull",value:function(t){return!this.isNull(t)}},{key:"isUndefined",value:function(t){return void 0===t}},{key:"isNotUndefined",value:function(t){return!this.isUndefined(t)}},{key:"isEmpty",value:function(t){return!!this.isNil(t)||("string"==typeof t||Array.isArray(t)?0===t.length:t instanceof Map||t instanceof Set?0===t.size:"object"===l()(t)&&0===(null===(n=this.keys(t))||void 0===n?void 0:n.length));var n}},{key:"isNotEmpty",value:function(t){return!this.isEmpty(t)}},{key:"isPrototype",value:function(t){if("object"!==l()(t))return!1;var n=t.constructor;return t===("function"==typeof n?n.prototype:t.prototype)}},{key:"allNil",value:function(){for(var t=this,n=arguments.length,e=new Array(n),r=0;r<n;r++)e[r]=arguments[r];return this.isEmpty(e)||!e.some((function(n){return t.isNotNil(n)}))}},{key:"allNotNil",value:function(){for(var t=this,n=arguments.length,e=new Array(n),r=0;r<n;r++)e[r]=arguments[r];return this.isNotEmpty(e)&&!e.some((function(n){return t.isNil(n)}))}},{key:"anyNil",value:function(){for(var t=this,n=arguments.length,e=new Array(n),r=0;r<n;r++)e[r]=arguments[r];return this.isEmpty(e)||e.some((function(n){return t.isNil(n)}))}},{key:"anyNotNil",value:function(){for(var t=this,n=arguments.length,e=new Array(n),r=0;r<n;r++)e[r]=arguments[r];return this.isNotEmpty(e)&&e.some((function(n){return t.isNotNil(n)}))}},{key:"allEmpty",value:function(){for(var t=this,n=arguments.length,e=new Array(n),r=0;r<n;r++)e[r]=arguments[r];return this.isEmpty(e)||!e.some((function(n){return t.isNotEmpty(n)}))}},{key:"allNotEmpty",value:function(){for(var t=this,n=arguments.length,e=new Array(n),r=0;r<n;r++)e[r]=arguments[r];return this.isNotEmpty(e)&&!e.some((function(n){return t.isEmpty(n)}))}},{key:"anyEmpty",value:function(){for(var t=this,n=arguments.length,e=new Array(n),r=0;r<n;r++)e[r]=arguments[r];return this.isEmpty(e)||e.some((function(n){return t.isEmpty(n)}))}},{key:"anyNotEmpty",value:function(){for(var t=this,n=arguments.length,e=new Array(n),r=0;r<n;r++)e[r]=arguments[r];return this.isNotEmpty(e)&&e.some((function(n){return t.isNotEmpty(n)}))}},{key:"firstNonNil",value:function(){for(var t=arguments.length,n=new Array(t),e=0;e<t;e++)n[e]=arguments[e];if(!n||0===n.length)return null;for(var r=0,o=n;r<o.length;r++){var u=o[r];if(this.isNotNil(u))return u}return null}},{key:"hasProperty",value:function(t,n){return this.allNotNil(t,n)&&"object"===l()(t)&&(null==n?void 0:n.length)>0&&Object.prototype.hasOwnProperty.call(t,n)}},{key:"keys",value:function(t){if(this.isNil(t))return[];if(!this.isPrototype(t))return Object.keys(t);var n=[];for(var e in Object(t))"constructor"!==e&&this.hasProperty(t,e)&&n.push(e);return n}},{key:"toString",value:function(t,n){return t?t.toString():n}}]),t}(),s=function(){function t(){n()(this,t)}return u()(t,null,[{key:"isEmpty",value:function(t){return!t||0===t.length}},{key:"isNotEmpty",value:function(t){return!this.isEmpty(t)}},{key:"includes",value:function(t,n){return a.allNotNil(t,n)&&t.includes(n)}}]),t}(),f=function(){function t(){n()(this,t)}return u()(t,null,[{key:"isEmpty",value:function(t){return!t||0===t.length}},{key:"isNotEmpty",value:function(t){return!this.isEmpty(t)}},{key:"isBlank",value:function(t){if(!t||0===t.length)return!0;for(var n=t.length,e=0;e<n;e++){var r=t.charAt(e);if(" "!==r&&"\\r"!==r&&"\\n"!==r)return!1}return!0}},{key:"isNotBlank",value:function(t){return!this.isBlank(t)}},{key:"isWhitespace",value:function(t){if(!t||0===t.length)return!1;for(var n=t.length,e=0;e<n;e++)if(" "!==t.charAt(e))return!1;return!0}},{key:"allEmpty",value:function(){for(var t=this,n=arguments.length,e=new Array(n),r=0;r<n;r++)e[r]=arguments[r];return!e||0===e.length||!e.some((function(n){return t.isNotEmpty(n)}))}},{key:"allNotEmpty",value:function(){for(var t=this,n=arguments.length,e=new Array(n),r=0;r<n;r++)e[r]=arguments[r];return e&&e.length>0&&!e.some((function(n){return t.isEmpty(n)}))}},{key:"anyEmpty",value:function(){for(var t=this,n=arguments.length,e=new Array(n),r=0;r<n;r++)e[r]=arguments[r];return!e||0===e.length||e.some((function(n){return t.isEmpty(n)}))}},{key:"anyNotEmpty",value:function(){for(var t=this,n=arguments.length,e=new Array(n),r=0;r<n;r++)e[r]=arguments[r];return e&&e.length>0&&e.some((function(n){return t.isNotEmpty(n)}))}},{key:"allBlank",value:function(){for(var t=this,n=arguments.length,e=new Array(n),r=0;r<n;r++)e[r]=arguments[r];return!e||0===e.length||!e.some((function(n){return t.isNotBlank(n)}))}},{key:"allNotBlank",value:function(){for(var t=this,n=arguments.length,e=new Array(n),r=0;r<n;r++)e[r]=arguments[r];return e&&e.length>0&&!e.some((function(n){return t.isBlank(n)}))}},{key:"anyBlank",value:function(){for(var t=this,n=arguments.length,e=new Array(n),r=0;r<n;r++)e[r]=arguments[r];return!e||0===e.length||e.some((function(n){return t.isBlank(n)}))}},{key:"anyNotBlank",value:function(){for(var t=this,n=arguments.length,e=new Array(n),r=0;r<n;r++)e[r]=arguments[r];return e&&e.length>0&&e.some((function(n){return t.isNotBlank(n)}))}},{key:"defaultIfEmpty",value:function(t,n){return this.isEmpty(t)?n:t}},{key:"defaultIfBlank",value:function(t,n){return this.isBlank(t)?n:t}},{key:"equals",value:function(t,n){return!(t!==n&&!a.allNil(t,n))||!a.anyNil(t,n)&&(null==t?void 0:t.length)===(null==n?void 0:n.length)&&t===n}},{key:"equalsIgnoreCase",value:function(t,n){return!(t!==n&&!a.allNil(t,n))||!a.anyNil(t,n)&&(null==t?void 0:t.length)===(null==n?void 0:n.length)&&(null==t?void 0:t.toUpperCase())===(null==n?void 0:n.toUpperCase())}},{key:"equalsAny",value:function(t,n){return s.includes(n,t)}},{key:"equalsAnyIgnoreCase",value:function(t,n){var e=this;return!a.isNil(t)&&!s.isEmpty(n)&&n.some((function(n){return e.equalsIgnoreCase(t,n)}))}},{key:"includes",value:function(t,n){return t===n||a.allNotNil(t,n)&&t.includes(n)}},{key:"includesIgnoreCase",value:function(t,n){var e;return t===n||a.allNotNil(t,n)&&(null==t||null===(e=t.toUpperCase())||void 0===e?void 0:e.includes(null==n?void 0:n.toUpperCase()))}},{key:"includesAny",value:function(t,n){var e=this;return a.allNotNil(t,n)&&(null==n?void 0:n.some((function(n){return e.includes(t,n)})))}},{key:"includesAnyIgnoreCase",value:function(t,n){var e=this;return a.allNotNil(t,n)&&(null==n?void 0:n.some((function(n){return e.includesIgnoreCase(t,n)})))}},{key:"trim",value:function(t,n){if(!t)return t;var e=t.trim();return n&&this.isEmpty(e)?null:e}}]),t}(),y=function(){function t(){n()(this,t)}return u()(t,null,[{key:"fromString",value:function(t){return!!f.equalsAnyIgnoreCase(t,["true","yes","on","y","t","1"])||!f.equalsAnyIgnoreCase(t,["false","no","off","n","f","0"])&&void 0}},{key:"toString",value:function(t,n,e,r){return a.isNil(t)?r:t?n:e}},{key:"toStringTrueFalse",value:function(t){return this.toString(t,"true","false",void 0)}},{key:"toStringOnOff",value:function(t){return this.toString(t,"on","off",void 0)}},{key:"toStringYesNo",value:function(t){return this.toString(t,"yes","no",void 0)}},{key:"toStringYN",value:function(t){return this.toString(t,"Y","N",void 0)}},{key:"toStringTF",value:function(t){return this.toString(t,"T","F",void 0)}},{key:"toString10",value:function(t){return this.toString(t,"1","0",void 0)}}]),t}(),c=function(){function t(){n()(this,t)}return u()(t,null,[{key:"randomBoolean",value:function(){return Math.random()>=.5}},{key:"randomElement",value:function(t){return s.isNotEmpty(t)?t.at(this.randomInteger(0,t.length)):void 0}},{key:"randomInteger",value:function(t,n){return Math.floor(this.randomNumber(t,n))}},{key:"randomNumber",value:function(t,n){var e=t||0,r=n||Number.MAX_SAFE_INTEGER-1;if(e>r)throw SyntaxError("The min value must not be greater than max value");return e===r?e:e+(r-e)*Math.random()}}]),t}(),v=function(){function t(){n()(this,t)}return u()(t,null,[{key:"sleep",value:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:1e3;return new Promise((function(n){setTimeout(n,t)}))}}]),t}()}(),r}()})); | ||
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.TsLangUtils=e():t.TsLangUtils=e()}(self,(function(){return function(){var t={486:function(t){t.exports=function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")},t.exports.__esModule=!0,t.exports.default=t.exports},702:function(t,e,n){var r=n(281);function o(t,e){for(var n=0;n<e.length;n++){var o=e[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(t,r(o.key),o)}}t.exports=function(t,e,n){return e&&o(t.prototype,e),n&&o(t,n),Object.defineProperty(t,"prototype",{writable:!1}),t},t.exports.__esModule=!0,t.exports.default=t.exports},224:function(t,e,n){var r=n(944).default;t.exports=function(t,e){if("object"!==r(t)||null===t)return t;var n=t[Symbol.toPrimitive];if(void 0!==n){var o=n.call(t,e||"default");if("object"!==r(o))return o;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===e?String:Number)(t)},t.exports.__esModule=!0,t.exports.default=t.exports},281:function(t,e,n){var r=n(944).default,o=n(224);t.exports=function(t){var e=o(t,"string");return"symbol"===r(e)?e:String(e)},t.exports.__esModule=!0,t.exports.default=t.exports},944:function(t){function e(n){return t.exports=e="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},t.exports.__esModule=!0,t.exports.default=t.exports,e(n)}t.exports=e,t.exports.__esModule=!0,t.exports.default=t.exports}},e={};function n(r){var o=e[r];if(void 0!==o)return o.exports;var i=e[r]={exports:{}};return t[r](i,i.exports,n),i.exports}n.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return n.d(e,{a:e}),e},n.d=function(t,e){for(var r in e)n.o(e,r)&&!n.o(t,r)&&Object.defineProperty(t,r,{enumerable:!0,get:e[r]})},n.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},n.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})};var r={};return function(){"use strict";n.r(r),n.d(r,{ArrayUtils:function(){return s},BooleanUtils:function(){return c},DateUtils:function(){return p},JsonUtils:function(){return y},ObjectUtils:function(){return a},RandomUtils:function(){return v},StringUtils:function(){return f},ThreadUtils:function(){return h}});var t=n(486),e=n.n(t),o=n(702),i=n.n(o),u=n(944),l=n.n(u),a=function(){function t(){e()(this,t)}return i()(t,null,[{key:"isNil",value:function(t){return null==t}},{key:"isNotNil",value:function(t){return!this.isNil(t)}},{key:"isNull",value:function(t){return null===t}},{key:"isNotNull",value:function(t){return!this.isNull(t)}},{key:"isUndefined",value:function(t){return void 0===t}},{key:"isNotUndefined",value:function(t){return!this.isUndefined(t)}},{key:"isEmpty",value:function(t){return!!this.isNil(t)||("string"==typeof t||Array.isArray(t)?0===t.length:t instanceof Map||t instanceof Set?0===t.size:"object"===l()(t)&&0===(null===(e=this.keys(t))||void 0===e?void 0:e.length));var e}},{key:"isNotEmpty",value:function(t){return!this.isEmpty(t)}},{key:"isPrototype",value:function(t){if("object"!==l()(t))return!1;var e=t.constructor;return t===("function"==typeof e?e.prototype:t.prototype)}},{key:"allNil",value:function(){for(var t=this,e=arguments.length,n=new Array(e),r=0;r<e;r++)n[r]=arguments[r];return this.isEmpty(n)||!n.some((function(e){return t.isNotNil(e)}))}},{key:"allNotNil",value:function(){for(var t=this,e=arguments.length,n=new Array(e),r=0;r<e;r++)n[r]=arguments[r];return this.isNotEmpty(n)&&!n.some((function(e){return t.isNil(e)}))}},{key:"anyNil",value:function(){for(var t=this,e=arguments.length,n=new Array(e),r=0;r<e;r++)n[r]=arguments[r];return this.isEmpty(n)||n.some((function(e){return t.isNil(e)}))}},{key:"anyNotNil",value:function(){for(var t=this,e=arguments.length,n=new Array(e),r=0;r<e;r++)n[r]=arguments[r];return this.isNotEmpty(n)&&n.some((function(e){return t.isNotNil(e)}))}},{key:"allEmpty",value:function(){for(var t=this,e=arguments.length,n=new Array(e),r=0;r<e;r++)n[r]=arguments[r];return this.isEmpty(n)||!n.some((function(e){return t.isNotEmpty(e)}))}},{key:"allNotEmpty",value:function(){for(var t=this,e=arguments.length,n=new Array(e),r=0;r<e;r++)n[r]=arguments[r];return this.isNotEmpty(n)&&!n.some((function(e){return t.isEmpty(e)}))}},{key:"anyEmpty",value:function(){for(var t=this,e=arguments.length,n=new Array(e),r=0;r<e;r++)n[r]=arguments[r];return this.isEmpty(n)||n.some((function(e){return t.isEmpty(e)}))}},{key:"anyNotEmpty",value:function(){for(var t=this,e=arguments.length,n=new Array(e),r=0;r<e;r++)n[r]=arguments[r];return this.isNotEmpty(n)&&n.some((function(e){return t.isNotEmpty(e)}))}},{key:"firstNonNil",value:function(){for(var t=arguments.length,e=new Array(t),n=0;n<t;n++)e[n]=arguments[n];if(!e||0===e.length)return null;for(var r=0,o=e;r<o.length;r++){var i=o[r];if(this.isNotNil(i))return i}return null}},{key:"hasProperty",value:function(t,e){return this.allNotNil(t,e)&&"object"===l()(t)&&(null==e?void 0:e.length)>0&&Object.prototype.hasOwnProperty.call(t,e)}},{key:"keys",value:function(t){if(this.isNil(t))return[];if(!this.isPrototype(t))return Object.keys(t);var e=[];for(var n in Object(t))"constructor"!==n&&this.hasProperty(t,n)&&e.push(n);return e}},{key:"toString",value:function(t,e){return t?t.toString():e}}]),t}(),s=function(){function t(){e()(this,t)}return i()(t,null,[{key:"getLength",value:function(t){return t?t.length:0}},{key:"isEmpty",value:function(t){return!t||0===t.length}},{key:"isNotEmpty",value:function(t){return!this.isEmpty(t)}},{key:"includes",value:function(t,e){return a.allNotNil(t,e)&&t.includes(e)}}]),t}(),f=function(){function t(){e()(this,t)}return i()(t,null,[{key:"getLength",value:function(t){return t?t.length:0}},{key:"isEmpty",value:function(t){return!t||0===t.length}},{key:"isNotEmpty",value:function(t){return!this.isEmpty(t)}},{key:"isBlank",value:function(t){return!t||0===t.length||/^\s*$/.test(t)}},{key:"isNotBlank",value:function(t){return!this.isBlank(t)}},{key:"allEmpty",value:function(){for(var t=this,e=arguments.length,n=new Array(e),r=0;r<e;r++)n[r]=arguments[r];return!n||0===n.length||!n.some((function(e){return t.isNotEmpty(e)}))}},{key:"allNotEmpty",value:function(){for(var t=this,e=arguments.length,n=new Array(e),r=0;r<e;r++)n[r]=arguments[r];return n&&n.length>0&&!n.some((function(e){return t.isEmpty(e)}))}},{key:"anyEmpty",value:function(){for(var t=this,e=arguments.length,n=new Array(e),r=0;r<e;r++)n[r]=arguments[r];return!n||0===n.length||n.some((function(e){return t.isEmpty(e)}))}},{key:"anyNotEmpty",value:function(){for(var t=this,e=arguments.length,n=new Array(e),r=0;r<e;r++)n[r]=arguments[r];return n&&n.length>0&&n.some((function(e){return t.isNotEmpty(e)}))}},{key:"allBlank",value:function(){for(var t=this,e=arguments.length,n=new Array(e),r=0;r<e;r++)n[r]=arguments[r];return!n||0===n.length||!n.some((function(e){return t.isNotBlank(e)}))}},{key:"allNotBlank",value:function(){for(var t=this,e=arguments.length,n=new Array(e),r=0;r<e;r++)n[r]=arguments[r];return n&&n.length>0&&!n.some((function(e){return t.isBlank(e)}))}},{key:"anyBlank",value:function(){for(var t=this,e=arguments.length,n=new Array(e),r=0;r<e;r++)n[r]=arguments[r];return!n||0===n.length||n.some((function(e){return t.isBlank(e)}))}},{key:"anyNotBlank",value:function(){for(var t=this,e=arguments.length,n=new Array(e),r=0;r<e;r++)n[r]=arguments[r];return n&&n.length>0&&n.some((function(e){return t.isNotBlank(e)}))}},{key:"defaultIfEmpty",value:function(t,e){return this.isEmpty(t)?e:t}},{key:"defaultIfBlank",value:function(t,e){return this.isBlank(t)?e:t}},{key:"equals",value:function(t,e){return!(t!==e&&!a.allNil(t,e))||!a.anyNil(t,e)&&(null==t?void 0:t.length)===(null==e?void 0:e.length)&&t===e}},{key:"equalsIgnoreCase",value:function(t,e){return!(t!==e&&!a.allNil(t,e))||!a.anyNil(t,e)&&(null==t?void 0:t.length)===(null==e?void 0:e.length)&&(null==t?void 0:t.toUpperCase())===(null==e?void 0:e.toUpperCase())}},{key:"equalsAny",value:function(t,e){return s.includes(e,t)}},{key:"equalsAnyIgnoreCase",value:function(t,e){var n=this;return!a.isNil(t)&&!s.isEmpty(e)&&e.some((function(e){return n.equalsIgnoreCase(t,e)}))}},{key:"formatBraces",value:function(t){for(var e=arguments.length,n=new Array(e>1?e-1:0),r=1;r<e;r++)n[r-1]=arguments[r];if(!t||t.length<=2||s.isEmpty(n))return t;for(var o=t,i=0,u=n;i<u.length;i++){var l=u[i];o=o.replace("{}",l?l.toString():"")}return o}},{key:"formatPlaceholders",value:function(t,e){if(!t||t.length<=2||!e)return t;var n=t;for(var r in e){var o=new RegExp("\\{".concat(r,"\\}"),"gi"),i=e[r];n=n.replace(o,i?i.toString():"")}return n}},{key:"includes",value:function(t,e){return t===e||a.allNotNil(t,e)&&t.includes(e)}},{key:"includesIgnoreCase",value:function(t,e){var n;return t===e||a.allNotNil(t,e)&&(null==t||null===(n=t.toUpperCase())||void 0===n?void 0:n.includes(null==e?void 0:e.toUpperCase()))}},{key:"includesAny",value:function(t,e){var n=this;return a.allNotNil(t,e)&&(null==e?void 0:e.some((function(e){return n.includes(t,e)})))}},{key:"includesAnyIgnoreCase",value:function(t,e){var n=this;return a.allNotNil(t,e)&&(null==e?void 0:e.some((function(e){return n.includesIgnoreCase(t,e)})))}},{key:"trim",value:function(t,e){if(!t)return t;var n=t.trim();return e&&this.isEmpty(n)?null:n}}]),t}(),c=function(){function t(){e()(this,t)}return i()(t,null,[{key:"fromString",value:function(t){return!!f.equalsAnyIgnoreCase(t,["true","yes","on","y","t","1"])||!f.equalsAnyIgnoreCase(t,["false","no","off","n","f","0"])&&void 0}},{key:"toString",value:function(t,e,n,r){return a.isNil(t)?r:t?e:n}},{key:"toStringTrueFalse",value:function(t){return this.toString(t,"true","false",void 0)}},{key:"toStringOnOff",value:function(t){return this.toString(t,"on","off",void 0)}},{key:"toStringYesNo",value:function(t){return this.toString(t,"yes","no",void 0)}},{key:"toStringYN",value:function(t){return this.toString(t,"Y","N",void 0)}},{key:"toStringTF",value:function(t){return this.toString(t,"T","F",void 0)}},{key:"toString10",value:function(t){return this.toString(t,"1","0",void 0)}}]),t}(),y=function(){function t(){e()(this,t)}return i()(t,null,[{key:"isJsonObject",value:function(t){return"object"===l()(t)&&"[object object]"===Object.prototype.toString.call(t).toLowerCase()&&!t.length}},{key:"isJsonString",value:function(t){if(f.isBlank(t))return!1;try{if("object"===l()(JSON.parse(t)))return!0}catch(t){}return!1}},{key:"toJsonString",value:function(t){if("string"==typeof t&&t.length>0)try{var e=JSON.parse(t);if("object"===l()(e))return JSON.stringify(e)}catch(t){}if("object"===l()(t)&&this.isJsonObject(t))return JSON.stringify(t)}}]),t}(),v=function(){function t(){e()(this,t)}return i()(t,null,[{key:"randomBoolean",value:function(){return Math.random()>=.5}},{key:"randomElement",value:function(t){return s.isNotEmpty(t)?t.at(this.randomInteger(0,t.length)):void 0}},{key:"randomInteger",value:function(t,e){return Math.floor(this.randomNumber(t,e))}},{key:"randomNumber",value:function(t,e){var n=t||0,r=e||Number.MAX_SAFE_INTEGER-1;if(n>r)throw SyntaxError("The min value must not be greater than max value");return n===r?n:n+(r-n)*Math.random()}}]),t}(),h=function(){function t(){e()(this,t)}return i()(t,null,[{key:"sleep",value:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:1e3;return new Promise((function(e){setTimeout(e,t)}))}}]),t}(),p=function(){function t(){e()(this,t)}return i()(t,null,[{key:"formatDateTime",value:function(t,e){if(!f.isBlank(e)){var n={"y+":t.getFullYear(),"M+":t.getMonth()+1,"d+":t.getDate(),"h+":t.getHours()%12==0?12:t.getHours()%12,"H+":t.getHours(),"m+":t.getMinutes(),"s+":t.getSeconds(),"q+":Math.floor((t.getMonth()+3)/3),S:t.getMilliseconds()},r=e;for(var o in n){var i=new RegExp("(".concat(o,")")).exec(r);i&&(r=/(y+)/.test(o)?r.replace(i[1],n[o].toString().substring(4-i[1].length)):r.replace(i[1],1===i[1].length?n[o].toString():n[o].toString().padStart(i[1].length,"0")))}return r}}},{key:"getCurrentDate",value:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"yyyy-MM-dd";return this.formatDateTime(new Date,t)}},{key:"getCurrentDateTime",value:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"yyyy-MM-dd hh:mm:ss";return this.formatDateTime(new Date,t)}},{key:"getCurrentTime",value:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"hh:mm:ss";return this.formatDateTime(new Date,t)}},{key:"getTimezone",value:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:new Date,e=t.getTimezoneOffset(),n=Math.abs(e),r=Math.floor(n/60),o=n%60,i=o>0?":"+("0"+o).slice(-2):"";return(e<0?"+":"-")+r+i}},{key:"isLeapYear",value:function(t){return!((t%4||!(t%100))&&t%400)}}]),t}()}(),r}()})); |
{ | ||
"name": "@yookue/ts-lang-utils", | ||
"version": "0.1.1", | ||
"version": "0.1.2", | ||
"title": "TsLangUtils", | ||
@@ -5,0 +5,0 @@ "description": "Common Lang Utilities for TypeScript", |
@@ -13,6 +13,8 @@ # @yookue/ts-lang-utils | ||
2️⃣ Utilities for boolean | ||
3️⃣ Utilities for object | ||
4️⃣ Utilities for random | ||
5️⃣ Utilities for string | ||
6️⃣ Utilities for time | ||
3️⃣️ Utilities for date time | ||
4️⃣ Utilities for json | ||
5️⃣ Utilities for object | ||
6️⃣ Utilities for random | ||
7️⃣ Utilities for string | ||
8️⃣ Utilities for thread | ||
@@ -30,3 +32,3 @@ ## Quickstart | ||
```jsx | pure | ||
import {ArrayUtils, BooleanUtils, ObjectUtils, RandomUtils, StringUtils, TimeUtils} from '@yookue/ts-lang-utils'; | ||
import {ArrayUtils, BooleanUtils, DateUtils, JsonUtils, ObjectUtils, RandomUtils, StringUtils, ThreadUtils} from '@yookue/ts-lang-utils'; | ||
``` | ||
@@ -33,0 +35,0 @@ |
145076
40
3748
47