Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@yookue/ts-lang-utils

Package Overview
Dependencies
Maintainers
1
Versions
64
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@yookue/ts-lang-utils - npm Package Compare versions

Comparing version 0.1.7 to 0.1.8

16

dist/cjs/util/ArrayUtils.d.ts

@@ -16,2 +16,9 @@ /**

/**
* Returns the element types of the given array
*
* @param array the array to check
* @return the element types of the given array
*/
static getTypeof(array?: Array<any>): string[] | undefined;
/**
* Returns whether the given array is empty

@@ -37,2 +44,11 @@ *

/**
* Returns whether each element in the given array is the expected type
*
* @param array the array to check
* @param type the expected element type
* @param relaxed treat null as string or object
* @return true if each element in the given array is the expected type
*/
static isTypeof(array?: Array<any>, type?: string, relaxed?: boolean): boolean;
/**
* Returns whether the given array includes the given element

@@ -39,0 +55,0 @@ *

@@ -26,2 +26,3 @@ var __defProp = Object.defineProperty;

var import_ObjectUtils = require("./ObjectUtils");
var import_StringUtils = require("./StringUtils");
var ArrayUtils = class {

@@ -38,2 +39,22 @@ /**

/**
* Returns the element types of the given array
*
* @param array the array to check
* @return the element types of the given array
*/
static getTypeof(array) {
if (this.isEmpty(array)) {
return void 0;
}
return array == null ? void 0 : array.map((item) => {
if (Array.isArray(item)) {
return "array";
}
if (typeof item === "object") {
return item === null ? "null" : "object";
}
return typeof item;
});
}
/**
* Returns whether the given array is empty

@@ -63,2 +84,18 @@ *

/**
* Returns whether each element in the given array is the expected type
*
* @param array the array to check
* @param type the expected element type
* @param relaxed treat null as string or object
* @return true if each element in the given array is the expected type
*/
static isTypeof(array, type, relaxed = false) {
if (this.isEmpty(array) || import_StringUtils.StringUtils.isBlank(type)) {
return false;
}
return array == null ? void 0 : array.every((item) => {
return typeof item === type || relaxed && item === null && import_StringUtils.StringUtils.equalsAny(type, ["string", "object"]);
});
}
/**
* Returns whether the given array includes the given element

@@ -65,0 +102,0 @@ *

2

dist/cjs/util/StringUtils.js

@@ -74,3 +74,3 @@ var __defProp = Object.defineProperty;

static isBlank(text) {
return !text || text.length === 0 || /^\s*$/.test(text);
return !text || (text == null ? void 0 : text.length) === 0 || /^\s*$/.test(text);
}

@@ -77,0 +77,0 @@ /**

@@ -16,2 +16,9 @@ /**

/**
* Returns the element types of the given array
*
* @param array the array to check
* @return the element types of the given array
*/
static getTypeof(array?: Array<any>): string[] | undefined;
/**
* Returns whether the given array is empty

@@ -37,2 +44,11 @@ *

/**
* Returns whether each element in the given array is the expected type
*
* @param array the array to check
* @param type the expected element type
* @param relaxed treat null as string or object
* @return true if each element in the given array is the expected type
*/
static isTypeof(array?: Array<any>, type?: string, relaxed?: boolean): boolean;
/**
* Returns whether the given array includes the given element

@@ -39,0 +55,0 @@ *

@@ -0,4 +1,6 @@

import _typeof from "@babel/runtime/helpers/esm/typeof";
import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
import _createClass from "@babel/runtime/helpers/esm/createClass";
import { ObjectUtils } from "./ObjectUtils";
import { StringUtils } from "./StringUtils";
export var ArrayUtils = /*#__PURE__*/function () {

@@ -14,2 +16,18 @@ function ArrayUtils() {

}, {
key: "getTypeof",
value: function getTypeof(array) {
if (this.isEmpty(array)) {
return undefined;
}
return array === null || array === void 0 ? void 0 : array.map(function (item) {
if (Array.isArray(item)) {
return 'array';
}
if (_typeof(item) === 'object') {
return item === null ? 'null' : 'object';
}
return _typeof(item);
});
}
}, {
key: "isEmpty",

@@ -25,2 +43,13 @@ value: function isEmpty(array) {

}, {
key: "isTypeof",
value: function isTypeof(array, type) {
var relaxed = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
if (this.isEmpty(array) || StringUtils.isBlank(type)) {
return false;
}
return array === null || array === void 0 ? void 0 : array.every(function (item) {
return _typeof(item) === type || relaxed && item === null && StringUtils.equalsAny(type, ['string', 'object']);
});
}
}, {
key: "includes",

@@ -27,0 +56,0 @@ value: function includes(array, element) {

@@ -27,3 +27,3 @@ import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";

value: function isBlank(text) {
return !text || text.length === 0 || /^\s*$/.test(text);
return !text || (text === null || text === void 0 ? void 0 : text.length) === 0 || /^\s*$/.test(text);
}

@@ -30,0 +30,0 @@ }, {

@@ -1,1 +0,1 @@

!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 u(t,e){for(var n=0;n<e.length;n++){var u=e[n];u.enumerable=u.enumerable||!1,u.configurable=!0,"value"in u&&(u.writable=!0),Object.defineProperty(t,r(u.key),u)}}t.exports=function(t,e,n){return e&&u(t.prototype,e),n&&u(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 u=n.call(t,e||"default");if("object"!==r(u))return u;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,u=n(224);t.exports=function(t){var e=u(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 u=e[r];if(void 0!==u)return u.exports;var o=e[r]={exports:{}};return t[r](o,o.exports,n),o.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 y},DateUtils:function(){return g},JsonUtils:function(){return c},ObjectUtils:function(){return l},RandomUtils:function(){return v},StringUtils:function(){return f},ThreadUtils:function(){return h}});var t=n(486),e=n.n(t),u=n(702),o=n.n(u),i=n(944),a=n.n(i),l=function(){function t(){e()(this,t)}return o()(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"===a()(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:"isPlainObject",value:function(t){return"object"===a()(t)&&"[object Object]"===Object.prototype.toString.call(t)}},{key:"isPromiseObject",value:function(t){return"object"===a()(t)&&"[object Promise]"===Object.prototype.toString.call(t)}},{key:"isPrototype",value:function(t){if("object"!==a()(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,u=e;r<u.length;r++){var o=u[r];if(this.isNotNil(o))return o}return null}},{key:"getProperty",value:function(t,e){if(!this.anyNil(t,e)&&"object"===a()(t)&&0!==(null==e?void 0:e.length)){var n=e.replace(/\[/g,".").replace(/]/g,"").split(".");if(n&&0!==(null==n?void 0:n.length))return 1===(null==n?void 0:n.length)?t[n[0]]:n.reduce((function(t,e){return(t||{})[e]}),t)}}},{key:"hasProperty",value:function(t,e){return this.allNotNil(t,e)&&"object"===a()(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 o()(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 l.allNotNil(t,e)&&t.includes(e)}}]),t}(),f=function(){function t(){e()(this,t)}return o()(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&&!l.allNil(t,e))||!l.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&&!l.allNil(t,e))||!l.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!l.isNil(t)&&!s.isEmpty(e)&&e.some((function(e){return n.equalsIgnoreCase(t,e)}))}},{key:"formatBrace",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 u=t,o=0,i=n;o<i.length;o++){var a=i[o];u=u.replace("{}",l.toString(a,""))}return u}},{key:"formatPlaceholder",value:function(t,e){if(!t||t.length<=2||!e)return t;var n=t;for(var r in e){var u=new RegExp("\\{".concat(r,"\\}"),"gi"),o=e[r];n=n.replace(u,o?o.toString():"")}return n}},{key:"includes",value:function(t,e){return t===e||l.allNotNil(t,e)&&t.includes(e)}},{key:"includesIgnoreCase",value:function(t,e){var n;return t===e||l.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 l.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 l.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}(),y=function(){function t(){e()(this,t)}return o()(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 l.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}(),c=function(){function t(){e()(this,t)}return o()(t,null,[{key:"isJsonString",value:function(t){if(f.isBlank(t))return!1;try{if("object"===a()(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"===a()(e))return JSON.stringify(e)}catch(t){}if(l.isPlainObject(t))return JSON.stringify(t)}}]),t}(),v=function(){function t(){e()(this,t)}return o()(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:"randomElements",value:function(t,e){if(s.isEmpty(t)||e<=0)return[];if(s.getLength(t)<=e)return t;for(var n=new Set;n.size<e;)n.add(this.randomInteger(0,t.length));return t.filter((function(t,e){return n.has(e)}))}},{key:"randomInteger",value:function(t,e){return Math.floor(this.randomNumber(t,e))}},{key:"randomIntegers",value:function(t,e,n){if(t<=0)return[];for(var r=[],u=0;u<t;u++)r.push(this.randomInteger(e,n));return r}},{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()}},{key:"randomNumbers",value:function(t,e,n){if(t<=0)return[];for(var r=[],u=0;u<t;u++)r.push(this.randomNumber(e,n));return r}}]),t}(),h=function(){function t(){e()(this,t)}return o()(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}(),g=function(){function t(){e()(this,t)}return o()(t,null,[{key:"addYear",value:function(t,e){if(!e)return t;var n=new Date(t);return n.setFullYear(t.getFullYear()+e),n}},{key:"addMonth",value:function(t,e){if(!e)return t;var n=new Date(t);return n.setMonth(t.getMonth()+e),n}},{key:"addDay",value:function(t,e){if(!e)return t;var n=new Date(t);return n.setDate(t.getDate()+e),n}},{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 u in n){var o=new RegExp("(".concat(u,")")).exec(r);o&&(r=/(y+)/.test(u)?r.replace(o[1],n[u].toString().substring(4-o[1].length)):r.replace(o[1],1===o[1].length?n[u].toString():n[u].toString().padStart(o[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:"getStartOfYear",value:function(t){var e=new Date(t);return e.setFullYear(t.getFullYear(),0,1),e.setHours(0,0,0,0),e}},{key:"getStartOfMonth",value:function(t){var e=new Date(t);return e.setDate(1),e.setHours(0,0,0,0),e}},{key:"getStartOfDay",value:function(t){var e=new Date(t);return e.setHours(0,0,0,0),e}},{key:"getEndOfYear",value:function(t){var e=new Date(t);return e.setFullYear(t.getFullYear()+1,0,0),e.setHours(23,59,59,999),e}},{key:"getEndOfMonth",value:function(t){var e=new Date(t);return e.setFullYear(t.getFullYear(),t.getMonth()+1,0),e.setHours(23,59,59,999),e}},{key:"getEndOfDay",value:function(t){var e=new Date(t);return e.setHours(23,59,59,999),e}},{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),u=n%60,o=u>0?":"+("0"+u).slice(-2):"";return(e<0?"+":"-")+r+o}},{key:"isFirstDayOfMonth",value:function(t){return 1===t.getDate()}},{key:"isLastDayOfMonth",value:function(t){return this.isSameDay(this.getEndOfDay(t),this.getEndOfMonth(t))}},{key:"isLeapYear",value:function(t){var e=t instanceof Date?t.getFullYear():t;return!((e%4||!(e%100))&&e%400)}},{key:"isSameYear",value:function(t,e){return t.getFullYear()===e.getFullYear()}},{key:"isSameMonth",value:function(t,e){var n=!(arguments.length>2&&void 0!==arguments[2])||arguments[2];return t.getMonth()===e.getMonth()&&(!n||t.getFullYear()===e.getFullYear())}},{key:"isSameDay",value:function(t,e){var n=!(arguments.length>2&&void 0!==arguments[2])||arguments[2];return t.getDate()===e.getDate()&&(!n||t.getFullYear()===e.getFullYear()&&t.getMonth()===e.getMonth())}},{key:"isWeekend",value:function(t){return 0===t.getDay()||6===t.getDay()}},{key:"isYesterday",value:function(t){return this.isSameDay(new Date,this.addDay(t,1))}},{key:"isTomorrow",value:function(t){return this.isSameDay(new Date,this.addDay(t,-1))}}]),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 u(t,e){for(var n=0;n<e.length;n++){var u=e[n];u.enumerable=u.enumerable||!1,u.configurable=!0,"value"in u&&(u.writable=!0),Object.defineProperty(t,r(u.key),u)}}t.exports=function(t,e,n){return e&&u(t.prototype,e),n&&u(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 u=n.call(t,e||"default");if("object"!==r(u))return u;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,u=n(224);t.exports=function(t){var e=u(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 u=e[r];if(void 0!==u)return u.exports;var o=e[r]={exports:{}};return t[r](o,o.exports,n),o.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 f},BooleanUtils:function(){return y},DateUtils:function(){return g},JsonUtils:function(){return c},ObjectUtils:function(){return a},RandomUtils:function(){return v},StringUtils:function(){return s},ThreadUtils:function(){return h}});var t=n(944),e=n.n(t),u=n(486),o=n.n(u),i=n(702),l=n.n(i),a=function(){function t(){o()(this,t)}return l()(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"===e()(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:"isPlainObject",value:function(t){return"object"===e()(t)&&"[object Object]"===Object.prototype.toString.call(t)}},{key:"isPromiseObject",value:function(t){return"object"===e()(t)&&"[object Promise]"===Object.prototype.toString.call(t)}},{key:"isPrototype",value:function(t){if("object"!==e()(t))return!1;var n=t.constructor;return t===("function"==typeof n?n.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,u=e;r<u.length;r++){var o=u[r];if(this.isNotNil(o))return o}return null}},{key:"getProperty",value:function(t,n){if(!this.anyNil(t,n)&&"object"===e()(t)&&0!==(null==n?void 0:n.length)){var r=n.replace(/\[/g,".").replace(/]/g,"").split(".");if(r&&0!==(null==r?void 0:r.length))return 1===(null==r?void 0:r.length)?t[r[0]]:r.reduce((function(t,e){return(t||{})[e]}),t)}}},{key:"hasProperty",value:function(t,n){return this.allNotNil(t,n)&&"object"===e()(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 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(){o()(this,t)}return l()(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===(null==t?void 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 f.includes(e,t)}},{key:"equalsAnyIgnoreCase",value:function(t,e){var n=this;return!a.isNil(t)&&!f.isEmpty(e)&&e.some((function(e){return n.equalsIgnoreCase(t,e)}))}},{key:"formatBrace",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||f.isEmpty(n))return t;for(var u=t,o=0,i=n;o<i.length;o++){var l=i[o];u=u.replace("{}",a.toString(l,""))}return u}},{key:"formatPlaceholder",value:function(t,e){if(!t||t.length<=2||!e)return t;var n=t;for(var r in e){var u=new RegExp("\\{".concat(r,"\\}"),"gi"),o=e[r];n=n.replace(u,o?o.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}(),f=function(){function t(){o()(this,t)}return l()(t,null,[{key:"getLength",value:function(t){return t?t.length:0}},{key:"getTypeof",value:function(t){if(!this.isEmpty(t))return null==t?void 0:t.map((function(t){return Array.isArray(t)?"array":"object"===e()(t)?null===t?"null":"object":e()(t)}))}},{key:"isEmpty",value:function(t){return!t||0===t.length}},{key:"isNotEmpty",value:function(t){return!this.isEmpty(t)}},{key:"isTypeof",value:function(t,n){var r=arguments.length>2&&void 0!==arguments[2]&&arguments[2];return!this.isEmpty(t)&&!s.isBlank(n)&&(null==t?void 0:t.every((function(t){return e()(t)===n||r&&null===t&&s.equalsAny(n,["string","object"])})))}},{key:"includes",value:function(t,e){return a.allNotNil(t,e)&&t.includes(e)}}]),t}(),y=function(){function t(){o()(this,t)}return l()(t,null,[{key:"fromString",value:function(t){return!!s.equalsAnyIgnoreCase(t,["true","yes","on","y","t","1"])||!s.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}(),c=function(){function t(){o()(this,t)}return l()(t,null,[{key:"isJsonString",value:function(t){if(s.isBlank(t))return!1;try{if("object"===e()(JSON.parse(t)))return!0}catch(t){}return!1}},{key:"toJsonString",value:function(t){if("string"==typeof t&&t.length>0)try{var n=JSON.parse(t);if("object"===e()(n))return JSON.stringify(n)}catch(t){}if(a.isPlainObject(t))return JSON.stringify(t)}}]),t}(),v=function(){function t(){o()(this,t)}return l()(t,null,[{key:"randomBoolean",value:function(){return Math.random()>=.5}},{key:"randomElement",value:function(t){return f.isNotEmpty(t)?t.at(this.randomInteger(0,t.length)):void 0}},{key:"randomElements",value:function(t,e){if(f.isEmpty(t)||e<=0)return[];if(f.getLength(t)<=e)return t;for(var n=new Set;n.size<e;)n.add(this.randomInteger(0,t.length));return t.filter((function(t,e){return n.has(e)}))}},{key:"randomInteger",value:function(t,e){return Math.floor(this.randomNumber(t,e))}},{key:"randomIntegers",value:function(t,e,n){if(t<=0)return[];for(var r=[],u=0;u<t;u++)r.push(this.randomInteger(e,n));return r}},{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()}},{key:"randomNumbers",value:function(t,e,n){if(t<=0)return[];for(var r=[],u=0;u<t;u++)r.push(this.randomNumber(e,n));return r}}]),t}(),h=function(){function t(){o()(this,t)}return l()(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}(),g=function(){function t(){o()(this,t)}return l()(t,null,[{key:"addYear",value:function(t,e){if(!e)return t;var n=new Date(t);return n.setFullYear(t.getFullYear()+e),n}},{key:"addMonth",value:function(t,e){if(!e)return t;var n=new Date(t);return n.setMonth(t.getMonth()+e),n}},{key:"addDay",value:function(t,e){if(!e)return t;var n=new Date(t);return n.setDate(t.getDate()+e),n}},{key:"formatDateTime",value:function(t,e){if(!s.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 u in n){var o=new RegExp("(".concat(u,")")).exec(r);o&&(r=/(y+)/.test(u)?r.replace(o[1],n[u].toString().substring(4-o[1].length)):r.replace(o[1],1===o[1].length?n[u].toString():n[u].toString().padStart(o[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:"getStartOfYear",value:function(t){var e=new Date(t);return e.setFullYear(t.getFullYear(),0,1),e.setHours(0,0,0,0),e}},{key:"getStartOfMonth",value:function(t){var e=new Date(t);return e.setDate(1),e.setHours(0,0,0,0),e}},{key:"getStartOfDay",value:function(t){var e=new Date(t);return e.setHours(0,0,0,0),e}},{key:"getEndOfYear",value:function(t){var e=new Date(t);return e.setFullYear(t.getFullYear()+1,0,0),e.setHours(23,59,59,999),e}},{key:"getEndOfMonth",value:function(t){var e=new Date(t);return e.setFullYear(t.getFullYear(),t.getMonth()+1,0),e.setHours(23,59,59,999),e}},{key:"getEndOfDay",value:function(t){var e=new Date(t);return e.setHours(23,59,59,999),e}},{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),u=n%60,o=u>0?":"+("0"+u).slice(-2):"";return(e<0?"+":"-")+r+o}},{key:"isFirstDayOfMonth",value:function(t){return 1===t.getDate()}},{key:"isLastDayOfMonth",value:function(t){return this.isSameDay(this.getEndOfDay(t),this.getEndOfMonth(t))}},{key:"isLeapYear",value:function(t){var e=t instanceof Date?t.getFullYear():t;return!((e%4||!(e%100))&&e%400)}},{key:"isSameYear",value:function(t,e){return t.getFullYear()===e.getFullYear()}},{key:"isSameMonth",value:function(t,e){var n=!(arguments.length>2&&void 0!==arguments[2])||arguments[2];return t.getMonth()===e.getMonth()&&(!n||t.getFullYear()===e.getFullYear())}},{key:"isSameDay",value:function(t,e){var n=!(arguments.length>2&&void 0!==arguments[2])||arguments[2];return t.getDate()===e.getDate()&&(!n||t.getFullYear()===e.getFullYear()&&t.getMonth()===e.getMonth())}},{key:"isWeekend",value:function(t){return 0===t.getDay()||6===t.getDay()}},{key:"isYesterday",value:function(t){return this.isSameDay(new Date,this.addDay(t,1))}},{key:"isTomorrow",value:function(t){return this.isSameDay(new Date,this.addDay(t,-1))}}]),t}()}(),r}()}));
{
"name": "@yookue/ts-lang-utils",
"version": "0.1.7",
"version": "0.1.8",
"title": "TsLangUtils",

@@ -40,3 +40,3 @@ "description": "Common Lang Utilities for TypeScript",

"dependencies": {
"@babel/runtime": "^7.23.1"
"@babel/runtime": "^7.23.2"
},

@@ -43,0 +43,0 @@ "devDependencies": {

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc