# tote-box

> NZ's utils

Latest version **0.11.3** (published 2019-01-07) · MIT license · 0 weekly downloads

> **Deprecated.** This package is deprecated.

## Install

```sh
npm install tote-box
pnpm add tote-box
yarn add tote-box
bun add tote-box
```

## Health

**Score 10/100 (F)** — status: deprecated.

Negative: deprecated.

## Facts

| | |
|---|---|
| Version | 0.11.3 |
| Published | 2019-01-07 |
| First published | 2018-04-12 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Node | >=8 |
| Dependencies | 0 |
| Unpacked size | 142 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 4 |
| Author | NZ |
| Maintainers | nicolaszhao |
| Keywords | utils, library |

## Links

- npm: https://www.npmjs.com/package/tote-box
- Repository: https://github.com/nicolaszhao/tote-box
- Homepage: https://github.com/nicolaszhao/tote-box#readme
- Issues: https://github.com/nicolaszhao/tote-box/issues
- npm.io page: https://npm.io/package/tote-box

## Recent versions

- 0.11.3 (latest) — 2019-01-07
- 0.11.2 — 2019-01-07
- 0.11.1 — 2018-12-28
- 0.11.0 — 2018-12-27
- 0.10.2 — 2018-10-15
- 0.10.1 — 2018-09-30
- 0.10.0 — 2018-09-29
- 0.9.19 — 2018-09-27
- 0.9.18 — 2018-09-25
- 0.9.17 — 2018-09-25
- 0.9.16 — 2018-09-25
- 0.9.15 — 2018-09-25
- 0.9.14 — 2018-09-25
- 0.9.13 — 2018-09-25
- 0.9.12 — 2018-09-21
- … 32 more at https://npm.io/package/tote-box/versions

## README

# Tote Box &middot; ![license](https://img.shields.io/github/license/nicolaszhao/tote-box.svg?style=flat-square) ![npm (scoped)](https://img.shields.io/npm/v/tote-box.svg?style=flat-square) 
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

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

### NodeJS

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

### In Browser

```html
<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](LICENSE)

---
_Source: https://npm.io/package/tote-box · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
