ThirdCorner / generator-scaffi

Generator for the scaffi framework
0 stars 1 forks source link

Add filters generator #15

Open jblaketc opened 8 years ago

jblaketc commented 8 years ago
'use strict';

import {Filter} from 'scaffi-ui-core'; // jshint unused: false;
class Decamelize {
    //start-non-standard
    @Filter({
        filterName: 'decamelize'
    })
    //end-non-standard
    static decamelizeFilter() {
        return (str, sep) => {
            if (typeof str !== 'string') {
                throw new TypeError('Expected a string');
            }
            return str.replace(/([a-z\d])([A-Z])/g, '$1' + (sep || ' ') + '$2');
        };
    }
}

export default Decamelize;