npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

vanilla-website-utils

v1.8.5

Published

Vanilla JS utility functions for daily website usage

Downloads

258

Readme

Vanilla-website-utils

Vanilla JS utility functions for daily website usage

Feeback

If you are using or are interested in this module, please send me some Feedback. Any comment, request or critic is welcome! [email protected]

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

GPL licenses A module for Vanilla-website-utils

module.exports#csv_file_to_array(file) ⇒ array

Kind: Exported function
Returns: array - - the collected data from the csv file into an array

| Param | Type | Description | | --- | --- | --- | | file | object | file object from a HTML website |

Example

var vwu = new Vanilla_website_utils();
document.querySelector("#input").addEventListener("change", function(){
let arr = vwu.file_to_array(this.files[0]);
},false)

module.exports#clear_textarea() ⏏

Kind: Exported function
Example

var vwu = new Vanilla_website_utils();
vwu.clear_textarea()

module.exports#sort_object(obj, sort_order) ⇒ array

Kind: Exported function

| Param | Type | Default | Description | | --- | --- | --- | --- | | obj | object | | javascript object | | sort_order | string | "desc" | desc or asc (default desc) |

Example

var vwu = new Vanilla_website_utils();
let obj = {a:100,b:50,c:75,d:1};
let a = vwu.sort_object('desc'); 

module.exports#date_to_112(_date) ⇒ string

Kind: Exported function
Returns: string - - in 112 format like 20230515

| Param | Type | Description | | --- | --- | --- | | _date | object | dateobject |

Example

var vwu = new Vanilla_website_utils();
let date = new Date();
let iso_112 = vwu.date_to_112(date); 

module.exports#month_list(month_back, revert, format) ⇒ arry

Kind: Exported function
Returns: arry - - list of month in format like 10.2022

| Param | Type | Default | Description | | --- | --- | --- | --- | | month_back | int | 12 | number of month back | | revert | bolean | false | revert order - Default is false | | format | string | "`${j}.${i}`" | return format of the month year pair - Default {j}.{i} like 09.2022 | j = month | i =year | |

Example

var vwu = new Vanilla_website_utils();
let data = await vwu.month_list(60,true,"`${j}.${i}`");

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);

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([email protected])

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([email protected])

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
       search: inline
     });

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, selected, copy2clipboard, log) ⏏

Kind: Exported function

| Param | Type | Default | Description | | --- | --- | --- | --- | | select_obj | object | | DOM object | | data | object | | data array | | selected | string | | 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#pad(number) ⇒ string

Kind: Exported function
Returns: string - - data array

| Param | Type | Description | | --- | --- | --- | | number | int | number |

Example

var vwu = new Vanilla_website_utils();
 let x = vwu.pad(5);

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']);