"use strict";
/*
 * edge.js
 *
 * (c) Harminder Virk <virk@adonisjs.com>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.GLOBALS = void 0;
const edge_error_1 = require("edge-error");
const js_stringify_1 = __importDefault(require("js-stringify"));
const helpers_1 = require("@poppinss/utils/build/helpers");
const Template_1 = require("../../Template");
exports.GLOBALS = {
    /**
     * Converts new lines to break
     */
    nl2br: (value) => {
        if (!value) {
            return;
        }
        return String(value).replace(/([^>\r\n]?)(\r\n|\n\r|\r|\n)/g, '$1<br>');
    },
    /**
     * Inspect state
     */
    inspect: (value) => {
        return (0, Template_1.safeValue)(require('@poppinss/inspect').string.html(value));
    },
    /**
     * Truncate a sentence
     */
    truncate: (value, length = 20, options) => {
        options = options || {};
        return helpers_1.string.truncate(value, length, {
            completeWords: options.completeWords !== undefined ? options.completeWords : !options.strict,
            suffix: options.suffix,
        });
    },
    /**
     * Raise an exception
     */
    raise: (message, options) => {
        if (!options) {
            throw new Error(message);
        }
        else {
            throw new edge_error_1.EdgeError(message, 'E_RUNTIME_EXCEPTION', options);
        }
    },
    /**
     * Generate an excerpt
     */
    excerpt: (value, length = 20, options) => {
        options = options || {};
        return helpers_1.string.excerpt(value, length, {
            completeWords: options.completeWords !== undefined ? options.completeWords : !options.strict,
            suffix: options.suffix,
        });
    },
    /**
     * Using `"e"` because, `escape` is a global function in the
     * Node.js global namespace and edge parser gives priority
     * to it
     */
    e: Template_1.escape,
    /**
     * Convert javascript data structures to a string. The method is a little
     * better over JSON.stringify in handling certain data structures. For
     * example: In JSON.stringify, the date is converted to an ISO string
     * whereas this method converts it to an actual instance of date
     */
    stringify: js_stringify_1.default,
    safe: Template_1.safeValue,
    camelCase: helpers_1.string.camelCase,
    snakeCase: helpers_1.string.snakeCase,
    dashCase: helpers_1.string.dashCase,
    pascalCase: helpers_1.string.pascalCase,
    capitalCase: helpers_1.string.capitalCase,
    sentenceCase: helpers_1.string.sentenceCase,
    dotCase: helpers_1.string.dotCase,
    noCase: helpers_1.string.noCase,
    titleCase: helpers_1.string.titleCase,
    pluralize: helpers_1.string.pluralize,
    toSentence: helpers_1.string.toSentence,
    prettyBytes: helpers_1.string.prettyBytes,
    toBytes: helpers_1.string.toBytes,
    prettyMs: helpers_1.string.prettyMs,
    toMs: helpers_1.string.toMs,
    ordinalize: helpers_1.string.ordinalize,
};
