Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions src/functions/string/operations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,19 @@ export function stringLength(str: string | undefined): number | undefined {
}

/**
* Checks if a string is empty (length === 0)
* Checks if a string is empty (null or length === 0)
*/
export function isEmpty(str: string | undefined): boolean | undefined {
export function isEmpty(str: string | null | undefined): boolean | undefined {
if (str === undefined) {
return undefined;
}
if (str === null) {
return true;
}
if (typeof str !== 'string') {
throw new Error('Argument to isEmpty must be a string');
}

return str.length === 0;
}

Expand Down
5 changes: 5 additions & 0 deletions test/functions/functions-string.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ describe('String Functions TypeScript Test', function () {
assert.strictEqual(parser.evaluate('isEmpty("")'), true);
});

it('should return true for null values', function () {
const parser = new Parser();
assert.strictEqual(parser.evaluate('isEmpty(null)'), true);
});

it('should return false for non-empty strings', function () {
const parser = new Parser();
assert.strictEqual(parser.evaluate('isEmpty("hello")'), false);
Expand Down