1.1.26 • Published 3 years ago

bbo v1.1.26

Weekly downloads
104
License
MIT
Repository
github
Last release
3 years ago

logo


npm version gzip size monthly npm installs jest codecov-image license

bbo is a utility library of zero dependencies for javascript.

Overview

Every frontend developer has his own utils library, and we often write methods that are easily forgotten and highly used. bbo is a super small and useful utils library for JavaScript. It isn't couping with lodash underscore lazy.js.

I sorted out the most frequently used functions in daily development. These functions are almost ubiquitous in your development, and they cannot be found in lodash and underscore.

Most code comes from the stackOverflow site in the high-score answers, so we pay tribute to the original authors.

With easy code and less than 7k gzip, bbo can be used anytime and anywhere with no worries.

See the latest docs/documentation for a full API reference or bbo-docs.

Why

When you use react, vue, angular,you often need to write a lot of utils methods. But lodash and underscore libraries are not omnipotent. So you have to find a lot of tool libraries. By using bbo, you can solve many small problems in the daily development. It is simple and compact!

Documentation

Functions

deviceargshttpstringarray
uaargsopentrimunique
isIosnoopgetUrlParamfillZerouniqueBy
isiPhonemergesetUrlParamlongUniqueuniqueFrom
isIPadoverdeleteUrlParamstripTagsrandom
isAndroidcallobjectParamcapitalizerandomSize
isMobilehasOwnPropertyhttpGetdeCapitalizeshuffle
isPCbomhttpPostisAbsoluteURLcontains
isWeixinstopPropagationrandommapStringincludesAll
isNewsAppgrandomColormaskincludesAny
isQQgcrandomA2BsplitLinesremoveAt
isQQbrowsercrandomKeycamelizeremove
isTenvideoquerybehaviorunderscoredcompact
isWeiShishowtriggerdasherizepluck
isIphoneXmodelhidelockTouchtruncateunion
isIEelementContainscopyToClipboardbyteSizeunionBy
ieVersionformToObjectmlodashbyteLenunionWith
loggetStylegetTagrepeatintersect
logsetStyleisendsWithintersectBy
logsattrisObjectstartsWithdifference
removeConsoleloadisArraycontainsWithdifferenceBy
trashloadImagesisStringxssFiltermax
otherloadjsisBooleaneffortIndexmin
uuidloadcssisNumbercapwordsequal
hashfillisMapobjectallEqual
judgefill0isSetproperObjectall
getTypefloorisFunctionobjectDiffany
isTypeofchainAsyncisEmptyaddedDiffchunk
constructnumberFormatisShallowEqualdeletedDiffcountBy
paramsNamemodulohasdetailedDiffcountOccurrences
eventEmittercookietoPathupdatedDiffdrop
timescookiereducecollectiondropRight
setTimesoutsetCookieforEachclonedropWhile
clearTimesoutgetCookiemapentriesdropRightWhile
getDatedeleteCookiefindextendcolumn
formatPassTimeparseCookiefindIndexflushsplit
formatRemainTimeimagegetvaluesunary
formatDurationcheckImageSizesetsizeindexBy
sleepimageOptimizationdebouncesearch
retrytoDataUrlthrottle
jsonpick
toJsonomit
jsonpisSymbol
storageisDate
storagemapValues

Usage

example

// base case
bbo.getCookie('username'); // => 'userName'
bbo.cookie().getJson(); //  => {a: 1, b: 2}
bbo.isiPhone(); // => true or false
bbo.numberFormat(1234.56, 2, ',', ' '); // => '1 234,56';
bbo.split([1, 2, 3, 4, 5], 2); // => [[1,2], [3,4], [5]]
bbo.entries({ c: 8, a: 4 }); // => [['c', 8], ['a', 4]]
bbo.toPath("a.b.c"); // => ['a', 'b', 'c']
bbo.get({ a: { aa: { aaa: 2 } }, b: 4 }, "a.aa.aaa"); // => 2
bbo.union([1, 2, 3], [4, 3, 2]); // => [1, 2, 3, 4]
bbo.intersect([1, 2, 3], [4, 3, 2]); // => [2, 3]
bbo.unionBy([2.1], [1.2, 2.3], Math.floor); // [2.1, 1.2]
bbo.mapValues({ a: 3, b: 5, c: 9 }, (value) => value + 1); //=> {a: 4, b: 6, c: 10}
bbo.compact([0, 1, false, 2, "", 3]); // [1, 2, 3]
bbo.flush({a: 2, b: null, c: 4, d: undefined}); // => {a: 2, c: 4}
bbo.differenceBy([2.1, 1.2], [2.3, 3.4], Math.floor); // => [1]
bbo.search("3", { a: 3, b: 5, c: 7 }); // => 'a'
bbo.size({ a: 1, b: 2 }); // => 2

var users = [
  { user: "barney", age: 36, active: true },
  { user: "fred", age: 40, active: false },
];
bbo.find(users, { age: 1, active: true }); // => {"active": true, "age": 36, "user": "barney"}
bbo.findIndex(users, ["active", false]); // => 1

// chain case
var array1 = [1, 2, 3, null];
var array2 = [3, 4, 5, ''];
var object1 = { a: 6, b: 7 };
var object2 = { c: 8, d: 9 };

bbo
  .chain(object1)
  .extend(object2) // => {a: 6, b: 7, c: 8, d: 9}
  .entries() // =>  [["a", 6], ["b", 7], ["c", 8], ["d", 9]]
  .thru((words) => {
    const temp = [];
    bbo.forEach(words, (item, index) => {
      temp.push(item[1]);
    });
    return temp;
  }) // => [6, 7, 8, 9]
  .union(array1) // => [6, 7, 8, 9, 1, 2, 3, null]
  .union(array2) // => [6, 7, 8, 9, 1, 2, 3, null, 4, 5, ""]
  .compact() // => [6, 7, 8, 9, 1, 2, 3, 4, 5]
  .thru((array) => {
    return array.sort();
  }) // => [1, 2, 3, 4, 5, 6, 7, 8, 9]
  .value();
// return  => [1, 2, 3, 4, 5, 6, 7, 8, 9]

... ∞

Install

bbo supports Node.js, Rollup, Webpack, Browserify。

commonjs

npm

bbo

Install the library with npm into your local modules directory:

npm install bbo --save

CommonJS modules

Then in your application require the entire library:

const bbo = require('bbo');
bbo.isiPhone(); // => 'true'

Or require individual functions:

const cookie = require('bbo/cookie');

ES2015 modules

Bbo is compatible with ES2015 modules to import the entire library:

import bbo from 'bbo';

Or import individual functions:

import storage from 'bbo/storage';

Browser

browsers

Load the UMD builds directly into browser's web page:

<script src="bbo.min.js" type="text/javascript"></script>

Then a global variable bbo is exposed for the entire library:

<script type="text/javascript">
  bbo.cookie().getJson(); // => {a: 1, b: 2}
</script>

CDN

npm.io npm.io

Building

node is a dependency, use terminal/iTerm to install it with

Clone git repository:

git clone git://github.com/tnfe/bbo.git

Install dependencies:

npm install

Build bundle

npm run build

And run example

npm run start
//visit http://localhost:8080

Testing

  • Run all tests as a single test suite with npm run test
  • Show the world you're using Jest.

Coverage sunburst

Each block represents a single file in the project(codecov.io). The size and color of each block is represented by the number of statements and the coverage, respectively.

codecov

Contribution

Contribution is welcome! If you wish to contribute to the project, please send the pull requests to the develop branch

  • Create a pull request containing bug fixes or new features. 😎

  • Propose new functions, improvements, better documentation

See contributors.

If you want to participate in the creation of this project,Edit or add function,Fork this project,Modify and Pull requests or new Issues.

How to sync?

# Add upstream origin,Just execute it once
git remote add upstream git@github.com:tnfe/bbo.git

# Pull remote code
git pull upstream master

# Commit changes
git add .
git commit

# update fork
git push origin master

More: Syncing a fork

Changelog

Detailed changes for each release are documented in the release notes.

License

bbo is MIT licensed.

1.1.26

3 years ago

1.1.25

3 years ago

1.1.24

3 years ago

1.1.23

4 years ago

1.1.22

4 years ago

1.1.21

4 years ago

1.1.20

4 years ago

1.1.19

4 years ago

1.1.18

4 years ago

1.1.17

4 years ago

1.1.16

4 years ago

1.1.15

4 years ago

1.1.14

4 years ago

1.1.13

4 years ago

1.1.12

4 years ago

1.1.11

4 years ago

1.1.10

4 years ago

1.0.9

4 years ago

1.0.8

4 years ago

1.0.7

4 years ago

1.0.6

4 years ago

1.0.5

4 years ago

1.0.4

4 years ago

1.0.3

4 years ago

1.0.2

4 years ago

1.0.1

4 years ago