Skip to content

Latest commit

History

5 Commits

Folders and files

NameName
Last commit message
Last commit date

Repository files navigation

QLib

QLib is aimed to help fullstack developers to have a unified interface while developing projects with 2 or more languages involved. With the help of QLib, fullstack developers will no longer be aware of the different method names and argument orders for the "same" function in different languages such as array_slice(arr, start, length) in PHP and Array.prototype.slice(start, end) in Javascript.

Note: This library will involve some overhead of extra function calls or object creations normally. So use it carefully in performace-sensitive places.

Languages and Naming Conventions

PHP

For PHP QLib uses class static methods to provide the set of interfaces. For example, the code using native php function like:

$arr = [1, 2, 3, 4, 5];
$newArr = array_slice($arr, 0, 3);

will be like:

$arr = [1, 2, 3, 4, 5];
$newArr = QArray::slice($arr, 0, 3);

Note that all parameters and return values are php native data types. Some frequently used type mappings are shown in the following table.

PHP native typeQLib corresponding class
stringQString
array(non assoc)QArray
array(assoc)QObject

Note that though in PHP, sequential array and associative array are the same type, they do have much different behaivors. So in QLib they are classified in QArray and QObject respectively. Also, consistent with other languages is another concern.

Javascript

For Javascript QLib use prototype way to provide the interfaces. For each interface, QLib uses a q_ prefix with the interface name to naming the methods. For example, to use slice method in QLib, you may need to write code like:

var slicedArr = [1, 2, 3, 4, 5].q_slice(2, 4);

Interfaces

String

interface signatureinterface outline
size(void):intGet string length
isEmpty(void):boolCheck if empty
trim(option):stringRemove leading or trailing blanks
split(seperator):arraySplit a string into an array
contains(substr, ignoreCase):boolCheck if has the substr
indexOf(substr, direction):intFind the index of the first matched substr
slice(start, end):stringCreate a substring
concat(string):stringAppend another string
splice(start, count, replace):voidInsert/Remove elements at custom index

Array

interface signatureinterface outline
size(void):intGet array element counts
isEmpty(void):boolCheck if empty
contains(element):boolCheck if element is contained in array
indexOf(element, direction):intFind the index of the first match element
slice(start, end):arrayCreate a slice of an array
concat(array):arrayAppend another array
push(element):voidInsert a new element from end
pop(void)Pop up the last element
shift(void)Remove the zero-indexed element
unshift(element):voidInsert a new element at zero-index
splice(start, count, replace):voidInsert/Remove elements at custom index
reverse(void):arrayReturn a reverse ordered array
join(seperator):stringJoin the elements

Assoc Array

interface signatureinterface outline
size(void):intGet element counts
isEmpty(void):boolCheck if empty

Date & Time, Calendar

Regular Expression

About

A cross-platformed unified interface for frequently used components like array, string, date, time, etc

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages