@amaui/amaui-binary-tree
Advanced tools
Comparing version 1.0.1111 to 1.0.11111
"use strict"; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.AmauiBinaryTree = exports.AmauiNode = void 0; | ||
const utils_1 = require("@amaui/utils"); | ||
const is_1 = __importDefault(require("@amaui/utils/is")); | ||
class AmauiNode { | ||
@@ -52,3 +55,3 @@ constructor(value, left, right) { | ||
static preorder(value, method) { | ||
if (value !== undefined && (0, utils_1.is)('function', method)) { | ||
if (value !== undefined && (0, is_1.default)('function', method)) { | ||
method(value, value.left, value.right); | ||
@@ -60,3 +63,3 @@ this.preorder(value.left, method); | ||
static inorder(value, method) { | ||
if (value !== undefined && (0, utils_1.is)('function', method)) { | ||
if (value !== undefined && (0, is_1.default)('function', method)) { | ||
this.inorder(value.left, method); | ||
@@ -68,3 +71,3 @@ method(value, value.left, value.right); | ||
static postorder(value, method) { | ||
if (value !== undefined && (0, utils_1.is)('function', method)) { | ||
if (value !== undefined && (0, is_1.default)('function', method)) { | ||
this.postorder(value.left, method); | ||
@@ -94,3 +97,3 @@ this.postorder(value.right, method); | ||
make(value) { | ||
if ((0, utils_1.is)('array', value)) | ||
if ((0, is_1.default)('array', value)) | ||
value.forEach(item => this.add(item)); | ||
@@ -97,0 +100,0 @@ return this; |
import _defineProperty from "@babel/runtime/helpers/defineProperty"; | ||
import { is } from '@amaui/utils'; | ||
import is from '@amaui/utils/is'; | ||
export class AmauiNode { | ||
@@ -4,0 +4,0 @@ constructor(value, left, right) { |
@@ -1,2 +0,2 @@ | ||
/** @license AmauiBinaryTree v1.0.1111 | ||
/** @license AmauiBinaryTree v1.0.11111 | ||
* | ||
@@ -3,0 +3,0 @@ * This source code is licensed under the MIT license found in the |
{ | ||
"name": "@amaui/amaui-binary-tree", | ||
"version": "1.0.1111", | ||
"version": "1.0.11111", | ||
"description": "Binary tree", | ||
@@ -30,3 +30,3 @@ "repository": "https://github.com/amaui-org/amaui-binary-tree.git", | ||
"dependencies": { | ||
"@amaui/utils": "^1.0.11114", | ||
"@amaui/utils": "^1.0.11411", | ||
"@babel/runtime": "^7.18.3" | ||
@@ -36,3 +36,3 @@ }, | ||
"access": "public", | ||
"registry": "https://registry.npmjs.org/" | ||
"registry": "https://registry.npmjs.org" | ||
}, | ||
@@ -39,0 +39,0 @@ "sideEffects": false, |
@@ -22,3 +22,3 @@ | ||
<sub>Production ready </sub> | ||
<sub>UMD 2kb gzipped </sub> | ||
<sub>UMD 1.9kb gzipped </sub> | ||
<sub>100% test cov </sub> | ||
@@ -25,0 +25,0 @@ <sub>Browser and Nodejs</sub> |
@@ -1,2 +0,2 @@ | ||
/** @license AmauiBinaryTree v1.0.1111 | ||
/** @license AmauiBinaryTree v1.0.11111 | ||
* | ||
@@ -31,197 +31,145 @@ * This source code is licensed under the MIT license found in the | ||
const optionsDefault = {}; // Multiple is methods instead of one, | ||
// so it's lighter for tree shaking usability reasons | ||
function getDefaultExportFromCjs (x) { | ||
return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x; | ||
} | ||
const is = function (type) { | ||
var _value$constructor; | ||
var is$1 = {exports: {}}; | ||
let value = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : undefined; | ||
let options_ = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : optionsDefault; | ||
const options = { ...optionsDefault, | ||
...options_ | ||
}; | ||
const { | ||
variant | ||
} = options; | ||
const prototype = value && typeof value === 'object' && Object.getPrototypeOf(value); | ||
switch (type) { | ||
case 'string': | ||
return typeof value === 'string'; | ||
case 'number': | ||
return typeof value === 'number' && !Number.isNaN(value); | ||
case 'boolean': | ||
return typeof value === 'boolean'; | ||
case 'array': | ||
return Array.isArray(value); | ||
case 'object': | ||
const isObject = typeof value === 'object' && !!value && value.constructor === Object; | ||
return isObject; | ||
// Map, null, WeakMap, Date, etc. | ||
case 'object-like': | ||
return typeof value === 'object' && (value === null || value.constructor !== Object); | ||
case 'class': | ||
return (typeof value === 'object' || typeof value === 'function') && (/class/gi.test(String(value)) || /class/gi.test(String(value === null || value === void 0 ? void 0 : value.constructor))); | ||
case 'function': | ||
return !!(value && value instanceof Function); | ||
case 'async': | ||
// If it's browser avoid calling the method | ||
// to see if it's async func or not, | ||
// where as in nodejs we have no other choice | ||
// that i know of when using transpilation | ||
// And also it might not be always correct, as | ||
// a method that returns a promise is also async | ||
// but we can't know that until the method is called and | ||
// we inspect the method's return value | ||
return !!(is('function', value) && (isEnvironment('browser') ? value.constructor.name === 'AsyncFunction' : value() instanceof Promise)); | ||
case 'map': | ||
return !!(prototype === Map.prototype); | ||
case 'weakmap': | ||
return !!(prototype === WeakMap.prototype); | ||
case 'set': | ||
return !!(prototype === Set.prototype); | ||
case 'weakset': | ||
return !!(prototype === WeakSet.prototype); | ||
case 'promise': | ||
return !!(prototype === Promise.prototype); | ||
case 'int8array': | ||
return !!(prototype === Int8Array.prototype); | ||
case 'uint8array': | ||
return !!(prototype === Uint8Array.prototype); | ||
case 'uint8clampedarray': | ||
return !!(prototype === Uint8ClampedArray.prototype); | ||
case 'int16array': | ||
return !!(prototype === Int16Array.prototype); | ||
case 'uint16array': | ||
return !!(prototype === Uint16Array.prototype); | ||
case 'int32array': | ||
return !!(prototype === Int32Array.prototype); | ||
case 'uint32array': | ||
return !!(prototype === Uint32Array.prototype); | ||
case 'float32array': | ||
return !!(prototype === Float32Array.prototype); | ||
case 'float64array': | ||
return !!(prototype === Float64Array.prototype); | ||
case 'bigint64array': | ||
return !!(prototype === BigInt64Array.prototype); | ||
case 'biguint64array': | ||
return !!(prototype === BigUint64Array.prototype); | ||
case 'typedarray': | ||
return is('int8array', value) || is('uint8array', value) || is('uint8clampedarray', value) || is('int16array', value) || is('uint16array', value) || is('int32array', value) || is('uint32array', value) || is('float32array', value) || is('float64array', value) || is('bigint64array', value) || is('biguint64array', value); | ||
case 'dataview': | ||
return !!(prototype === DataView.prototype); | ||
case 'arraybuffer': | ||
return !!(prototype === ArrayBuffer.prototype); | ||
case 'sharedarraybuffer': | ||
return typeof SharedArrayBuffer !== 'undefined' && !!(prototype === SharedArrayBuffer.prototype); | ||
case 'symbol': | ||
return !!(typeof value === 'symbol'); | ||
case 'error': | ||
return !!(value && value instanceof Error); | ||
case 'date': | ||
return !!(value && value instanceof Date); | ||
case 'regexp': | ||
return !!(value && value instanceof RegExp); | ||
case 'arguments': | ||
return !!(value && value.toString() === '[object Arguments]'); | ||
case 'null': | ||
return value === null; | ||
case 'undefined': | ||
return value === undefined; | ||
case 'blob': | ||
return isEnvironment('browser') && value instanceof Blob; | ||
case 'buffer': | ||
return !!(isEnvironment('nodejs') && typeof (value === null || value === void 0 ? void 0 : (_value$constructor = value.constructor) === null || _value$constructor === void 0 ? void 0 : _value$constructor.isBuffer) === 'function' && value.constructor.isBuffer(value)); | ||
case 'element': | ||
if (value) { | ||
switch (variant) { | ||
case undefined: | ||
case 'html': | ||
case 'element': | ||
return isEnvironment('browser') && (typeof HTMLElement === 'object' ? value instanceof HTMLElement : value && typeof value === 'object' && value !== null && value.nodeType === 1 && typeof value.nodeName === 'string'); | ||
case 'node': | ||
return isEnvironment('browser') && (typeof Node === 'object' ? value instanceof Node : value && typeof value === 'object' && value !== null && typeof value.nodeType === 'number' && typeof value.nodeName === 'string'); | ||
case 'react': | ||
return value.elementType || value.hasOwnProperty('$$typeof'); | ||
default: | ||
(function (module, exports) { | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const optionsDefault = {}; | ||
const isBrowser = typeof window !== 'undefined' && typeof window.document !== 'undefined'; | ||
const isNodejs = !!(typeof global$1 !== 'undefined' && 'object' !== 'undefined' && module.exports); | ||
// Multiple is methods instead of one, | ||
// so it's lighter for tree shaking usability reasons | ||
function is(type, value, options_ = {}) { | ||
var _a; | ||
const options = Object.assign(Object.assign({}, optionsDefault), options_); | ||
const { variant } = options; | ||
const prototype = value && typeof value === 'object' && Object.getPrototypeOf(value); | ||
switch (type) { | ||
case 'string': | ||
return typeof value === 'string'; | ||
case 'number': | ||
return typeof value === 'number' && !Number.isNaN(value); | ||
case 'boolean': | ||
return typeof value === 'boolean'; | ||
case 'array': | ||
return Array.isArray(value); | ||
case 'object': | ||
const isObject = typeof value === 'object' && !!value && value.constructor === Object; | ||
return isObject; | ||
// Map, null, WeakMap, Date, etc. | ||
case 'object-like': | ||
return typeof value === 'object' && (value === null || value.constructor !== Object); | ||
case 'class': | ||
return ((typeof value === 'object' || typeof value === 'function') && | ||
(/class/gi.test(String(value)) || /class/gi.test(String(value === null || value === void 0 ? void 0 : value.constructor)))); | ||
case 'function': | ||
return !!(value && value instanceof Function); | ||
case 'async': | ||
// If it's browser avoid calling the method | ||
// to see if it's async func or not, | ||
// where as in nodejs we have no other choice | ||
// that i know of when using transpilation | ||
// And also it might not be always correct, as | ||
// a method that returns a promise is also async | ||
// but we can't know that until the method is called and | ||
// we inspect the method's return value | ||
return !!(is('function', value) && (isBrowser ? value.constructor.name === 'AsyncFunction' : value() instanceof Promise)); | ||
case 'map': | ||
return !!(prototype === Map.prototype); | ||
case 'weakmap': | ||
return !!(prototype === WeakMap.prototype); | ||
case 'set': | ||
return !!(prototype === Set.prototype); | ||
case 'weakset': | ||
return !!(prototype === WeakSet.prototype); | ||
case 'promise': | ||
return !!(prototype === Promise.prototype); | ||
case 'int8array': | ||
return !!(prototype === Int8Array.prototype); | ||
case 'uint8array': | ||
return !!(prototype === Uint8Array.prototype); | ||
case 'uint8clampedarray': | ||
return !!(prototype === Uint8ClampedArray.prototype); | ||
case 'int16array': | ||
return !!(prototype === Int16Array.prototype); | ||
case 'uint16array': | ||
return !!(prototype === Uint16Array.prototype); | ||
case 'int32array': | ||
return !!(prototype === Int32Array.prototype); | ||
case 'uint32array': | ||
return !!(prototype === Uint32Array.prototype); | ||
case 'float32array': | ||
return !!(prototype === Float32Array.prototype); | ||
case 'float64array': | ||
return !!(prototype === Float64Array.prototype); | ||
case 'bigint64array': | ||
return !!(prototype === BigInt64Array.prototype); | ||
case 'biguint64array': | ||
return !!(prototype === BigUint64Array.prototype); | ||
case 'typedarray': | ||
return is('int8array', value) || is('uint8array', value) || is('uint8clampedarray', value) || is('int16array', value) || is('uint16array', value) || is('int32array', value) || is('uint32array', value) || is('float32array', value) || is('float64array', value) || is('bigint64array', value) || is('biguint64array', value); | ||
case 'dataview': | ||
return !!(prototype === DataView.prototype); | ||
case 'arraybuffer': | ||
return !!(prototype === ArrayBuffer.prototype); | ||
case 'sharedarraybuffer': | ||
return typeof SharedArrayBuffer !== 'undefined' && !!(prototype === SharedArrayBuffer.prototype); | ||
case 'symbol': | ||
return !!(typeof value === 'symbol'); | ||
case 'error': | ||
return !!(value && value instanceof Error); | ||
case 'date': | ||
return !!(value && value instanceof Date); | ||
case 'regexp': | ||
return !!(value && value instanceof RegExp); | ||
case 'arguments': | ||
return !!(value && value.toString() === '[object Arguments]'); | ||
case 'null': | ||
return value === null; | ||
case 'undefined': | ||
return value === undefined; | ||
case 'blob': | ||
return isBrowser && value instanceof Blob; | ||
case 'buffer': | ||
return !!(isNodejs && typeof ((_a = value === null || value === void 0 ? void 0 : value.constructor) === null || _a === void 0 ? void 0 : _a.isBuffer) === 'function' && value.constructor.isBuffer(value)); | ||
case 'element': | ||
if (value) { | ||
switch (variant) { | ||
case undefined: | ||
case 'html': | ||
case 'element': | ||
return isBrowser && (typeof HTMLElement === 'object' ? | ||
value instanceof HTMLElement : | ||
value && typeof value === 'object' && value !== null && value.nodeType === 1 && typeof value.nodeName === 'string'); | ||
case 'node': | ||
return isBrowser && (typeof Node === 'object' ? | ||
value instanceof Node : | ||
value && typeof value === 'object' && value !== null && typeof value.nodeType === 'number' && typeof value.nodeName === 'string'); | ||
case 'react': | ||
return value.elementType || value.hasOwnProperty('$$typeof'); | ||
default: | ||
return false; | ||
} | ||
} | ||
return false; | ||
} | ||
} | ||
case 'simple': | ||
return (is('string', value, options) || | ||
is('number', value, options) || | ||
is('boolean', value, options) || | ||
is('undefined', value, options) || | ||
is('null', value, options)); | ||
case 'not-array-object': | ||
return !is('array', value, options) && !is('object', value, options); | ||
default: | ||
return false; | ||
} | ||
} | ||
exports.default = is; | ||
}(is$1, is$1.exports)); | ||
return false; | ||
var is = /*@__PURE__*/getDefaultExportFromCjs(is$1.exports); | ||
case 'simple': | ||
return is('string', value, options) || is('number', value, options) || is('boolean', value, options) || is('undefined', value, options) || is('null', value, options); | ||
case 'not-array-object': | ||
return !is('array', value, options) && !is('object', value, options); | ||
default: | ||
return false; | ||
} | ||
}; | ||
const isEnvironment = function (type) { | ||
let value = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : undefined; | ||
let value_; | ||
switch (type) { | ||
case 'browser': | ||
return typeof window !== 'undefined' && typeof window.document !== 'undefined'; | ||
case 'worker': | ||
return typeof WorkerGlobalScope !== 'undefined' && self instanceof WorkerGlobalScope; | ||
case 'nodejs': | ||
return !!(typeof global$1 !== 'undefined' && typeof module !== 'undefined' && module.exports); | ||
case 'localhost': | ||
value_ = value !== undefined ? value : isEnvironment('browser') && window.location.hostname; | ||
return is('string', value_) && ['localhost', '127.0.0.1'].some(value__ => value_.indexOf(value__) > -1); | ||
default: | ||
return false; | ||
} | ||
}; | ||
class AmauiNode { | ||
@@ -228,0 +176,0 @@ constructor(value, left, right) { |
@@ -1,2 +0,2 @@ | ||
/** @license AmauiBinaryTree v1.0.1111 | ||
/** @license AmauiBinaryTree v1.0.11111 | ||
* | ||
@@ -6,2 +6,2 @@ * This source code is licensed under the MIT license found in the | ||
*/ | ||
!function(e,r){"object"==typeof exports&&"undefined"!=typeof module?r(exports):"function"==typeof define&&define.amd?define(["exports"],r):r((e="undefined"!=typeof globalThis?globalThis:e||self).AmauiBinaryTree={})}(this,(function(e){"use strict";var r="undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{};const t={},o=function(e){var r;let a=arguments.length>1&&void 0!==arguments[1]?arguments[1]:void 0,i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:t;const s={...t,...i},{variant:u}=s,c=a&&"object"==typeof a&&Object.getPrototypeOf(a);switch(e){case"string":return"string"==typeof a;case"number":return"number"==typeof a&&!Number.isNaN(a);case"boolean":return"boolean"==typeof a;case"array":return Array.isArray(a);case"object":return"object"==typeof a&&!!a&&a.constructor===Object;case"object-like":return"object"==typeof a&&(null===a||a.constructor!==Object);case"class":return("object"==typeof a||"function"==typeof a)&&(/class/gi.test(String(a))||/class/gi.test(String(null==a?void 0:a.constructor)));case"function":return!!(a&&a instanceof Function);case"async":return!(!o("function",a)||!(n("browser")?"AsyncFunction"===a.constructor.name:a()instanceof Promise));case"map":return!(c!==Map.prototype);case"weakmap":return!(c!==WeakMap.prototype);case"set":return!(c!==Set.prototype);case"weakset":return!(c!==WeakSet.prototype);case"promise":return!(c!==Promise.prototype);case"int8array":return!(c!==Int8Array.prototype);case"uint8array":return!(c!==Uint8Array.prototype);case"uint8clampedarray":return!(c!==Uint8ClampedArray.prototype);case"int16array":return!(c!==Int16Array.prototype);case"uint16array":return!(c!==Uint16Array.prototype);case"int32array":return!(c!==Int32Array.prototype);case"uint32array":return!(c!==Uint32Array.prototype);case"float32array":return!(c!==Float32Array.prototype);case"float64array":return!(c!==Float64Array.prototype);case"bigint64array":return!(c!==BigInt64Array.prototype);case"biguint64array":return!(c!==BigUint64Array.prototype);case"typedarray":return o("int8array",a)||o("uint8array",a)||o("uint8clampedarray",a)||o("int16array",a)||o("uint16array",a)||o("int32array",a)||o("uint32array",a)||o("float32array",a)||o("float64array",a)||o("bigint64array",a)||o("biguint64array",a);case"dataview":return!(c!==DataView.prototype);case"arraybuffer":return!(c!==ArrayBuffer.prototype);case"sharedarraybuffer":return"undefined"!=typeof SharedArrayBuffer&&!(c!==SharedArrayBuffer.prototype);case"symbol":return!("symbol"!=typeof a);case"error":return!!(a&&a instanceof Error);case"date":return!!(a&&a instanceof Date);case"regexp":return!!(a&&a instanceof RegExp);case"arguments":return!(!a||"[object Arguments]"!==a.toString());case"null":return null===a;case"undefined":return void 0===a;case"blob":return n("browser")&&a instanceof Blob;case"buffer":return!(!n("nodejs")||"function"!=typeof(null==a||null===(r=a.constructor)||void 0===r?void 0:r.isBuffer)||!a.constructor.isBuffer(a));case"element":if(a)switch(u){case void 0:case"html":case"element":return n("browser")&&("object"==typeof HTMLElement?a instanceof HTMLElement:a&&"object"==typeof a&&null!==a&&1===a.nodeType&&"string"==typeof a.nodeName);case"node":return n("browser")&&("object"==typeof Node?a instanceof Node:a&&"object"==typeof a&&null!==a&&"number"==typeof a.nodeType&&"string"==typeof a.nodeName);case"react":return a.elementType||a.hasOwnProperty("$$typeof");default:return!1}return!1;case"simple":return o("string",a,s)||o("number",a,s)||o("boolean",a,s)||o("undefined",a,s)||o("null",a,s);case"not-array-object":return!o("array",a,s)&&!o("object",a,s);default:return!1}},n=function(e){let t,a=arguments.length>1&&void 0!==arguments[1]?arguments[1]:void 0;switch(e){case"browser":return"undefined"!=typeof window&&void 0!==window.document;case"worker":return"undefined"!=typeof WorkerGlobalScope&&self instanceof WorkerGlobalScope;case"nodejs":return!(void 0===r||"undefined"==typeof module||!module.exports);case"localhost":return t=void 0!==a?a:n("browser")&&window.location.hostname,o("string",t)&&["localhost","127.0.0.1"].some((e=>t.indexOf(e)>-1));default:return!1}};class a{constructor(e,r,t){this.value=e,this.left=r,this.right=t}}class i{constructor(){var e,r,t;t=void 0,(r="root")in(e=this)?Object.defineProperty(e,r,{value:t,enumerable:!0,configurable:!0,writable:!0}):e[r]=t}static make(e){return(new i).make(e)}static lowestCommonAncestor(e,r,t){let o;const n=t=>{if(!t)return;const i=t.value===(e instanceof a?e.value:e)||t.value===(r instanceof a?r.value:r),s=n(t.left),u=n(t.right);return(i&&s||i&&u||s&&u)&&(o=t),s||u||i};return n(t),o}static maxDepth(e){const r=e=>void 0===e?0:Math.max(1+r(e.left),1+r(e.right));return r(e)}static valid(e){const r=e=>{var t,o;return void 0===e||!((null===(t=e.left)||void 0===t?void 0:t.value)>=e.value)&&(!((null===(o=e.right)||void 0===o?void 0:o.value)<=e.value)&&(r(e.left)&&r(e.right)))};return r(e.root)}static preorder(e,r){void 0!==e&&o("function",r)&&(r(e,e.left,e.right),this.preorder(e.left,r),this.preorder(e.right,r))}static inorder(e,r){void 0!==e&&o("function",r)&&(this.inorder(e.left,r),r(e,e.left,e.right),this.inorder(e.right,r))}static postorder(e,r){void 0!==e&&o("function",r)&&(this.postorder(e.left,r),this.postorder(e.right,r),r(e,e.left,e.right))}static min(e){let r=e;for(;void 0!==(null===(t=r)||void 0===t?void 0:t.left);){var t;r=r.left}return r}static max(e){let r=e;for(;void 0!==(null===(t=r)||void 0===t?void 0:t.right);){var t;r=r.right}return r}array(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"preorder";const r=[];return i[e]&&i[e](this.root,(e=>r.push(e.value))),r}make(e){return o("array",e)&&e.forEach((e=>this.add(e))),this}add(e){const r=e instanceof a?e:new a(e);if(!this.root)return this.root=r,this;let t=this.root;for(;t;){if(r.value===t.value)return this;if(r.value<t.value){if(void 0===t.left)return t.left=r,this;t=t.left}if(r.value>t.value){if(void 0===t.right)return t.right=r,this;t=t.right}}}find(e){if(!this.root)return;let r,t=this.root;for(;t&&!r;)e<t.value?t=t.left:e>t.value?t=t.right:r=t;return r}remove(e){this.root=this.removeNode(this.root,e)}removeNode(e,r){if(void 0!==e){if(r===e.value){if(void 0===e.left&&void 0===e.right)return;if(void 0===e.left)return e.right;if(void 0===e.right)return e.left;const r=i.min(e.right);return e.value=r.value,e.right=this.removeNode(e.right,r.value),e}return r<e.value?(e.left=this.removeNode(e.left,r),e):(e.right=this.removeNode(e.right,r),e)}}}e.AmauiBinaryTree=i,e.AmauiNode=a,Object.defineProperty(e,"__esModule",{value:!0})})); | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).AmauiBinaryTree={})}(this,(function(e){"use strict";var t="undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{};function r(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var o={exports:{}};!function(e,r){Object.defineProperty(r,"__esModule",{value:!0});const o={},n="undefined"!=typeof window&&void 0!==window.document,a=!(void 0===t||!e.exports);r.default=function e(t,r,i={}){var u;const s=Object.assign(Object.assign({},o),i),{variant:c}=s,f=r&&"object"==typeof r&&Object.getPrototypeOf(r);switch(t){case"string":return"string"==typeof r;case"number":return"number"==typeof r&&!Number.isNaN(r);case"boolean":return"boolean"==typeof r;case"array":return Array.isArray(r);case"object":return"object"==typeof r&&!!r&&r.constructor===Object;case"object-like":return"object"==typeof r&&(null===r||r.constructor!==Object);case"class":return("object"==typeof r||"function"==typeof r)&&(/class/gi.test(String(r))||/class/gi.test(String(null==r?void 0:r.constructor)));case"function":return!!(r&&r instanceof Function);case"async":return!(!e("function",r)||!(n?"AsyncFunction"===r.constructor.name:r()instanceof Promise));case"map":return!(f!==Map.prototype);case"weakmap":return!(f!==WeakMap.prototype);case"set":return!(f!==Set.prototype);case"weakset":return!(f!==WeakSet.prototype);case"promise":return!(f!==Promise.prototype);case"int8array":return!(f!==Int8Array.prototype);case"uint8array":return!(f!==Uint8Array.prototype);case"uint8clampedarray":return!(f!==Uint8ClampedArray.prototype);case"int16array":return!(f!==Int16Array.prototype);case"uint16array":return!(f!==Uint16Array.prototype);case"int32array":return!(f!==Int32Array.prototype);case"uint32array":return!(f!==Uint32Array.prototype);case"float32array":return!(f!==Float32Array.prototype);case"float64array":return!(f!==Float64Array.prototype);case"bigint64array":return!(f!==BigInt64Array.prototype);case"biguint64array":return!(f!==BigUint64Array.prototype);case"typedarray":return e("int8array",r)||e("uint8array",r)||e("uint8clampedarray",r)||e("int16array",r)||e("uint16array",r)||e("int32array",r)||e("uint32array",r)||e("float32array",r)||e("float64array",r)||e("bigint64array",r)||e("biguint64array",r);case"dataview":return!(f!==DataView.prototype);case"arraybuffer":return!(f!==ArrayBuffer.prototype);case"sharedarraybuffer":return"undefined"!=typeof SharedArrayBuffer&&!(f!==SharedArrayBuffer.prototype);case"symbol":return!("symbol"!=typeof r);case"error":return!!(r&&r instanceof Error);case"date":return!!(r&&r instanceof Date);case"regexp":return!!(r&&r instanceof RegExp);case"arguments":return!(!r||"[object Arguments]"!==r.toString());case"null":return null===r;case"undefined":return void 0===r;case"blob":return n&&r instanceof Blob;case"buffer":return!(!a||"function"!=typeof(null===(u=null==r?void 0:r.constructor)||void 0===u?void 0:u.isBuffer)||!r.constructor.isBuffer(r));case"element":if(r)switch(c){case void 0:case"html":case"element":return n&&("object"==typeof HTMLElement?r instanceof HTMLElement:r&&"object"==typeof r&&null!==r&&1===r.nodeType&&"string"==typeof r.nodeName);case"node":return n&&("object"==typeof Node?r instanceof Node:r&&"object"==typeof r&&null!==r&&"number"==typeof r.nodeType&&"string"==typeof r.nodeName);case"react":return r.elementType||r.hasOwnProperty("$$typeof");default:return!1}return!1;case"simple":return e("string",r,s)||e("number",r,s)||e("boolean",r,s)||e("undefined",r,s)||e("null",r,s);case"not-array-object":return!e("array",r,s)&&!e("object",r,s);default:return!1}}}(o,o.exports);var n=r(o.exports);class a{constructor(e,t,r){this.value=e,this.left=t,this.right=r}}class i{constructor(){var e,t,r;r=void 0,(t="root")in(e=this)?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r}static make(e){return(new i).make(e)}static lowestCommonAncestor(e,t,r){let o;const n=r=>{if(!r)return;const i=r.value===(e instanceof a?e.value:e)||r.value===(t instanceof a?t.value:t),u=n(r.left),s=n(r.right);return(i&&u||i&&s||u&&s)&&(o=r),u||s||i};return n(r),o}static maxDepth(e){const t=e=>void 0===e?0:Math.max(1+t(e.left),1+t(e.right));return t(e)}static valid(e){const t=e=>{var r,o;return void 0===e||!((null===(r=e.left)||void 0===r?void 0:r.value)>=e.value)&&(!((null===(o=e.right)||void 0===o?void 0:o.value)<=e.value)&&(t(e.left)&&t(e.right)))};return t(e.root)}static preorder(e,t){void 0!==e&&n("function",t)&&(t(e,e.left,e.right),this.preorder(e.left,t),this.preorder(e.right,t))}static inorder(e,t){void 0!==e&&n("function",t)&&(this.inorder(e.left,t),t(e,e.left,e.right),this.inorder(e.right,t))}static postorder(e,t){void 0!==e&&n("function",t)&&(this.postorder(e.left,t),this.postorder(e.right,t),t(e,e.left,e.right))}static min(e){let t=e;for(;void 0!==(null===(r=t)||void 0===r?void 0:r.left);){var r;t=t.left}return t}static max(e){let t=e;for(;void 0!==(null===(r=t)||void 0===r?void 0:r.right);){var r;t=t.right}return t}array(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"preorder";const t=[];return i[e]&&i[e](this.root,(e=>t.push(e.value))),t}make(e){return n("array",e)&&e.forEach((e=>this.add(e))),this}add(e){const t=e instanceof a?e:new a(e);if(!this.root)return this.root=t,this;let r=this.root;for(;r;){if(t.value===r.value)return this;if(t.value<r.value){if(void 0===r.left)return r.left=t,this;r=r.left}if(t.value>r.value){if(void 0===r.right)return r.right=t,this;r=r.right}}}find(e){if(!this.root)return;let t,r=this.root;for(;r&&!t;)e<r.value?r=r.left:e>r.value?r=r.right:t=r;return t}remove(e){this.root=this.removeNode(this.root,e)}removeNode(e,t){if(void 0!==e){if(t===e.value){if(void 0===e.left&&void 0===e.right)return;if(void 0===e.left)return e.right;if(void 0===e.right)return e.left;const t=i.min(e.right);return e.value=t.value,e.right=this.removeNode(e.right,t.value),e}return t<e.value?(e.left=this.removeNode(e.left,t),e):(e.right=this.removeNode(e.right,t),e)}}}e.AmauiBinaryTree=i,e.AmauiNode=a,Object.defineProperty(e,"__esModule",{value:!0})})); |
37538
716
Updated@amaui/utils@^1.0.11411