UNPKG

ez-string-toolkit

Version:

A simple and easy-to-use string utility library with essential string manipulation functions

44 lines (35 loc) โ€ข 2.21 kB
/** * Simple tests for string utils library */ const stringUtils = require('./index.js'); // Test helper function function assert(condition, message) { if (!condition) { console.error('โŒ FAIL:', message); process.exit(1); } console.log('โœ… PASS:', message); } console.log('๐Ÿงช Running tests for ez-string-toolkit...\n'); // Test capitalize function assert(stringUtils.capitalize('hello') === 'Hello', 'capitalize("hello") should return "Hello"'); assert(stringUtils.capitalize('WORLD') === 'World', 'capitalize("WORLD") should return "World"'); assert(stringUtils.capitalize('') === '', 'capitalize("") should return ""'); // Test toCamelCase function assert(stringUtils.toCamelCase('hello world') === 'helloWorld', 'toCamelCase("hello world") should return "helloWorld"'); assert(stringUtils.toCamelCase('foo-bar-baz') === 'fooBarBaz', 'toCamelCase("foo-bar-baz") should return "fooBarBaz"'); assert(stringUtils.toCamelCase('test_case') === 'testCase', 'toCamelCase("test_case") should return "testCase"'); // Test reverse function assert(stringUtils.reverse('hello') === 'olleh', 'reverse("hello") should return "olleh"'); assert(stringUtils.reverse('abc') === 'cba', 'reverse("abc") should return "cba"'); assert(stringUtils.reverse('') === '', 'reverse("") should return ""'); // Test wordCount function assert(stringUtils.wordCount('hello world') === 2, 'wordCount("hello world") should return 2'); assert(stringUtils.wordCount('one two three four') === 4, 'wordCount("one two three four") should return 4'); assert(stringUtils.wordCount(' single ') === 1, 'wordCount(" single ") should return 1'); assert(stringUtils.wordCount('') === 0, 'wordCount("") should return 0'); // Test truncate function assert(stringUtils.truncate('hello world', 5) === 'he...', 'truncate("hello world", 5) should return "he..."'); assert(stringUtils.truncate('short', 10) === 'short', 'truncate("short", 10) should return "short"'); assert(stringUtils.truncate('hello world', 8, '>>') === 'hello >>', 'truncate("hello world", 8, ">>") should return "hello >>"'); console.log('\n๐ŸŽ‰ All tests passed! EZ String Toolkit is working correctly.');