1.1.5 • Published 4 years ago

api_counter v1.1.5

Weekly downloads
3
License
ISC
Repository
github
Last release
4 years ago

API Counter

Count the request you make. This npm package is nothing more than a counter.
This package was created out of restrictions on certain free API's limiting 50 request per day.

forthebadge forthebadge

Goals

  • Count the the number of request and store (cache) in browser.
  • Add function to list all counters and Localstrorge keys
  • Convert counter from simple string to json (json)
  • Log the number of request per day (json)
  • Warn the developer if they are about to reach their limit
  • Warn the developer if they have reached their limit
  • Notify the developer that they have 1 request left
  • Notify the developer that they have gone over there request
  • The ability to reset a counter
  • The ability to remove or reset one counter with out localStorage.clear()
    • restCounter('counterAPI','soft') soft to reset to 0 or hard to erase counter
  • Return the object if requested
    • getCLS = (cn = 'mainCounter', 1) giveback = 1: Return Object or 0: Update CLS (0 is default)
  • The ability to choice how to receive alert by console.log, alert or return counter
  • Create a mini version of this package
  • add the ability to log every add and request beside hard reset
  • Provide the length of time until they can use there API again.
  • The current local storage size
  • Update method from daily counter to specified counter
    • Hourly, daily, weekly, monthly and yearly

How to use APICounter()

All you have todo is add APICounter() to your project via npm i api_counter, add it to your try and catch or where ever you want to count.

You can have multiple counters, just pass in a name as a 'string'. If you do not pass in a name as the variable it will default to 'mainCounter'.
You can also add a limit to alert you that you have used 50% or 100% of your daily use. APICounter('counterNameAsString', limit as intiger)

try {
    const result = fetch(`https://www.apiurl.com/api/search?key=1235`);
    APICounter('mainCounter', 50);
} catch (error) {
    console.log(error);
    APICounter('errorCount')
}

Function that you can use

Gives you everything in localstorage (Current web page/domain)

allStorage()

understanding the acronyms and format

  • Function Format = cn , cls , limit, type
  • cn = counter name
  • cls = current local storage
  • limit = at what count do you want to be warn by
  • type = soft or hard reset
  • cy = current year
  • cm = current month
  • cdy = current day
  • clsli = current local storage last item - meaning the last object in the array
  • ldt = last date
  • tm = time

Data structure of JSON "file"

let cls = {
  data: [
    {
      counterAPI: 13,
      counterYear: 2022,
      counterMonth: 12,
      counterDay: 24,
      counterTime: 1568681773241
    },
    {
      counterAPI: 48,
      counterYear: 2022,
      counterMonth: 12,
      counterDay: 25,
      counterTime: 1568681901168
    }
  ]
};
Pull request are recommend and any features you want let's collaborate
1.1.5

4 years ago

1.1.4

5 years ago

1.1.3

5 years ago

1.1.2

5 years ago

1.1.1

5 years ago

1.0.0

5 years ago