exam-cc
v3.0.0
Published
Exam console collection
Downloads
23
Readme
exam-cc
EXAM Cheet Commands package for Hungarian 'OKJ' software developer exam
Install (using npm)
npm i exam-cc --save
Usage
const cc = require('exam-cc')
Most important functions
read
read(filename[,col_sep,elines,header_arr,bof,row_sep,char_set])
Read data (comma separated values) from text files (.csv or .txt) into an array of objects
var ot = cc.read('input.txt',';',1,['id','property','value'])
Return value: exam-cc Array
Parameters
- filename | String
- Path to location and filename
- col_sep | String | optional
- Column (attribute) separator
- usually in a csv file it is ',' or ';'
- in txt file it is ' ' (space) or ('\t') tabulator
- Column (attribute) separator
- elines | Number | optional
- Empty (or cuttable) rows on end of file
- header_arr | Array | optional
- Custom header/attribute names
- if the file not contain, is needed
- Custom header/attribute names
- bof | Number | optional
- Empty rows on begin of file
- row_sep | String | optional
- Row (line-end, record) separator
- in windows file is '\r\n'
- in linux file is '\n'
- default value is '\n'
- Row (line-end, record) separator
- char_set | String | optional
- default value is 'UTF-8'
write
write( filename, content [, sep1, sep2] )
Wrte array of objects into a comma separated text file
var ot = cc.write('input.txt', content, '\r\n', ',')
Parameters (write)
- filename | String
- Path to location and filename.
- content | Array of Objects
- sep1 | String | optional
- Row (line-end, record) separator.
- in windows file is '\r\n'
- in linux file is '\n'
- default value is '\n'
- Row (line-end, record) separator.
- sep2 | String | optional
- Column (attribute) separator.
- n csv file is ',' or ';'
- in txt file is ' ' (space) or ('\t') tabulator
- Column (attribute) separator.
- custom header/attribute names - under construction
initsql
initsql(db,content,tablename,host,user,pwd)
Initialise MySQL, create a MySQL table and insert all element of object array to the MySQL table
cc.initsql('mydb',array_of_objects,'test_table')
...
cc.sql.end()
or if table aredy exists:
cc.initsql('mydb')
...
cc.sql.end()
Parameters (initsql)
- db | String
- Database name
- default value is 'vizsga'
- content | Array of Objects
- tablename | String
- Name of the data table in MySQL
- default value is 'default'
- host | String
- MySQL Host URL
- default value is 'localhost'
- user | String
- MySQL Username
- default value is 'root'
- pwd | String
- MySQL password
- default value is '' (empty String)
query
query(sql)
Run SQL Query and return an array of objects from results
let answ = cc.query('SELECT * FROM teszt')[0].szerzo
Parameter (query)
- query | String
- The Query string in MySQL language
input
input(text)
Get an input from console to a value
name=cc.input('Tell a name!')
print( value <or a list of value> )
cc.print("I found:",cc.find(t,'Name',name).age)
Array
let ta=new cc.Array({a:1, b:3},{a:2, b:2},{a:4, b:3})
let m=ta.toMap('a')
console.log(m)
Map
let t1 = [
{id: 1, name:'cica', lsz: 4},
{id: 2, name:'cirmoscica', lsz: 3},
{id: 4, name:'kisvakond', lsz: 4}
]
const m=new cc.Map(t1,'id')
console.log( m.toArray('cica') )
const cc=require('exam-cc')
let t1 = new cc.Map([{a:1, b:3},{a:2, b:2},{a:4, b:3}],'a')
let t2 = new cc.Map([{a:1, c:2},{a:2, c:4},{a:3, c:1}],'a')
console.log(t1.union(t2))
const cc=require('exam-cc')
let t1 = new cc.Map([{a:1, b:3},{a:2, b:2},{a:4, b:3}],'a')
let t2 = new cc.Map([{a:1, b:2},{a:2, b:4},{a:3, b:1}],'a')
console.log( t1.union( t2, ( a, b ) => a + b ) )
Examples
cc = require('exam-cc')
t = cc.read('users.txt')
console.log(cc.sort(t,'Name'))
betu=cc.input('Tell a name!')
cc.print("I found:",cc.find(t,'Name',name).age)
const cc = require('exam-cc')
const text = cc.read('input.txt',';',1,['name','age'])
cc.initsql('exam',text,'test')
const name = cc.input('Please give a name!')
cc.print( cc.query(`
SELECT *
FROM test
WHERE name like '%${name}%'
ORDER BY age
`)
.map( v => v.name + ': '+ v.age)
.join( cc.EOL )
)
cc.sql
.end()
Colors in console (console.log)
(cyan, red, white, green, blue, light, black, yellow)
const cc = require('exam-cc')
console.log(cc.yellow,'Sárga')
Other functions
find( array, attribute, condition )
Parameters (find)
- array | Array of Objects
- attribute | String
- condition | String
- exact | Boolean
filter( array, attribute, condition )
Parameters (filter)
- array | Array of Objects
- attribute | String
- condition | String
- exact | Boolean
sort( array, attribute )
sorting
Parameters (sort)
- array | Array of Objects
- attribute | String
rsort( array, attribute )
reverse sorting
Parameters (rsort)
- array | Array of Objects
- attribute | String
max( array, attribute )
find minimum value
Parameters (max)
- array | Array of Objects
- attribute | String
min( array, attribute )
find maximum value
Parameters (min)
- array | Array of Objects
- attribute | String