@ansonhkg/utils
a personal utils library.
Last updated 2 months ago by ansonhkg .
ISC · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install @ansonhkg/utils 
SYNC missed versions from official npm registry.

What is this?

A utils library for personal use.

Installation

npm

npm i @ansonhkg/utils --save

yarn

yarn add @ansonhkg/utils

Then ...

Usage

Images

Save Div as Image

<!-- target div -->
<div id="divId"></div>
import utils from '@ansonhkg/utils';

utils.image.saveDiv("divId", 'filename');

Math

Add commas to digit

import utils from '@ansonhkg/utils';

var value = 1000000

var output = utils.math.commas(value);

// expected outcome 1,000,000

Cusum

import utils from '@ansonhkg/utils';

var input = [1,2,3,4,5];

var output = utils.array.cusum(input);

// expected output: [1,3,6,10,15]

UI

Remove html tags from string

import utils from '@ansonhkg/utils';

var string = '<h1>food</h1>';

var new_string = utils.ul.html(string);

// expected outcome food

Dynamically changes a div height based on if div has touched footer

import utils from '@ansonhkg/utils';

  mounted() {
    this.$nextTick(() => {
      window.addEventListener('scroll', () => {
        if (window.innerWidth >= 1024) {
          utils.ul.dynamicDiv('header', 'targetDiv', 'footer')
        }
      })
    })
  }

Javascript functions

Debounce


    // Expected Usage
    var input = document.getElementById('search-input');

    input.addEventListener('keyup', debounce(() => {
        // immediate execution
          
      }, async () => {
          // Wait 1000 ms before execution
          res = await search(input.value);
          
      }, 1000));
    };


    /**
     * Returns a function, that, as long as it contiunes to be invoked, will not
     * be triggered. 
     * @param { function } func_immediate function to be called immediately
     * @param { function } func function to be called after it stops being called for N milliseconds.
     * @param { number } wait milliseconds before triggering function
     */
    function debounce(func_immediate, func, wait){

      var timeoutId;
    
      return () => {
        // function to trigger immediately
        func_immediate();
        
        // Each time the function calls clear timeout
        clearTimeout(timeoutId);

        // delayed call
        timeoutId = setTimeout(func, wait);
      }
    }

How to publish NPM

Please note:

  • yarn to install all dependencies to run yarn test
  • Make sure you add .gitignore with and ignore node_modules when you clone this repo.

Make sure you have login to npm

npm login

initialize

npm init

inside package.json, add the following to your scripts

  "scripts": {
    "dev": "parcel ./src/index.html",
    "test": "jest",
    "publish:patch": "yarn version --patch && yarn publish",
    "publish:minor": "yarn version --minor && yarn publish",
    "publish:major": "yarn version --major && yarn publish"
  },

Your your new version when it prompts question New version eg 0.0.35 when patching.

Current Tags

  • 0.0.36                                ...           latest (2 months ago)

34 Versions

  • 0.0.36                                ...           2 months ago
  • 0.0.35                                ...           2 months ago
  • 0.0.34                                ...           8 months ago
  • 0.0.33                                ...           8 months ago
  • 0.0.32                                ...           8 months ago
  • 0.0.31                                ...           8 months ago
  • 0.0.30                                ...           8 months ago
  • 0.0.29                                ...           8 months ago
  • 0.0.28                                ...           8 months ago
  • 0.0.27                                ...           8 months ago
  • 0.0.26                                ...           8 months ago
  • 0.0.25                                ...           8 months ago
  • 0.0.23                                ...           8 months ago
  • 0.0.22                                ...           8 months ago
  • 0.0.19                                ...           8 months ago
  • 0.0.18                                ...           8 months ago
  • 0.0.17                                ...           8 months ago
  • 0.0.16                                ...           8 months ago
  • 0.0.15                                ...           8 months ago
  • 0.0.14                                ...           8 months ago
  • 0.0.13                                ...           8 months ago
  • 0.0.12                                ...           8 months ago
  • 0.0.11                                ...           8 months ago
  • 0.0.10                                ...           8 months ago
  • 0.0.9                                ...           8 months ago
  • 0.0.8                                ...           8 months ago
  • 0.0.7                                ...           8 months ago
  • 0.0.6                                ...           8 months ago
  • 0.0.5                                ...           8 months ago
  • 0.0.4                                ...           8 months ago
  • 0.0.3                                ...           8 months ago
  • 0.0.2                                ...           8 months ago
  • 0.0.1                                ...           8 months ago
  • 0.0.0                                ...           8 months ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 35
Last Month 105
Dependencies (363)
Dev Dependencies (1)
Dependents (0)
None

Copyright 2014 - 2017 © taobao.org |