vanilla-website-utils

Vanilla-website-utils

Vanilla JS utility functions for daily website usage

Install

  npm install vanilla-website-utils

Usage:

  <script src="../node_modules/vanilla-website-utils/dist/vanilla-website-utils.js"></script>

Example Usage:

  var vu = new Vanilla_website_utils();
  window.onload = async function()
  {
	const host = await vu.get_host();
	const v = await vu.get_parameters();
	console.log(host);
	console.log(v);
  };
   	

Functions:

    <form>
      <input  id="test" class="test" />
    </form>
   await vwu.autoload_textfield("http://127.0.0.1:8051/book_authors_name?f=data&_max=100",'test','test')

Repro:

https://calantas.org/vanilla-website-utils

Vanilla-website-utils

A module for Vanilla-website-utils

module.exports#get_host(ext) ⇒ string

Kind: Exported function
Returns: string - - the hostname

Param Type Default Description
ext string "html" extentison

Example

var vwu = new Vanilla_website_utils();
let host = await vwu.get_host();

module.exports#get_parameters(url) ⇒ object

Kind: Exported function
Returns: object - json pair key/value

Param Type Description
url string url

Example

var vwu = new Vanilla_website_utils();
let v = await vwu.get_parameters();

module.exports#get_select_text_by_value(select, value) ⇒ string

Kind: Exported function
Returns: string - text

Param Type Description
select object the DOM select object
value string value

Example

var vwu = new Vanilla_website_utils();
let mytext = await vwu.get_select_text_by_value(document.querySelector("#resource"), v['resource'],v['resource']);

module.exports#add_parameters(url, parameters) ⇒ string

Kind: Exported function
Returns: string - url plus the new parameters

Param Type Description
url string original url
parameters string json like {'foo':'bar'}

Example

var vwu = new Vanilla_website_utils();
filter = {"foo":"bar"};
url = await vwu.add_parameters(url, filter);

module.exports#aget_api(url) ⇒ object

Kind: Exported function
Returns: object - json

Param Type Description
url string api url

Example

var vwu = new Vanilla_website_utils();
let res = await vwu.aget_api(url, data);

module.exports#aput_api(url, data, content_type) ⇒ object

Kind: Exported function
Returns: object - json

Param Type Default Description
url string api url
data object data
content_type string "application/json" content type of the sending data optional - default is "application/json"

Example

let data = {"foo":"bar"}
var vwu = new Vanilla_website_utils();
let res = await vwu.apost_api(url, data, "application/json");

module.exports#apost_api(url, data, content_type) ⇒ object

Kind: Exported function
Returns: object - json

Param Type Default Description
url string api url
data object data
content_type string "application/json" content type of the sending data optional - default is "application/json"

Example

var vwu = new Vanilla_website_utils();
let res = await vwu.apost_api(url, data, "application/json");

module.exports#post_api(url, my_callback, _data) ⇒ object

Kind: Exported function
Returns: object - json

Param Type Description
url string api url
object data
my_callback string name of the callback function
_data string content type of the sending data optional - default is "application/json"

Example

var vwu = new Vanilla_website_utils();
let data = {"foo":"bar"}
let ret = vwu.post_api('http://foo.bar/api','myfuncion','application/json') 

module.exports#_email_validator(email) ⇒ bolan

Kind: Exported function
Returns: bolan - true if ok and false if bad email

Param Type Description
email string email

Example

var vwu = new Vanilla_website_utils();
const ok = vwu._email_validator(foo@bar.com)

module.exports#email_validator(email) ⇒ bolan

Kind: Exported function
Returns: bolan - true if ok and false if bad email

Param Type Description
email string email

Example

var vwu = new Vanilla_website_utils();
const ok = await vwu._email_validator(foo@bar.com)

module.exports#get_url_parameter(name) ⇒ string

Kind: Exported function
Returns: string - url parameter

Param Type Description
name string key of the url parameter

Example

var vwu = new Vanilla_website_utils();
const from = await vwu.get_url_parameter('from')

module.exports#get_site() ⇒ string

Kind: Exported function
Returns: string - sitename
Example

var vwu = new Vanilla_website_utils();
let site = vwu.get_site

module.exports#autocomplete_textfield(setting) ⏏

Kind: Exported function

Param Type Description
setting object see example

Example

var vwu = new Vanilla_website_utils();
 await vwu.autocomplete_textfield({
     url: api + '/code/name',
       onetimeload: true,
       dom_id: 'search',
       name: 'search',
       append_to: '#nav-search',
       min_key_length: 2
     });

module.exports#_set_textfield() ⏏

Kind: Exported function

module.exports#autoload_textfield() ⏏

Kind: Exported function

module.exports#autocomplete() ⏏

Kind: Exported function

module.exports#get_form_data(form) ⇒ array

Kind: Exported function
Returns: array - in key/value

Param Type Description
form object form object

Example

var vwu = new Vanilla_website_utils();
let data = JSON.stringify(await vwu.get_form_data(form));

module.exports#s_fill_select(select_obj, data) ⏏

Kind: Exported function

Param Type Description
select_obj object DOM object
data object data array

Example

var vwu = new Vanilla_website_utils();
 let extra_sel = document.querySelector("#extra");
 await vwu.fill_select(extra_sel, data);

module.exports#fill_select(select_obj, data, style, copy2clipboard, log) ⏏

Kind: Exported function

Param Type Default Description
select_obj object DOM object
data object data array
style string style for the select element
copy2clipboard boolean false copy2clipboard true or false
log object false log object - experimental

Example

var vwu = new Vanilla_website_utils();
const url = api + '/fields?table=av0_style&db=sl&server=232&f=list';
const data = JSON.parse(await aget_api(url));
let extra_sel = document.querySelector("#extra");
await vwu.fill_select(extra_sel, data);
await vwu.fill_select(sel,all_tags,'height: 500px; width: 230px;font-size: 9px',true, log);

module.exports#s_set_selected(select_obj, data) ⏏

Kind: Exported function

Param Type Description
select_obj object DOM object
data object data array

Example

var vwu = new Vanilla_website_utils();
 let extra_sel = document.querySelector("#extra");
 await vwu.fill_select(extra_sel, data);

module.exports#set_selected() ⏏

Kind: Exported function
Example

var vwu = new Vanilla_website_utils(); 
let select = document.querySelector("#bom");
await vwu.set_selected(select,v['bom']);