UNPKG

stringzy

Version:

A versatile string manipulation library providing a range of text utilities for JavaScript and Node.js applications.

32 lines (31 loc) 1.79 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const node_test_1 = require("node:test"); const node_assert_1 = __importDefault(require("node:assert")); const truncateText_1 = require("../../transformations/truncateText"); (0, node_test_1.describe)('truncateText', () => { (0, node_test_1.it)('returns the original text if shorter than maxLength', () => { node_assert_1.default.strictEqual((0, truncateText_1.truncateText)('hello', 10), 'hello'); }); (0, node_test_1.it)('truncates and adds suffix if text is longer', () => { node_assert_1.default.strictEqual((0, truncateText_1.truncateText)('hello world', 5), 'he...'); }); (0, node_test_1.it)('truncates and adds custom suffix', () => { node_assert_1.default.strictEqual((0, truncateText_1.truncateText)('abcdef', 5, '--'), 'abc--'); }); (0, node_test_1.it)('returns only suffix if maxLength < suffix.length', () => { node_assert_1.default.strictEqual((0, truncateText_1.truncateText)('abcdef', 2), '...'); }); (0, node_test_1.it)('throws if text is not a string', () => { node_assert_1.default.throws(() => (0, truncateText_1.truncateText)(123, 5), /Input text must be a string/); }); (0, node_test_1.it)('throws if maxLength is negative', () => { node_assert_1.default.throws(() => (0, truncateText_1.truncateText)('abc', -1), /maxLength must be a non-negative number/); }); (0, node_test_1.it)('throws if suffix is not a string', () => { node_assert_1.default.throws(() => (0, truncateText_1.truncateText)('abc', 5, 123), /Suffix must be a string/); }); });