Prevent blank playlist names
This commit is contained in:
@@ -1,6 +1,24 @@
|
||||
import { describe, expect, it } from 'vitest';
|
||||
|
||||
import { toBoolean, toFloat } from './string';
|
||||
import { isBlank, toBoolean, toFloat } from './string';
|
||||
|
||||
describe('isBlank', () => {
|
||||
it('Should return true if the string is blank', () => {
|
||||
let check = isBlank(undefined);
|
||||
expect(check).toBe(true);
|
||||
check = isBlank(null);
|
||||
expect(check).toBe(true);
|
||||
check = isBlank('');
|
||||
expect(check).toBe(true);
|
||||
check = isBlank(' \t\t ');
|
||||
expect(check).toBe(true);
|
||||
});
|
||||
|
||||
it('Should return false if the string is not blank', () => {
|
||||
const check = isBlank('not an empty string');
|
||||
expect(check).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe('toBoolean', () => {
|
||||
it('Should return the boolean represented by the string', () => {
|
||||
|
||||
@@ -1,3 +1,12 @@
|
||||
/**
|
||||
* Checks if a string is empty or contains only whitespace.
|
||||
* @param {string} value The string to test.
|
||||
* @returns {boolean} True if the string is blank.
|
||||
*/
|
||||
export function isBlank(value: string | undefined | null) {
|
||||
return !value?.trim().length;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the value of a string as boolean.
|
||||
* @param {string} name The value as a string.
|
||||
|
||||
Reference in New Issue
Block a user