riku
2026-04-02 3282e95db0207ee133d1e98d9771dec9d83b0fc4
miniprogram_npm/tdesign-miniprogram/common/src/flatTool.js
@@ -1,57 +1 @@
export const getPrototypeOf = function (obj) {
    return Object.getPrototypeOf ? Object.getPrototypeOf(obj) : obj.__proto__;
};
export const isObject = function isObject(something) {
    const type = typeof something;
    return something !== null && (type === 'function' || type === 'object');
};
export const iterateInheritedPrototype = function iterateInheritedPrototype(callback, fromCtor, toCtor, includeToCtor = true) {
    let proto = fromCtor.prototype || fromCtor;
    const toProto = toCtor.prototype || toCtor;
    while (proto) {
        if (!includeToCtor && proto === toProto)
            break;
        if (callback(proto) === false)
            break;
        if (proto === toProto)
            break;
        proto = getPrototypeOf(proto);
    }
};
export const toObject = function toObject(something, options = {}) {
    const obj = {};
    if (!isObject(something))
        return obj;
    const excludes = options.excludes || ['constructor'];
    const { enumerable = true, configurable = 0, writable = 0 } = options;
    const defaultDesc = {};
    if (enumerable !== 0)
        defaultDesc.enumerable = enumerable;
    if (configurable !== 0)
        defaultDesc.configurable = configurable;
    if (writable !== 0)
        defaultDesc.writable = writable;
    iterateInheritedPrototype((proto) => {
        Object.getOwnPropertyNames(proto).forEach((key) => {
            if (excludes.indexOf(key) >= 0)
                return;
            if (Object.prototype.hasOwnProperty.call(obj, key))
                return;
            const desc = Object.getOwnPropertyDescriptor(proto, key);
            const fnKeys = ['get', 'set', 'value'];
            fnKeys.forEach((k) => {
                if (typeof desc[k] === 'function') {
                    const oldFn = desc[k];
                    desc[k] = function (...args) {
                        return oldFn.apply(Object.prototype.hasOwnProperty.call(options, 'bindTo') ? options.bindTo : this, args);
                    };
                }
            });
            Object.defineProperty(obj, key, Object.assign(Object.assign({}, desc), defaultDesc));
        });
    }, something, options.till || Object, false);
    return obj;
};
export const isPlainObject = function isPlainObject(something) {
    return Object.prototype.toString.call(something) === '[object Object]';
};
import{isObject}from"../../common/validator";export const getPrototypeOf=function(t){return Object.getPrototypeOf?Object.getPrototypeOf(t):t.__proto__};export const iterateInheritedPrototype=function(t,e,o,r=!0){let n=e.prototype||e;const c=o.prototype||o;for(;n&&(r||n!==c)&&!1!==t(n)&&n!==c;)n=getPrototypeOf(n)};export const toObject=function(t,e={}){const o={};if(!isObject(t))return o;const r=e.excludes||["constructor"],{enumerable:n=!0,configurable:c=0,writable:i=0}=e,p={};return 0!==n&&(p.enumerable=n),0!==c&&(p.configurable=c),0!==i&&(p.writable=i),iterateInheritedPrototype(t=>{Object.getOwnPropertyNames(t).forEach(n=>{if(r.indexOf(n)>=0)return;if(Object.prototype.hasOwnProperty.call(o,n))return;const c=Object.getOwnPropertyDescriptor(t,n);["get","set","value"].forEach(t=>{if("function"==typeof c[t]){const o=c[t];c[t]=function(...t){return o.apply(Object.prototype.hasOwnProperty.call(e,"bindTo")?e.bindTo:this,t)}}}),Object.defineProperty(o,n,Object.assign(Object.assign({},c),p))})},t,e.till||Object,!1),o};