0.11.3 • Published 5 years ago

tote-box v0.11.3

Weekly downloads
4
License
MIT
Repository
github
Last release
5 years ago

Tote Box · license npm (scoped)

NZ 的个人工具库

Installation

tote-box requires axios, lodash, @babel/runtime, but just requires axios to browsers.

$ npm i tote-box

Usage?

ESModules(in webpack builder or Rollup) for Tree-Shaking

import { parseTextPlaceholder } from 'tote-box';
parseTextPlaceholder('Hello, {name}!', { name: 'NZ' });

NodeJS

const { parseTextPlaceholder } = require('tote-box')
parseTextPlaceholder('Hello, {name}!', { name: 'NZ' });

In Browser

<script src="tote-box.js"></script>
<script>
  ToteBox.parseTextPlaceholder('Hello, {name}!', { name: 'NZ' });
</script>

ability

listenPageVisibility( handler )

isElementInViewport( element )

lazyLoadImage( dataSrcAttr = 'data-src', container = document )

cache

cache.get( key )

cache.set( key, value )

cache.remove( key )

cache.clear()

cacheTable

cacheTable.get( primaryKey, secondaryKey )

cacheTable.set( primaryKey, secondaryKey, value )

cacheTable.remote( primaryKey, secondaryKey )

cacheTable.clear( primaryKey )

cookie

cookie.get( name )

cookie.set( name, value , options )

options: { expires, path, domain, secure }

cookie.remove( name , options )

options: { path, domain, secure }

array

arrayToTree( data , options )

options: { id = 'id', parentId = 'parentId', rootParentId = 0, children = 'children' }

chunk( data, process , context, duration = 100 )

batch( data, process , context, cb, options )

options: { runDuration = 25, chunkDuration = 50 }

history

historyInst.getPrev()

historyInst.getNext()

historyInst.size()

historyInst.add( url )

historyInst.find( url )

historyInst.direct( url )

fetch-request

request.get( url , data, options )

request.post( url , data, options )

request.put( url , data, options )

request.patch( url , data, options )

request.delete( url , data, options )

request.defaults

axios-request

request( config, handlers )

config

Type: Object

same as axios.create() config

handlers

Type: Object

handlers.filterResponse( response.data )
handlers.beautifyError( url, error )

req = request()

req.get( url , data, config )
req.delete( url , data, config )
req.head( url , data, config )
req.options( url , data, config )
req.post( url , data, config )
req.put( url , data, config )
req.patch( url , data, config )

string

parseTextPlaceholder( text, data , dataReplaceable )

parseNumberPlaceholder( text, …params )

trim( text )

formatSize( bytes )

html

html.entityify( text )

html.deentityify( text )

html.strip( text )

html.escape( text )

html.filter( text, maxlength )

date

isLeapYear( year )

parseDate( format, value )

formatDate( format, date )

time

timeParser( options )

return (time) => { unit, value }, ...

options

Type: Object

options.startUnit

Type: String

Default: 'year'

possible values: 'years', 'months', 'weeks', 'days', 'hours', 'minutes', 'seconds'

options.units

Type: Object

Defult: { hours: 'Years', months: 'Months', weeks: 'Weeks', days: 'Days', hours: 'Hours', minutes: 'Minutes', seconds: 'Seconds' }

e.g. { hours: '小时', minutes: '分钟', ... }

countdown( value , { onStart, onProgress, onEnd }, context )

util

type( obj )

deepAssign( target, source1 , source2... )

random(a, b)

delayTask( task, delay = 600 )

query

getQuerys( url )

addQuerys( url, querys )

querys( url, querys )

checkQuery( requiredParams )

License

MIT

0.11.3

5 years ago

0.11.2

5 years ago

0.11.1

5 years ago

0.11.0

5 years ago

0.10.2

6 years ago

0.10.1

6 years ago

0.10.0

6 years ago

0.9.19

6 years ago

0.9.18

6 years ago

0.9.17

6 years ago

0.9.16

6 years ago

0.9.15

6 years ago

0.9.14

6 years ago

0.9.13

6 years ago

0.9.12

6 years ago

0.9.11

6 years ago

0.9.10

6 years ago

0.9.9

6 years ago

0.9.7

6 years ago

0.9.5

6 years ago

0.9.4

6 years ago

0.9.3

6 years ago

0.9.1

6 years ago

0.9.0

6 years ago

0.8.4

6 years ago

0.8.3

6 years ago

0.8.2

6 years ago

0.8.1

6 years ago

0.8.0

6 years ago

0.7.4

6 years ago

0.7.3

6 years ago

0.7.2

6 years ago

0.7.1

6 years ago

0.7.0

6 years ago

0.6.1

6 years ago

0.6.0

6 years ago

0.5.1

6 years ago

0.5.0

6 years ago

0.4.1

6 years ago

0.4.0

6 years ago

0.3.0

6 years ago

0.2.1

6 years ago

0.2.0

6 years ago

0.1.4

6 years ago

0.1.3

6 years ago

0.1.2

6 years ago

0.1.1

6 years ago