import util from 'node:util';
import { platform } from "./platform.js";
import { to_method_property_descriptors } from "./prototype.common.js";
export * from "./prototype.common.js";
if (!globalThis.my_prototype_defined) {
    Object.defineProperties(String.prototype, {
        ...to_method_property_descriptors({
            quote_if_space(type = 'single') {
                return this.includes(' ') ? this.quote(type) : this;
            },
            trim_doc_comment() {
                return `/** ${this.slice(3, -2).replace(/\s*\*\s*/g, '  ').replace(/@(param|params|return) \{.*?\}\s*/g, '').trim()} */`;
            },
            to_base64() {
                return Buffer.from(this).toString('base64');
            },
            decode_base64(buffer = false) {
                const buf = Buffer.from(this, 'base64');
                if (buffer)
                    return buf;
                return buf.toString();
            },
            strip_ansi() {
                return platform.strip_ansi(this);
            },
            to_backslash() {
                return this.replaceAll('/', '\\');
            }
        }),
        // ------------ colors
        ...Object.fromEntries([
            'red', 'green', 'yellow', 'blue', 'magenta', 'cyan', 'grey',
            'red_', 'green_', 'yellow_', 'blue_', 'magenta_', 'cyan_',
            'underline',
        ].map(color => {
            const style = color.endsWith('_') ? `${color.slice(0, -1)}Bright` : color;
            return [color, {
                    configurable: true,
                    ...util.styleText ? {
                        get() {
                            return util.styleText(style, this, { validateStream: false });
                        }
                    } : {
                        get() {
                            return this;
                        }
                    }
                }];
        }))
    });
    Object.defineProperties(Array.prototype, to_method_property_descriptors({
        log(limit = 10000) {
            const text = this.join('\n') + '\n';
            if (limit === -1 || this.length <= limit)
                console.log(text);
            else if (limit > 0)
                console.log(text.slice(0, limit) + '\n...'.blue);
            else
                console.log('...\n'.blue + text.slice(limit));
        },
        trim_license() {
            const i = this.indexOf('/*');
            const j = this.indexOf('*/');
            if (i === 0 && this[i + 1].includes('License'))
                return this.slice(j + 1);
            else
                return this;
        },
        split_indents() {
            return this.map(line => line.split_indent());
        },
        indent2to4() {
            return this.split_indents()
                .map(line => ' '.repeat(line.indent * 2) + line.text);
        }
    }));
}
//# sourceMappingURL=prototype.js.map