bem2ng
Version:
Create Angular 2 component from BEM blocks
56 lines (41 loc) • 1.07 kB
JavaScript
import fs from 'fs';
import util from 'util';
import process from 'child_process';
import chalk from 'chalk';
const capitalize = (str) => {
var first = str.slice(0, 1);
return first.toUpperCase() + str.slice(1);
};
const repeatArg = (arg, repeatCount) => {
const list = (arg + '%s').repeat(repeatCount).split('%s');
list.pop();
return list.filter(value => {
return value !== '%s';
});
};
const locale = (() => {
const args = [];
const options = { encoding: 'utf8' };
const command = process.spawnSync('locale', args, options);
if (command.error) {
return { LANG: 'en' };
}
const locale = command.stdout.split('\n').shift().split('=');
return { [locale.shift()]: locale.shift().slice(0, 2) };
})();
const readDIR = (dir) => {
const langs = [];
const names = fs.readdirSync(dir);
names.forEach(name => {
langs.push(name.slice(0, -3));
});
return langs;
};
Object.assign(util, {
chalk,
locale,
capitalize,
repeatArg,
readDIR,
});
export { util };