All files / src/utils/Formatters PlaceholderFormatter.js

58.82% Statements 10/17
68.42% Branches 13/19
66.66% Functions 2/3
58.82% Lines 10/17

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37        7x 7x 7x       16246x   16246x   16246x   16246x 295x   15951x                           7x      
import Formatter from './Formatter';
 
export class PlaceholderFormatter extends Formatter {
    constructor(placeholder = '-') {
        super();
        this.reversible = false;
        this.placeholder = placeholder;
    }
 
    format(value, placeholder) {
        placeholder = placeholder || this.placeholder;
 
        Iif (typeof value === 'object' || Array.isArray(value))
            return this.placeholder;
        else Iif (typeof value === 'number' && isNaN(value))
            return this.placeholder;
        else if (value === '' || value === undefined)
            return this.placeholder;
        else
            return value;
    }
 
    parse(value, placeholder) {
        placeholder = placeholder || this.placeholder;
        console.warn('[cloud-ui]', 'Parsed value may not be correct because PlaceholderFormatter is not reversible.');
 
        if (value === this.placeholder)
            return '';
        else
            return value;
    }
}
 
export const placeholderFormatter = new PlaceholderFormatter();
 
export default PlaceholderFormatter;