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

@agile-ts/utils

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@agile-ts/utils - npm Package Compare versions

Comparing version 0.0.8 to 0.0.9

dist/dist/index.d.ts

15

CHANGELOG.md
# @agile-ts/utils
## 0.0.9
### Patch Changes
- 488c87c: #### :nail_care: Polish
- `api`, `core`, `cra-template-agile-typescript`, `cra-template-agile`, `event`, `logger`, `multieditor`, `proxytree`, `react`, `utils`, `vue`
- [#194](https://github.com/agile-ts/agile/pull/194) Commonjs issue ([@bennodev19](https://github.com/bennodev19))
- `core`
- [#195](https://github.com/agile-ts/agile/pull/195) Removed `internal.ts` and resolved cycle dependencies ([@bennodev19](https://github.com/bennodev19))
#### Committers: 1
- BennoDev ([@bennodev19](https://github.com/bennodev19))
## 0.0.8

@@ -4,0 +19,0 @@

225

dist/esm/index.js

@@ -1,128 +0,133 @@

export function copy(value) {
if (value == null || typeof value !== 'object')
return value;
const valConstructorName = Object.getPrototypeOf(value).constructor.name.toLowerCase();
if (valConstructorName !== 'object' && valConstructorName !== 'array')
return value;
let temp;
const newObject = Array.isArray(value) ? [] : {};
for (const property in value) {
temp = value[property];
newObject[property] = copy(temp);
var __defProp = Object.defineProperty;
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __propIsEnum = Object.prototype.propertyIsEnumerable;
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
var __spreadValues = (a, b) => {
for (var prop in b || (b = {}))
if (__hasOwnProp.call(b, prop))
__defNormalProp(a, prop, b[prop]);
if (__getOwnPropSymbols)
for (var prop of __getOwnPropSymbols(b)) {
if (__propIsEnum.call(b, prop))
__defNormalProp(a, prop, b[prop]);
}
return newObject;
return a;
};
typeof require !== "undefined" ? require : (x) => {
throw new Error('Dynamic require of "' + x + '" is not supported');
};
function copy(value) {
if (value == null || typeof value !== "object")
return value;
const valConstructorName = Object.getPrototypeOf(value).constructor.name.toLowerCase();
if (valConstructorName !== "object" && valConstructorName !== "array")
return value;
let temp;
const newObject = Array.isArray(value) ? [] : {};
for (const property in value) {
temp = value[property];
newObject[property] = copy(temp);
}
return newObject;
}
export function isValidObject(value, considerArray = false) {
function isHTMLElement(obj) {
try {
return obj instanceof HTMLElement;
}
catch (e) {
return (typeof obj === 'object' &&
obj.nodeType === 1 &&
typeof obj.style === 'object' &&
typeof obj.ownerDocument === 'object');
}
function isValidObject(value, considerArray = false) {
function isHTMLElement(obj) {
try {
return obj instanceof HTMLElement;
} catch (e) {
return typeof obj === "object" && obj.nodeType === 1 && typeof obj.style === "object" && typeof obj.ownerDocument === "object";
}
return (value !== null &&
typeof value === 'object' &&
!isHTMLElement(value) &&
(considerArray ? true : !Array.isArray(value)));
}
return value !== null && typeof value === "object" && !isHTMLElement(value) && (considerArray ? true : !Array.isArray(value));
}
export function includesArray(array1, array2) {
return array2.every((element) => array1.includes(element));
function includesArray(array1, array2) {
return array2.every((element) => array1.includes(element));
}
export function normalizeArray(items, config = {}) {
config = defineConfig(config, {
createUndefinedArray: false,
});
if (items == null && !config.createUndefinedArray)
return [];
return Array.isArray(items) ? items : [items];
function normalizeArray(items, config = {}) {
config = defineConfig(config, {
createUndefinedArray: false
});
if (items == null && !config.createUndefinedArray)
return [];
return Array.isArray(items) ? items : [items];
}
export function isFunction(value) {
return typeof value === 'function';
function isFunction(value) {
return typeof value === "function";
}
export function isAsyncFunction(value) {
const valueString = value.toString();
return (isFunction(value) &&
(value.constructor.name === 'AsyncFunction' ||
valueString.includes('__awaiter')));
function isAsyncFunction(value) {
const valueString = value.toString();
return isFunction(value) && (value.constructor.name === "AsyncFunction" || valueString.includes("__awaiter"));
}
export function isJsonString(value) {
if (typeof value !== 'string')
return false;
try {
JSON.parse(value);
}
catch (e) {
return false;
}
return true;
function isJsonString(value) {
if (typeof value !== "string")
return false;
try {
JSON.parse(value);
} catch (e) {
return false;
}
return true;
}
export function defineConfig(config, defaults, overwriteUndefinedProperties) {
if (overwriteUndefinedProperties === undefined)
overwriteUndefinedProperties = true;
const shallowCopiedConfig = Object.assign({}, config);
for (const defaultKey in defaults) {
if (!Object.prototype.hasOwnProperty.call(shallowCopiedConfig, defaultKey) ||
(overwriteUndefinedProperties &&
shallowCopiedConfig[defaultKey] === undefined))
shallowCopiedConfig[defaultKey] = defaults[defaultKey];
}
return shallowCopiedConfig;
function defineConfig(config, defaults, overwriteUndefinedProperties) {
if (overwriteUndefinedProperties === void 0)
overwriteUndefinedProperties = true;
const shallowCopiedConfig = __spreadValues({}, config);
for (const defaultKey in defaults) {
if (!Object.prototype.hasOwnProperty.call(shallowCopiedConfig, defaultKey) || overwriteUndefinedProperties && shallowCopiedConfig[defaultKey] === void 0)
shallowCopiedConfig[defaultKey] = defaults[defaultKey];
}
return shallowCopiedConfig;
}
export function flatMerge(source, changes, config = {}) {
config = defineConfig(config, {
addNewProperties: true,
});
const _source = copy(source);
if (_source == null)
return _source;
const keys = Object.keys(changes);
keys.forEach((property) => {
if ((!config.addNewProperties && _source[property] != null) ||
config.addNewProperties)
_source[property] = changes[property];
});
function flatMerge(source, changes, config = {}) {
config = defineConfig(config, {
addNewProperties: true
});
const _source = copy(source);
if (_source == null)
return _source;
const keys = Object.keys(changes);
keys.forEach((property) => {
if (!config.addNewProperties && _source[property] != null || config.addNewProperties)
_source[property] = changes[property];
});
return _source;
}
export function equal(value1, value2) {
return (value1 === value2 ||
(typeof value1 === 'object' &&
typeof value2 === 'object' &&
JSON.stringify(value1) === JSON.stringify(value2)));
function equal(value1, value2) {
return value1 === value2 || typeof value1 === "object" && typeof value2 === "object" && JSON.stringify(value1) === JSON.stringify(value2);
}
export function notEqual(value1, value2) {
return !equal(value1, value2);
function notEqual(value1, value2) {
return !equal(value1, value2);
}
export function generateId(length = 5, characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789') {
const charactersLength = characters.length;
let result = '';
for (let i = 0; i < length; i++) {
result += characters.charAt(Math.floor(Math.random() * charactersLength));
}
return result;
function generateId(length = 5, characters = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789") {
const charactersLength = characters.length;
let result = "";
for (let i = 0; i < length; i++) {
result += characters.charAt(Math.floor(Math.random() * charactersLength));
}
return result;
}
export function createArrayFromObject(object) {
const array = [];
for (const key in object) {
array.push({
key: key,
instance: object[key],
});
}
return array;
function createArrayFromObject(object) {
const array = [];
for (const key in object) {
array.push({
key,
instance: object[key]
});
}
return array;
}
export function clone(instance) {
const objectCopy = Object.create(Object.getPrototypeOf(instance));
const objectClone = Object.assign(objectCopy, instance);
for (const key in objectClone)
objectClone[key] = copy(objectClone[key]);
return objectClone;
function clone(instance) {
const objectCopy = Object.create(Object.getPrototypeOf(instance));
const objectClone = Object.assign(objectCopy, instance);
for (const key in objectClone)
objectClone[key] = copy(objectClone[key]);
return objectClone;
}
export function removeProperties(object, properties) {
const copiedObject = copy(object);
properties.map((property) => delete copiedObject[property]);
return copiedObject;
function removeProperties(object, properties) {
const copiedObject = copy(object);
properties.map((property) => delete copiedObject[property]);
return copiedObject;
}
export { clone, copy, createArrayFromObject, defineConfig, equal, flatMerge, generateId, includesArray, isAsyncFunction, isFunction, isJsonString, isValidObject, normalizeArray, notEqual, removeProperties };

@@ -1,7 +0,17 @@

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.removeProperties = exports.clone = exports.createArrayFromObject = exports.generateId = exports.notEqual = exports.equal = exports.flatMerge = exports.defineConfig = exports.isJsonString = exports.isAsyncFunction = exports.isFunction = exports.normalizeArray = exports.includesArray = exports.isValidObject = exports.copy = void 0;
'use strict';
Object.defineProperty(exports, '__esModule', { value: true });
/**
* Creates a fresh (deep) copy of the specified value.
* https://www.samanthaming.com/tidbits/70-3-ways-to-clone-objects/
*
* @public
* @param value - Value to be copied.
*/
function copy(value) {
// Extra checking 'value == null' because 'typeof null === object'
if (value == null || typeof value !== 'object')
return value;
// Ignore everything that is no object or array but has the type of an object (e.g. classes)
const valConstructorName = Object.getPrototypeOf(value).constructor.name.toLowerCase();

@@ -18,3 +28,10 @@ if (valConstructorName !== 'object' && valConstructorName !== 'array')

}
exports.copy = copy;
/**
* Checks whether the specified value is a valid object.
* https://stackoverflow.com/questions/12996871/why-does-typeof-array-with-objects-return-object-and-not-array
*
* @public
* @param value - Value
* @param considerArray - Whether to considered an array as an object.
*/
function isValidObject(value, considerArray = false) {

@@ -37,10 +54,22 @@ function isHTMLElement(obj) {

}
exports.isValidObject = isValidObject;
/**
* Checks whether 'array1' contains all elements of 'array2'.
*
* @public
* @param array1 - Array 1
* @param array2 - Array 2
*/
function includesArray(array1, array2) {
return array2.every((element) => array1.includes(element));
}
exports.includesArray = includesArray;
/**
* Transforms Item/s into an array of Items.
*
* @public
* @param items - Item/s to be transformed into an array of Items.
* @param config - Config
*/
function normalizeArray(items, config = {}) {
config = defineConfig(config, {
createUndefinedArray: false,
createUndefinedArray: false, // If it should return [] or [undefined] if the passed Item is undefined
});

@@ -51,7 +80,17 @@ if (items == null && !config.createUndefinedArray)

}
exports.normalizeArray = normalizeArray;
/**
* Checks whether the specified function is a function.
*
* @public
* @param value - Value to be checked
*/
function isFunction(value) {
return typeof value === 'function';
}
exports.isFunction = isFunction;
/**
* Checks whether the specified function is an async function.
*
* @public
* @param value - Value to be checked.
*/
function isAsyncFunction(value) {

@@ -63,3 +102,8 @@ const valueString = value.toString();

}
exports.isAsyncFunction = isAsyncFunction;
/**
* Checks whether the specified value is a valid JSON string
*
* @public
* @param value - Value to be checked.
*/
function isJsonString(value) {

@@ -76,7 +120,14 @@ if (typeof value !== 'string')

}
exports.isJsonString = isJsonString;
/**
* Merges the default values object ('defaults') into the configuration object ('config').
*
* @public
* @param config - Configuration object to merge the default values in.
* @param defaults - Default values object to be merged into the configuration object.
* @param overwriteUndefinedProperties - Whether to overwrite 'undefined' set properties with default values.
*/
function defineConfig(config, defaults, overwriteUndefinedProperties) {
if (overwriteUndefinedProperties === undefined)
overwriteUndefinedProperties = true;
const shallowCopiedConfig = Object.assign({}, config);
const shallowCopiedConfig = { ...config };
for (const defaultKey in defaults) {

@@ -90,3 +141,10 @@ if (!Object.prototype.hasOwnProperty.call(shallowCopiedConfig, defaultKey) ||

}
exports.defineConfig = defineConfig;
/**
* Merges the 'changes' object into the 'source' object at top level.
*
* @public
* @param source - Source object
* @param changes - Changes object to be merged into the source object
* @param config - Configuration object
*/
function flatMerge(source, changes, config = {}) {

@@ -96,5 +154,7 @@ config = defineConfig(config, {

});
// Copy Source to avoid References
const _source = copy(source);
if (_source == null)
return _source;
// Merge Changes Object into Source Object
const keys = Object.keys(changes);

@@ -108,5 +168,13 @@ keys.forEach((property) => {

}
exports.flatMerge = flatMerge;
/**
* Checks whether the two specified values are equivalent.
*
* @public
* @param value1 - First value.
* @param value2 - Second value.
*/
function equal(value1, value2) {
return (value1 === value2 ||
// Checking if 'value1' and 'value2' is typeof object before
// using the JSON.stringify comparison to optimize the performance
(typeof value1 === 'object' &&

@@ -116,7 +184,19 @@ typeof value2 === 'object' &&

}
exports.equal = equal;
/**
* Checks whether the two specified values are NOT equivalent.
*
* @public
* @param value1 - First value.
* @param value2 - Second value.
*/
function notEqual(value1, value2) {
return !equal(value1, value2);
}
exports.notEqual = notEqual;
/**
* Generates a randomized id based on alphabetic and numeric characters.
*
* @public
* @param length - Length of the to generate id (default = 5).
* @param characters - Characters to generate the id from (default = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789').
*/
function generateId(length = 5, characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789') {

@@ -130,3 +210,11 @@ const charactersLength = characters.length;

}
exports.generateId = generateId;
/**
* Transforms the specified object into an array.
*
* Example:
* {"1": 'jeff', 2: 'frank'} -> [{key: "1", instance: 'jeff'}, {key: 2, instance: 'frank'}]
*
* @public
* @param object - Object to be transformed to an array.
*/
function createArrayFromObject(object) {

@@ -142,6 +230,13 @@ const array = [];

}
exports.createArrayFromObject = createArrayFromObject;
/**
* Clones the specified class.
*
* @public
* @param instance - Class to be cloned.
*/
function clone(instance) {
// Clone Class
const objectCopy = Object.create(Object.getPrototypeOf(instance));
const objectClone = Object.assign(objectCopy, instance);
// Copy Properties of Class to remove flat references
for (const key in objectClone)

@@ -151,3 +246,9 @@ objectClone[key] = copy(objectClone[key]);

}
exports.clone = clone;
/**
* Removes specified properties from the defined object.
*
* @public
* @param object - Object to remove the specified properties from.
* @param properties - Property keys to be removed from the specified object.
*/
function removeProperties(object, properties) {

@@ -158,2 +259,17 @@ const copiedObject = copy(object);

}
exports.clone = clone;
exports.copy = copy;
exports.createArrayFromObject = createArrayFromObject;
exports.defineConfig = defineConfig;
exports.equal = equal;
exports.flatMerge = flatMerge;
exports.generateId = generateId;
exports.includesArray = includesArray;
exports.isAsyncFunction = isAsyncFunction;
exports.isFunction = isFunction;
exports.isJsonString = isJsonString;
exports.isValidObject = isValidObject;
exports.normalizeArray = normalizeArray;
exports.notEqual = notEqual;
exports.removeProperties = removeProperties;
{
"name": "@agile-ts/utils",
"version": "0.0.8",
"version": "0.0.9",
"author": "BennoDev",

@@ -16,11 +16,18 @@ "license": "MIT",

"types": "dist/index.d.ts",
"exports": {
"./package.json": "./package.json",
".": {
"types": "./dist/index.d.ts",
"module": "./dist/esm/index.js",
"import": "./dist/esm/index.js",
"default": "./dist/index.js"
}
},
"scripts": {
"build": "yarn run build:esm && yarn run build:cjs",
"build": "shx rm -rf dist && rollup --c rollup.config.js",
"prepare": "yarn run build",
"build:esm": "tsc -p ./tsconfig.esm.json",
"build:cjs": "tsc -p ./tsconfig.json && tsc -p ./tsconfig.production.json",
"dev:publish": "yalc publish",
"dev:push": "yalc push",
"watch:push": "tsc-watch --onSuccess \"yarn run dev:push\"",
"watch": "tsc -w",
"watch": "shx rm -rf dist && tsc -w",
"release": "yarn run prepare",

@@ -27,0 +34,0 @@ "release:manual": "yarn run prepare && yarn run release && npm publish",

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