tooly

0.9.9 • Public • Published

tooly

A Javascript utility library covering everything from dom selection and css manipulation, object inheritance and extension, logging, event handling, string formatting, function execution timing, etc. Basically everything that I usually want/need at my fingertips for any given project. Compatible with node, amd, and modern browsers. 4.6kb minified and gzipped (3.4kb without the logger and timer modules, which shouldn't be used in production anyway - see dist/tooly-slim.js).

Update 2015.05.21

Tooly is now available as an angular service.

Install

npm: npm install tooly --save

bower: bower install tooly --save

Overview

Tooly is organized into categories, which are just that - organizational constructs - as opposed to individual modules. In a few cases the "category" is encompassed by a class. Below is a list of all categories, their related methods, and a description for the more interesting bits. The method names alone should give you an idea if tooly is something you'd find useful. Consult the documentation for a complete reference.

Collections

  • each
  • sort - sort array of objects by key

Frankie (class)

jQuery-like dom selection/manipulation

  • #addClass
  • #append
  • #attr
  • #children
  • #css
  • #each
  • #empty
  • #eq
  • #find
  • #get
  • #hasClass
  • #html
  • #on
  • #parent
  • #prepend
  • #remove
  • #removeClass
  • #toggleClass
  • #zilch

Handler (class)

Tiny "Event Emitter"; Observer pattern

  • #on
  • #register
  • #remove
  • #removeAll
  • #trigger

Logger (class)

Highly configurable, level-based and styled console logging for node and browser

  • #debug
  • #error
  • #group
  • #groupEnd
  • #info
  • #log
  • #warn
  • #trace

Object (or "everything else")

  • construct
  • extend
  • falsy
  • fromPrototype
  • inherit
  • scale
  • truthy
  • type - modified from Angus Croll's wicked-awesome toType

String

Functional versions of ECMAScript 6 stuff and useful formatters

  • contains
  • endsWith
  • extension
  • format - printf style string formatting
  • formatMoney
  • formatString - placeholder ('Drink {1}', "Marlort!") style string formatting
  • formatTime
  • leftPad
  • repeat
  • rightPad
  • sliceRel
  • startsWith
  • stripExtension
  • tag - jade syntax style dom builder

Timer (class)

Basic block/function execution timing

  • #end
  • funkyTime - static method, not part of Timer class
  • #log
  • #start
  • #stop
  • #toString

XHR

  • get
  • getJson

Documentation

View online at lokua.github.io/tooly or locally at ./doc/index.html

Custom Build

You can create a custom build of any combination of particular categories.

cd path_to/node_modules/tooly
# from the tooly module root, install dev dependecies 
npm install
# run the script and `include` command 
# passing as arguments modules (lowercase) you want included 
node bin/build include logger timer string
# run the `grunt build` task to wrap tooly in umd, minify etc. 
grunt build

By default the custom build will be located at ./dist/tooly-custom.js, or alternatively, you can specify a custom output file during the build instruction:

node bin/build include dom string -o tooly-custom.js && grunt build

Development

"Rough Drafts" are worked out in the test/_spec folder, either as .js files for node testing or .html for browser-based code, before being implemented in src. Testing is done with Mocha and Chai. Run with npm run test, or serve test/test.html for dom-related functions. Build with npm run all.

Changelog

0.9.9

  • fixed #falsy to not return true for empty arrays

0.8.6 (same as 0.8.5, ...fucking bower weirdness)

0.8.5

  • fixed tag bug - check if attrs exists before querying it

0.8.3

  • extendTo now returns the extended object, so one-liner like var _ = require('tooly').extendTo('lodash') works

0.8.2

  • fixed logger ctor bug when no option passed

0.8.1

  • added ready function
  • scale output now defaults to min=0, max=1

0.8.0

  • added extendTo function to lend tooly methods to another lib (tested with lodash)
  • Breaking Change: removed isHash- use tooly.type(obj, 'object') instead
  • added tooly.empty to collections
  • fixed global leak _0 in Frankie#css

0.7.0

  • Breaking change: Handler is now only on, register, remove, removeAll, and trigger (no aliases)
  • Breaking change: Handler#remove(<name>) now deletes the <name> property from the handlers object (instead of just emptying that <name>'s array)
  • Breaking change: tooly.Logger now defaults to level 0, and can be instantiated without arguments
  • added symbol param to formatMoney

0.6.5

  • Frankie#find and Frankie#attr bugfix
  • added Frankie#each

0.6.4

  • Logger options bypassTimestamp and bypassLine now default to true

License

The MIT License (MIT)

© 2014, 2015 Joshua Kleckner

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Package Sidebar

Install

npm i tooly

Weekly Downloads

0

Version

0.9.9

License

MIT

Last publish

Collaborators

  • lokua