sassy

1.0.0 • Public • Published

Sassy

Sassy eases the pain for object-oriented programmers and makes getting around in SASS a little easier.

Overview

Sassy provides some essential functionality and makes working with maps much easier.

It also includes a debugging utility for unit-testing (see notes at the bottom).

Methods:

  • get
  • set
  • has
  • compare
  • type
  • types
  • types-same
  • contains
  • explode
  • implode
  • thru
  • print
  • apply
  • increase
  • decrease

Method Uses:

@note All methods that use a ( map, key, ... ) signature allow for nested maps using a key list!

Method: get > gets an value from a map key. for nested maps, use a list of keys ######Signatures and Supported Types

Signature:

  • get( map, key )
  • get( map, ( nested, key ) )

Supported types: map

Method: set > sets a key:value pair in a map. for nested maps, use a key list ######Signatures and Supported Types

Signature:

  • set( map, key, value )
  • set( map, ( nested, key ), value )

@note Remember SASS objects are immutable. Replace your map reference each time!

Supported types: map

Method: has > checks if a map has a key. optionally returns the value ######Signatures and Supported Types

Signature: has( map, key, [return], [default] )

Optional default value IF NO KEY (otherwise returns null).

Supported types: map

Method: compare > compares 2 things ######Signatures and Supported Types

Signature: compare( A, B )

Supported types: any

Method: type > gets the type of an object (optional check string to compare and return bool) ######Signatures and Supported Types

Signature: type( var, [against] )

Supported types: any

Method: types > returns the types of all args provided in a new list ######Signatures and Supported Types

Signature: types ( varN... )

Supported types: any

Method: types-same > checks that all vars provided are the same type ######Signatures and Supported Types

Signature: types-same ( varN... )

Supported types: any

Method: contains > checks if one thing contains another ######Signatures and Supported Types

Signature: contains( haystack, needle )

Supported types: map, list, string

Method: explode > breaks a string by {delimiter}, returns as list ######Signatures and Supported Types

Signature: explode( string, [delimiter='-'] )

Supported types: string

Method: implode > joins list items between glue, returning as a string ######Signatures and Supported Types

Signature: implode( list, [wrap=false], [glue=', '] )

@note wrap is optional. if true, adds ( ) to string before returning

Supported types: list

Method: thru( any ) > returns the first argument straight thru (useful for testing purposes) ######Signatures and Supported Types

Signature: thru( any )

Supported types: any

Method: print > prints a map as a string representation (similar to native "inspect" function) ######Signatures and Supported Types

Signature: print( map )

Supported types: map

Method: apply > essentially 'calls' a function. values will be fed as call unless they are a list or map. if list, passed as multiple args. if you need to pass a single list, use an "argsmap" ( args: ( your, list ) ) as the arguments param. used by debugger ######Signatures and Supported Types

Signature:

  • apply( method_name, argslist... )
  • apply( method_name, ( list, of, args ) )
  • apply( method_name, argsmap )

Supported types: function

Method: increase > increases a number [in a map] by X ######Signatures and Supported Types

Signature:

  • increase( number, [x=1] )
  • increase( map, key, [x=1] )

Supported types: number, map with number as value to a key

Method: decrease > decreases a number [in a map] by X ######Signatures and Supported Types

Signature:

  • decrease( number, [x=1] )
  • decrease( map, key, [x=1] )

Supported types: number, map with number as value to a key

Method: pluck > pulls a shared key from multiple maps ######Signatures and Supported Types

Signature: pluck( key, maps.. )

@note also accepts a list of maps

Supported types: map


Sassy Debugger

I put together a SASS debug utility based loosely on my much more robust JS debugger.

There are only 3 mixins you need (really only "test", but it's better to use all 3).

Mixin: start > starts a debugger ######Signatures and Supported Types

Signature: @include start(debug_name)

Mixin: test > performs a unit test and echos result ######Signatures and Supported Types

Signature:

  • @include test( method_name, arguments, [expect=true] )
  • @include test( name, result, [expect=true] )

You should always use a list of arguments instead of a result boolean.

The result boolean option is there for edge cases where comparing the result isn't so easy.

If you need to pass a single list, use an argsmap

( args: ( your, list ) )

You can add a variation string as the 4th parameter. Useful if debugging similar signatures.

Mixin: complete

reports a summary of pass/fail

@note fire this after all of your tests. it will tell you that all tests passed or which ones failed (and why).

--

That's all! Enjoy the software!

Package Sidebar

Install

npm i sassy

Weekly Downloads

11

Version

1.0.0

License

DBAA, see license.txt

Last publish

Collaborators

  • caseydwayne