# devcontrol-helper ## how does it work? > the best code of devcontrol in one module add it to your `package.json` file ``` 'dependencies':{ ... 'devcontrol-helper':'git+https://git.devcontrol.org/team/helperjs.git#stable-v1' } ``` ## todo: - [x] tests [see reports](https://deploy.cbcode.at/deployserver/team/helperjs/stable-v1/) - [ ] express helper module ## Debug see [npm package debug](https://www.npmjs.com/package/debug) `DEBUG=helper:* node app.js` or to only log 1 lib: `DEBUG=helper:form node app.js` ## what can it do? - lib ``` const player = new Lib('player'); player.setHook('beforeAdd',(x) => {x.name = x.name.toUpperCase();return x;}); let p1 = player.add({name:"Max Muster"}); console.log(player.getById(p1.id)); //{id:uuid,name:'Max Muster'} console.log(player.getArray()) //[p1] player.remove(p1.id); ``` - form > vaitation.validator can be [validator](https://www.npmjs.com/package/validator) string or a boolean function ``` let validation = {name:{type:'text',element:'input',validator:'isLength',options:{max:20,min:10},required:true}} //or let validation = {name:{type:'text',element:'input',convert:(x){return x.toUpperCase()},validator(val){return val.length > 3}} let sample = Form(validation); sample.fill(post,false); if(sample.isValid()){ pug.renderfile('form.pug',sample); }else{ pug.renderfile('success.pug',sample); } //full pug and valitation file will follow soon ``` - math ``` let m = new Math(); let u = m.uuid(); //unique id xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx console.log(m.checkUuid(u)) //true console.log(m.random(0,5)); //int between 0 and 5 console.log(uniqueRandomArray(10,0,30)); //[10 unique values] ``` - config ``` import {config} from 'devcontrol-helper'; console.log(config); //object cointaining of config.default.js, config.js, APP_ENV or import {Config} from 'devcontrol-helper'; const config = new Config(env.PWD,'APP'); //directory, env-prefix ``` config.js and config.default.js can look like this ``` module.exports.development = { title:'hello developer' } module.exports.test = { title:'hello test-world' } module.exports.production = { title:'hello world' } ``` to overwrite an config property on execution: `APP_TITLE="meeeh" npm run start` - debug > see [npm package debug](https://www.npmjs.com/package/debug) - output 1 app: `DEBUG=helper:*` - output all debug: `DEBUG=*:error,*:info,*:debug` - express > express module is awesome, more doku and examples are comming with stable-v2 ``` import * as helper from 'devcontrol-helper'; helper.express.moduleLoader(app, config, passport); ```