kodekita
v1.0.16
Published
javascript reusable code collection
Downloads
1
Readme
kodekita
Kodekita is a collection of javascript code that can be reused without rewriting the code.
Daftar Isi
Installation
npm install --save kodekita
Usage
import React, { Component } from "react";
import { initGlobalTools } from "kodekita";
initGlobalTools({ devLog: true, devStatus: true });
class App extends Component {
componentDidMount( ) {
/** same as console.log, but the logs will not be displayed after the production / npm run build */
window.devLog( `Dev Status: ${ window.devStatus }` );
}
render( ) {
return (
<div>
<h1>Hello Joko!</h1>
<p>Happy Hacking! :)</p>
</div>
);
}
}
export default App;
API
initGlobalTools
initGlobalTools( object:config )
will initiate a global variable or function that can be accessed freely without importing
import { initGlobalTools } from "kodekita";
// call on the root component index.js
initGlobalTools({ devStatus: true, devLog: true });
console.log( window.devStatus ); // return true if it is under development
window.devLog( 'this message will not appear after production!' ); //can be used to view logs only during development
Name | Description | Type | Config
--------|---------- | ----|------
window.devLog( all:log )
| same as console.log
, but the logs will not be displayed after the production
/ npm run build
| function | devLog
: true
window.devStatus
| Global boolean variable that contains true
if running under development
| boolean | devStatus
: true
window.localhostStatus
| Global boolean variable that contains true
if running under localhost
| boolean|localhostStatus
: true
*variables and functions are not needed
| Configuring to disable React Developer Tools extension. This feature is only needed if the browser uses the React Developer Tools extension |boolean|disableReactDevTools
: true
promiseAll
promiseAll( list:functions )
will execute multiple functions asynchronously
import { promiseAll } from "kodekita";
function showLog( ) {
console.log( 'Im here!' );
}
promiseAll([ showLog, showLog, showLog ]);
isJsonString
isJsonString( string:jsonString )
will check and return true if string is a stringified JSON
import { isJsonString } from "kodekita";
const stringifiedJson = '{name:"Joko",gender:"male",city:"Bekasi"}';
isJsonString( stringifiedJson ); //true
idrCurrencyFormatter
idrCurrencyFormatter( number:currency )
will format integer into IDR currency format
import { idrCurrencyFormatter } from "kodekita";
idrCurrencyFormatter( 64000 ); //Rp 64000
idrCurrencyParser
idrCurrencyParser( string:currency )
will parse IDR currency into integer
import { idrCurrencyParser } from "kodekita";
idrCurrencyParser( 'Rp 64000' ); //64000
greeterText
greeterText( string:name )
will display greeter with name
import { greeterText } from "kodekita";
greeterText( 'Joko' );
setSession
setSession( string:header, string:value)
stores data to Session Storage.
import { setSession } from "kodekita";
setSession( 'name', 'Joko' );
getSession
getSession( string:header )
get data from Session Storage.
import { getSession } from "kodekita";
getSession( 'name' );
deleteSession
deleteSession( string:header )
delete data from Session Storage.
import { deleteSession } from "kodekita";
deleteSession( 'name' );
clearSession
clearSession()
clear all data from Session Storage.
import { clearSession } from "kodekita";
clearSession( );