Helper Utilities
The helper module provides a comprehensive collection of utility functions for string manipulation, data transformation, validation, and formatting. Located at packages/loopar/core/global/helper.js.
String Manipulation
Capitalize
Capitalizes the first character of a string.
import { Capitalize } from 'loopar';
const result = Capitalize('hello world');
// Output: 'Hello world'
UPPERCASE
Converts a string to uppercase.
import { UPPERCASE } from 'loopar';
const result = UPPERCASE('hello');
// Output: 'HELLO'
The text to convert to uppercase
lowercase
Converts a string to lowercase.
import { lowercase } from 'loopar';
const result = lowercase('HELLO');
// Output: 'hello'
The text to convert to lowercase
camelCase
Converts a string to camelCase format.
import { camelCase } from 'loopar';
const result = camelCase('hello-world');
// Output: 'helloWorld'
const result2 = camelCase('hello_world');
// Output: 'helloWorld'
The string to convert (supports hyphen and underscore separators)
The camelCase formatted string
decamelize
Converts a camelCase string to a delimited format.
import { decamelize } from 'loopar';
const result = decamelize('helloWorld');
// Output: 'hello-world'
const result2 = decamelize('dataForUSACounties', {
separator: '_',
preserveConsecutiveUppercase: true
});
// Output: 'data_for_USA_counties'
The camelCase text to convert
Configuration optionsThe separator character to use
preserveConsecutiveUppercase
Whether to preserve consecutive uppercase letters (e.g., “USA” stays as “USA”)
kebabToPascal
Converts a kebab-case string to PascalCase.
import { kebabToPascal } from 'loopar';
const result = kebabToPascal('hello-world-example');
// Output: 'HelloWorldExample'
The kebab-case string to convert
humanize
Converts a string to a human-readable format.
import { humanize } from 'loopar';
const result = humanize('helloWorld');
// Output: 'Hello world'
const result2 = humanize('user_profile_settings');
// Output: 'User profile settings'
The string to humanize (supports camelCase, snake_case, and kebab-case)
The human-readable string with first letter capitalized
debug_name
Converts a string to a debug-friendly format by replacing spaces and hyphens with underscores.
import { debug_name } from 'loopar';
const result = debug_name('Hello World');
// Output: 'Hello_World'
Hashing and Random Generation
hash
Generates a hash string from input text.
import { hash } from 'loopar';
const result = hash('mystring');
// Output: 'a1b2c3' (base-36 hash)
A base-36 encoded hash string
randomString
Generates a random alphanumeric string.
import { randomString } from 'loopar';
const result = randomString(10);
// Output: 'aB3xY9kL2m' (random 10-character string)
const result2 = randomString();
// Output: random 15-character string (default)
The length of the random string to generate
A random alphanumeric string starting with a letter
Value Validation and Conversion
trueValue
Checks if a value represents a boolean true.
import { trueValue } from 'loopar';
trueValue(true); // true
trueValue('true'); // true
trueValue(1); // true
trueValue('1'); // true
trueValue(false); // false
trueValue('0'); // false
Returns true if value is true, “true”, 1, or “1”
trueToBinary
Converts a truthy value to binary (1 or 0).
import { trueToBinary } from 'loopar';
const result = trueToBinary(true);
// Output: 1
const result2 = trueToBinary(false);
// Output: 0
Returns 1 if truthy, 0 otherwise
binaryValue
Checks if a value represents binary 1.
import { binaryValue } from 'loopar';
binaryValue(1); // true
binaryValue('1'); // true
binaryValue(0); // false
binaryValue('0'); // false
Returns true if value is 1 or “1”
nullValue
Checks if a value is null or undefined.
import { nullValue } from 'loopar';
nullValue(null); // true
nullValue('null'); // true
nullValue(undefined); // true
nullValue('undefined'); // true
nullValue(0); // false
nullValue(''); // false
Returns true if value is null, “null”, undefined, or “undefined”
JSON Utilities
isJSON
Checks if a string is valid JSON.
import { isJSON } from 'loopar';
isJSON('{"name": "test"}'); // true
isJSON('invalid'); // false
Returns true if the string is valid JSON
JSONparse
Safely parses a JSON string.
import { JSONparse } from 'loopar';
const result = JSONparse('{"name": "test"}');
// Output: { name: 'test' }
const result2 = JSONparse('invalid', { default: 'fallback' });
// Output: { default: 'fallback' }
The fallback value if parsing fails (defaults to null)
The parsed JSON object or the fallback value
fixJSON
Fixes common JSON formatting issues with escaped quotes.
import { fixJSON } from 'loopar';
const fixed = fixJSON('{"name": """"value""}');
// Recursively fixes escaped quote issues
Avatar and Display Utilities
avatar
Generates avatar initials from a name.
import { avatar } from 'loopar';
const result = avatar('John Doe');
// Output: 'JD'
const result2 = avatar('Loopar Framework');
// Output: 'LF'
The name to generate initials from
The size parameter (currently unused, reserved for future use)
Up to 2 uppercase initials from the name
avatarLetter
Extracts first letters from each word in a string.
import { avatarLetter } from 'loopar';
const result = avatarLetter('John Doe Smith');
// Output: 'JDS'
The text to extract letters from
Uppercase first letters of each word
Color Utilities
rgba
Converts a hex color to RGBA format.
import { rgba } from 'loopar';
const result = rgba('#ff5733', 0.5);
// Output: 'rgba(255, 87, 51, 0.5)'
const result2 = rgba({ color: '#ff5733', alpha: 0.8 });
// Output: 'rgba(255, 87, 51, 0.8)'
The hex color string (e.g., ‘#ff5733’) or an object with color and alpha properties
The alpha transparency value (0-1)
The RGBA color string or null if invalid
objToRGBA
Converts an RGB object to RGBA string.
import { objToRGBA } from 'loopar';
const result = objToRGBA({ r: 255, g: 87, b: 51, a: 0.5 });
// Output: 'rgba(255, 87, 51, 0.5)'
const result2 = objToRGBA({ r: 255, g: 87, b: 51 });
// Output: 'rgba(255, 87, 51, 1)'
RGB object with r, g, b properties (0-255) and optional a property (0-1)
The RGBA color string or null if invalid
Layout and Style Utilities
aspectRatio
Calculates percentage-based aspect ratio for CSS.
import { aspectRatio } from 'loopar';
const result = aspectRatio('16:9');
// Output: 56.25
const result2 = aspectRatio('4:3');
// Output: 75
The aspect ratio in “width:height” format
The percentage value for padding-bottom CSS trick
renderizableProps
Filters props to only those that can be rendered as HTML attributes.
import { renderizableProps } from 'loopar';
const props = {
className: 'test',
onClick: () => {},
element: 'div',
style: { color: 'red' },
'data-id': '123'
};
const result = renderizableProps(props);
// Output: { className: 'test', style: { color: 'red' }, 'data-id': '123' }
The props object to filter
Filtered props excluding internal properties, event handlers (except children and style), and metadata
Formats a date to a string.
import { formatDate } from 'loopar';
const result = formatDate(new Date());
// Output: '2024-03-15'
const result2 = formatDate(new Date(), 'MM/DD/YYYY');
// Output: '03/15/2024'
format
string
default:"YYYY-MM-DD"
The date format string (dayjs format)
The formatted date string or null if invalid
Formats a date to a time string.
import { formatTime } from 'loopar';
const result = formatTime(new Date());
// Output: '14:30:00'
const result2 = formatTime(new Date(), 'HH:mm');
// Output: '14:30'
The time format string (dayjs format)
The formatted time string or null if invalid
Formats a date to a datetime string.
import { formatDateTime } from 'loopar';
const result = formatDateTime(new Date());
// Output: '2024-03-15 14:30:00'
const result2 = formatDateTime(new Date(), 'MM/DD/YYYY HH:mm');
// Output: '03/15/2024 14:30'
format
string
default:"YYYY-MM-DD HH:mm:ss"
The datetime format string (dayjs format)
The formatted datetime string or null if invalid
Comparison and Array Utilities
compare
Compares two strings ignoring case and separators.
import { compare } from 'loopar';
compare('hello-world', 'Hello World'); // true
compare('user_name', 'User Name'); // true
compare('test', 'different'); // false
Returns true if strings are equal (case-insensitive, ignoring - and _)
getArrayMax
Finds the maximum value of a specific column in an array of objects.
import { getArrayMax } from 'loopar';
const data = [
{ id: 1, score: 85 },
{ id: 2, score: 92 },
{ id: 3, score: 78 }
];
const maxScore = getArrayMax(data, 'score');
// Output: 92
The column name to find the maximum value
The maximum value found, or 0 if array is empty
Data Structure Utilities
fieldList
Flattens a nested field structure into a single array.
import { fieldList } from 'loopar';
const fields = [
{ name: 'field1', elements: [
{ name: 'nested1' },
{ name: 'nested2', elements: [
{ name: 'deep1' }
]}
]},
{ name: 'field2' }
];
const flattened = fieldList(fields);
// Output: [field1, nested1, nested2, deep1, field2]
The fields array or JSON string to flatten
A flattened array of all fields including nested elements
ObjectDeepExtend
Deep merges two objects, with circular reference protection.
import { ObjectDeepExtend } from 'loopar';
const target = { a: 1, b: { c: 2 } };
const source = { b: { d: 3 }, e: 4 };
const result = ObjectDeepExtend(target, source);
// Output: { a: 1, b: { c: 2, d: 3 }, e: 4 }
The target object to extend
The source object to merge from
Internal parameter for tracking visited objects (prevents circular references)
URL and Routing Utilities
toEntityKey
Converts a string to a normalized entity key.
import { toEntityKey } from 'loopar';
const result = toEntityKey('User Profile Settings');
// Output: 'userprofilesettings'
const result2 = toEntityKey('my-entity_name');
// Output: 'myentityname'
Normalized lowercase string with no separators
urlHash
Generates a hash from a route object including query parameters.
import { urlHash } from 'loopar';
const route = {
pathname: '/users/edit',
search: '?name=john&id=123'
};
const hash = urlHash(route);
// Output: unique hash string based on pathname and name parameter
Route object with pathname and search properties
Hash string based on pathname and name query parameter
urlInstance
Generates a hash from a route pathname.
import { urlInstance } from 'loopar';
const route = { pathname: '/users/edit' };
const hash = urlInstance(route);
// Output: unique hash string based on pathname
Route object with pathname property
Hash string based on pathname only
AI Integration Utilities
evaluateAIResponse
Extracts content between delimiters from AI responses.
import { evaluateAIResponse } from 'loopar';
const message = 'Here is the result: [{"data": "value"}] and more text';
const result = evaluateAIResponse(message, '[', ']');
// Output: '[{"data": "value"}]'
const result2 = evaluateAIResponse('No brackets here');
// Output: 'No brackets here'
The ending delimiter (defaults to same as start)
The extracted content between delimiters, or the original message if no delimiters found
Complete Export List
All functions are exported as named exports:
import {
Capitalize,
UPPERCASE,
lowercase,
debug_name,
hash,
trueValue,
trueToBinary,
humanize,
JSONstringify,
JSONparse,
decamelize,
avatar,
randomString,
avatarLetter,
camelCase,
nullValue,
isJSON,
fieldList,
rgba,
aspectRatio,
kebabToPascal,
cookie,
renderizableProps,
binaryValue,
formatDate,
formatTime,
formatDateTime,
compare,
getArrayMax,
objToRGBA,
ObjectDeepExtend,
evaluateAIResponse,
toEntityKey,
fixJSON,
urlHash,
urlInstance
} from 'loopar';