0.0.36 • Published 2 years ago

@ansonhkg/utils v0.0.36

Weekly downloads
-
License
ISC
Repository
github
Last release
2 years ago

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.

ababacornacorn-globalsacorn-walkajvansi-escapesansi-regexansi-stylesanymatcharr-diffarr-flattenarr-unionarray-equalarray-uniqueasn1assert-plusassign-symbolsastral-regexasync-limiterasynckitatobaws-sign2aws4babel-jestbabel-plugin-istanbulbabel-plugin-jest-hoistbabel-preset-jestbalanced-matchbasebcrypt-pbkdfbrace-expansionbracesbrowser-process-hrtimebrowser-resolvebserbuffer-fromcache-basecallsitescamelcasecapture-exitcaselesschalkci-infoclass-utilscliuicocollection-visitcolor-convertcolor-namecombined-streamcommandercomponent-emitterconcat-mapconvert-source-mapcopy-descriptorcore-util-iscross-spawncssomcssstyledashdashdata-urlsdebugdecamelizedecode-uri-componentdeep-isdefine-propertiesdefine-propertydelayed-streamdetect-newlinediff-sequencesdomexceptionecc-jsbnemoji-regexend-of-streamerror-exes-abstractes-to-primitiveescape-string-regexpescodegenesprimaestraverseesutilsexec-shexecaexitexpand-bracketsexpectextendextend-shallowextglobextsprintffast-deep-equalfast-json-stable-stringifyfast-levenshteinfb-watchmanfill-rangefind-upfor-inforever-agentform-datafragment-cachefs.realpathfunction-bindget-caller-fileget-streamget-valuegetpassglobglobalsgraceful-fsgrowlyhandlebarshar-schemahar-validatorhashas-flaghas-symbolshas-valuehas-valueshosted-git-infohtml-encoding-snifferhtml2canvashttp-signatureiconv-liteimport-localimurmurhashinflightinheritsinvariantis-accessor-descriptoris-arrayishis-bufferis-callableis-ciis-data-descriptoris-date-objectis-descriptoris-extendableis-fullwidth-code-pointis-generator-fnis-numberis-plain-objectis-regexis-streamis-symbolis-typedarrayis-windowsis-wslisarrayisexeisobjectisstreamistanbul-lib-coverageistanbul-lib-instrumentistanbul-lib-reportistanbul-lib-source-mapsistanbul-reportsjest-changed-filesjest-clijest-configjest-diffjest-docblockjest-eachjest-environment-jsdomjest-environment-nodejest-get-typejest-haste-mapjest-jasmine2jest-leak-detectorjest-matcher-utilsjest-message-utiljest-mockjest-pnp-resolverjest-regex-utiljest-resolvejest-resolve-dependenciesjest-runnerjest-runtimejest-serializerjest-snapshotjest-utiljest-validatejest-watcherjest-workerjs-tokensjsbnjsdomjsescjson-parse-better-errorsjson-schemajson-schema-traversejson-stringify-safejson5jsprimkind-ofkleurleft-padlevenlevnload-json-filelocate-pathlodashlodash.sortbyloose-envifymake-dirmakeerrormap-cachemap-visitmerge-streammicromatchmime-dbmime-typesminimatchminimistmixin-deepmkdirpmsnanomatchnatural-compareneo-asyncnice-trynode-int64node-modules-regexpnode-notifiernormalize-package-datanormalize-pathnpm-run-pathnwsapioauth-signobject-copyobject-inspectobject-keysobject-visitobject.getownpropertydescriptorsobject.pickonceoptimistoptionatorp-each-seriesp-finallyp-limitp-locatep-reducep-tryparse-jsonparse5pascalcasepath-existspath-is-absolutepath-keypath-parsepath-typeperformance-nowpifypiratespkg-dirpnposix-character-classesprelude-lspretty-formatpromptspslpumppunycodeqsreact-isread-pkgread-pkg-uprealpath-nativeregex-notremove-trailing-separatorrepeat-elementrepeat-stringrequestrequest-promise-corerequest-promise-nativerequire-directoryrequire-main-filenameresolveresolve-cwdresolve-fromresolve-urlretrimrafrsvpsafe-buffersafe-regexsafer-buffersanesaxsemverset-blockingset-valueshebang-commandshebang-regexshellwordssignal-exitsisteransislashsnapdragonsnapdragon-nodesnapdragon-utilsource-mapsource-map-resolvesource-map-supportsource-map-urlspdx-correctspdx-exceptionsspdx-expression-parsespdx-license-idssplit-stringsshpkstack-utilsstatic-extendstealthy-requirestring-lengthstring-widthstring.prototype.trimleftstring.prototype.trimrightstrip-ansistrip-bomstrip-eofsupports-colorsymbol-treetest-excludethroattmplto-fast-propertiesto-object-pathto-regexto-regex-rangetough-cookietr46tunnel-agenttweetnacltype-checkuglify-jsunion-valueunset-valueuri-jsurixuseutil.promisifyuuidvalidate-npm-package-licenseverrorw3c-hr-timewalkerwebidl-conversionswhatwg-encodingwhatwg-mimetypewhatwg-urlwhichwhich-modulewordwrapwrap-ansiwrappywrite-file-atomicwsxml-name-validatory18nyargsyargs-parser
0.0.36

2 years ago

0.0.35

2 years ago

0.0.34

3 years ago

0.0.33

3 years ago

0.0.32

3 years ago

0.0.31

3 years ago

0.0.30

3 years ago

0.0.29

3 years ago

0.0.28

3 years ago

0.0.27

3 years ago

0.0.26

3 years ago

0.0.25

3 years ago

0.0.23

3 years ago

0.0.22

3 years ago

0.0.19

3 years ago

0.0.18

3 years ago

0.0.17

3 years ago

0.0.16

3 years ago

0.0.15

3 years ago

0.0.14

3 years ago

0.0.13

3 years ago

0.0.12

3 years ago

0.0.11

3 years ago

0.0.10

3 years ago

0.0.9

3 years ago

0.0.8

3 years ago

0.0.7

3 years ago

0.0.6

3 years ago

0.0.5

3 years ago

0.0.4

3 years ago

0.0.3

3 years ago

0.0.2

3 years ago

0.0.1

3 years ago

0.0.0

3 years ago