Tote Box ·
NZ 的个人工具库
tote-box
requires axios
, lodash
, @babel/runtime
, but just requires axios
to browsers.
$ npm i tote-box
ESModules(in webpack builder or Rollup) for Tree-Shaking
import { parseTextPlaceholder } from 'tote-box';
parseTextPlaceholder('Hello, {name}!', { name: 'NZ' });
const { parseTextPlaceholder } = require('tote-box')
parseTextPlaceholder('Hello, {name}!', { name: 'NZ' });
<script src="tote-box.js"></script>
<script>
ToteBox.parseTextPlaceholder('Hello, {name}!', { name: 'NZ' });
</script>
listenPageVisibility( handler )
isElementInViewport( element )
lazyLoadImage( [ dataSrcAttr = 'data-src', container = document ] )
cacheTable.get( primaryKey, secondaryKey )
cacheTable.set( primaryKey, secondaryKey, value )
cacheTable.remote( primaryKey, secondaryKey )
cacheTable.clear( primaryKey )
cookie.set( name, value [, options ] )
options: { expires, path, domain, secure }
cookie.remove( name [, options ] )
options: { path, domain, secure }
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 }
historyInst.direct( url )
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( [ config, handlers ] )
Type: Object
same as axios.create() config
Type: Object
handlers.filterResponse( response.data )
handlers.beautifyError( url, error )
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 ] )
parseTextPlaceholder( text, data [ , dataReplaceable ] )
parseNumberPlaceholder( text, …params )
html.filter( text, maxlength )
parseDate( format, value )
formatDate( format, date )
return (time) => [{ unit, value }, ...]
Type: Object
Type: String
Default: 'year'
possible values: 'years', 'months', 'weeks', 'days', 'hours', 'minutes', 'seconds'
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 ] )
deepAssign( target, source1 [ , source2... ] )
delayTask( task, delay = 600 )
addQuerys( [ url, querys ] )
querys( [ url, querys ] )
checkQuery( requiredParams )
MIT