3.0.0 • Published 5 years ago

exam-cc v3.0.0

Weekly downloads
-
License
MIT
Repository
-
Last release
5 years ago

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
  1. filename | String
    • Path to location and filename
  2. col_sep | String | optional
    • Column (attribute) separator
      • usually in a csv file it is ',' or ';'
      • in txt file it is ' ' (space) or ('\t') tabulator
  3. elines | Number | optional
    • Empty (or cuttable) rows on end of file
  4. header_arr | Array | optional
    • Custom header/attribute names
      • if the file not contain, is needed
  5. bof | Number | optional
    • Empty rows on begin of file
  6. row_sep | String | optional
    • Row (line-end, record) separator
      • in windows file is '\r\n'
      • in linux file is '\n'
      • default value is '\n'
  7. 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)
  1. filename | String
    • Path to location and filename.
  2. content | Array of Objects
  3. sep1 | String | optional
    • Row (line-end, record) separator.
      • in windows file is '\r\n'
      • in linux file is '\n'
      • default value is '\n'
  4. sep2 | String | optional
    • Column (attribute) separator.
      • n csv file is ',' or ';'
      • in txt file is ' ' (space) or ('\t') tabulator
  5. 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)
  1. db | String
    • Database name
    • default value is 'vizsga'
  2. content | Array of Objects
  3. tablename | String
    • Name of the data table in MySQL
    • default value is 'default'
  4. host | String
    • MySQL Host URL
    • default value is 'localhost'
  5. user | String
    • MySQL Username
    • default value is 'root'
  6. 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)
  1. 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)
  1. array | Array of Objects
  2. attribute | String
  3. condition | String
  4. exact | Boolean

filter( array, attribute, condition )

Parameters (filter)
  1. array | Array of Objects
  2. attribute | String
  3. condition | String
  4. exact | Boolean

sort( array, attribute )

sorting

Parameters (sort)
  1. array | Array of Objects
  2. attribute | String

rsort( array, attribute )

reverse sorting

Parameters (rsort)
  1. array | Array of Objects
  2. attribute | String

max( array, attribute )

find minimum value

Parameters (max)
  1. array | Array of Objects
  2. attribute | String

min( array, attribute )

find maximum value

Parameters (min)
  1. array | Array of Objects
  2. attribute | String
3.0.0

5 years ago

2.0.12

5 years ago

2.0.11

5 years ago

2.0.10

5 years ago

2.0.9

5 years ago

2.0.8

5 years ago

2.0.7

5 years ago

2.0.6

5 years ago

2.0.5

5 years ago

2.0.4

5 years ago

2.0.3

5 years ago

2.0.2

5 years ago

2.0.1

5 years ago

2.0.0

5 years ago

1.6.10

5 years ago

1.6.9

5 years ago

1.6.8

5 years ago

1.6.7

5 years ago

1.6.6

5 years ago

1.6.5

5 years ago

1.6.4

5 years ago

1.6.3

5 years ago

1.6.2

5 years ago

1.6.1

5 years ago

1.6.0

5 years ago

1.5.2

5 years ago

1.5.1

5 years ago

1.5.0

5 years ago

1.4.7

5 years ago

1.4.6

5 years ago

1.4.5

5 years ago

1.4.4

5 years ago

1.4.3

5 years ago

1.4.2

5 years ago

1.4.1

5 years ago

1.4.0

5 years ago

1.3.14

5 years ago

1.3.13

6 years ago

1.3.12

6 years ago

1.3.11

6 years ago

1.3.10

6 years ago

1.3.9

6 years ago

1.3.8

6 years ago

1.3.7

6 years ago

1.3.6

6 years ago

1.3.5

6 years ago

1.3.4

6 years ago

1.3.3

6 years ago

1.3.2

6 years ago

1.3.1

6 years ago

1.3.0

6 years ago

1.2.11

6 years ago

1.2.10

6 years ago

1.2.9

6 years ago

1.2.8

6 years ago

1.2.7

6 years ago

1.2.6

6 years ago

1.2.5

6 years ago

1.2.4

6 years ago

1.2.3

6 years ago

1.2.2

6 years ago

1.2.1

6 years ago

1.2.0

6 years ago

1.1.18

6 years ago

1.1.17

6 years ago

1.1.16

6 years ago

1.1.15

6 years ago

1.1.14

6 years ago

1.1.13

6 years ago

1.1.12

6 years ago

1.1.11

6 years ago

1.1.10

6 years ago

1.1.9

6 years ago

1.1.8

6 years ago

1.1.7

6 years ago

1.1.6

6 years ago

1.1.5

6 years ago

1.1.4

6 years ago

1.1.3

6 years ago

1.1.2

6 years ago

1.1.1

6 years ago

1.1.0

6 years ago

1.0.19

6 years ago

1.0.18

6 years ago

1.0.17

6 years ago

1.0.16

6 years ago

1.0.15

6 years ago

1.0.14

6 years ago

1.0.13

6 years ago

1.0.12

6 years ago

1.0.11

6 years ago

1.0.10

6 years ago

1.0.9

6 years ago

1.0.8

6 years ago

1.0.7

6 years ago

1.0.6

6 years ago

1.0.5

6 years ago

1.0.4

6 years ago

1.0.3

6 years ago

1.0.2

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago