SassyBitwise
Bitwise operators in Sass (not Ruby). Read API documentation.
Installation
gem install SassyBitwise
# config.rbrequire "SassyBitwise"
npm install sassybitwise
API
And
;// or ; // -> 32
Or
;// or ; // -> 58
Xor
;// or ; // -> 26
Not
;// or ; // -> -43
Shift left
;// or ; // -> 168
Shift right
;// or ; // -> 10
All together
; // -> 7
Notes
- Because Sass requires special characters to be either quoted or escaped, it is recommanded you always quote the operators.
bw()
is an alias forbitwise()
Example
Encoding flags as a single int. You know, because we can.
// Defining global flags, // Bitwise encoded ;;;; // Helper function // Checking for flag status // --- // @param [number] $int: flag encoded value // @param [number] $flag: a global flag // --- // @return [bool] // --- // Defining a mixin with many options // Accepting a single encoded flag as argument // --- // @param [list] $int: list of flags, low-level prog' style // --- // Sample test cast test
Thanks
A huge thanks to Valérian Galliat for his help, and Fabrice Weinberg for Travis integration.