SassyBitwise 1.0.0 → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -4
- data/lib/SassyBitwise.rb +13 -13
- data/stylesheets/SassyBitwise/api/_bitwise.scss +46 -46
- data/stylesheets/SassyBitwise/helpers/_binary-length.scss +9 -9
- data/stylesheets/SassyBitwise/helpers/_binary-to-decimal.scss +27 -27
- data/stylesheets/SassyBitwise/helpers/_decimal-to-binary.scss +24 -24
- data/stylesheets/SassyBitwise/helpers/_largest-power-of-2.scss +16 -16
- data/stylesheets/SassyBitwise/helpers/_order-args.scss +15 -0
- data/stylesheets/SassyBitwise/helpers/_power.scss +25 -25
- data/stylesheets/SassyBitwise/helpers/_sign.scss +9 -9
- data/stylesheets/SassyBitwise/operators/_and.scss +22 -19
- data/stylesheets/SassyBitwise/operators/_not.scss +10 -10
- data/stylesheets/SassyBitwise/operators/_or.scss +24 -21
- data/stylesheets/SassyBitwise/operators/_shift-left.scss +11 -11
- data/stylesheets/SassyBitwise/operators/_shift-right.scss +11 -11
- data/stylesheets/SassyBitwise/operators/_xor.scss +22 -19
- data/stylesheets/SassyBitwise/validators/_arguments-validator.scss +45 -45
- data/stylesheets/SassyBitwise/validators/_is-number.scss +9 -9
- data/stylesheets/_SassyBitwise.scss +16 -15
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bb3b64daed2bfc06498a4da5a3dca09d27a422d0
|
4
|
+
data.tar.gz: 7f4e8d21885e229cda01dd981d546bda85a48e9a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d1518a2072ca0c2f2ffe2eeba7847301edd746c782e888f181cf11f87bc37a5b627b79d05377102e18aa472f211842fb0cd3d997f6833f12662695f519d55fda
|
7
|
+
data.tar.gz: d15d5f8c4c3a56612c7fac5d7068dfa573294d65ebff9caf0ad30c88cc4b632620324c13cae8850d6786228c421e1020a920f50221bbb34a78b97b3bc2cb894a
|
data/CHANGELOG.md
CHANGED
@@ -1,4 +1,5 @@
|
|
1
|
-
# Changelog
|
2
|
-
|
3
|
-
* `1.0.
|
4
|
-
* `0.0
|
1
|
+
# Changelog
|
2
|
+
|
3
|
+
* `1.0.1`: fixing important issue in `^`, `|` and `&`
|
4
|
+
* `1.0.0`: stable API, gem release
|
5
|
+
* `0.0.1`: initial commit
|
data/lib/SassyBitwise.rb
CHANGED
@@ -1,14 +1,14 @@
|
|
1
|
-
require 'compass'
|
2
|
-
extension_path = File.expand_path(File.join(File.dirname(__FILE__), ".."))
|
3
|
-
Compass::Frameworks.register('SassyBitwise', :path => extension_path)
|
4
|
-
|
5
|
-
# Version is a number. If a version contains alphas, it will be created as a prerelease version
|
6
|
-
# Date is in the form of YYYY-MM-DD
|
7
|
-
module SassyBitwise
|
8
|
-
VERSION = "1.0.
|
9
|
-
DATE = "2014-06-04"
|
10
|
-
end
|
11
|
-
|
12
|
-
module Sass::Script::Functions
|
13
|
-
|
1
|
+
require 'compass'
|
2
|
+
extension_path = File.expand_path(File.join(File.dirname(__FILE__), ".."))
|
3
|
+
Compass::Frameworks.register('SassyBitwise', :path => extension_path)
|
4
|
+
|
5
|
+
# Version is a number. If a version contains alphas, it will be created as a prerelease version
|
6
|
+
# Date is in the form of YYYY-MM-DD
|
7
|
+
module SassyBitwise
|
8
|
+
VERSION = "1.0.1"
|
9
|
+
DATE = "2014-06-04"
|
10
|
+
end
|
11
|
+
|
12
|
+
module Sass::Script::Functions
|
13
|
+
|
14
14
|
end
|
@@ -1,46 +1,46 @@
|
|
1
|
-
// Bitwise helper function
|
2
|
-
// ---
|
3
|
-
// @param [list] $args: list of parameters
|
4
|
-
// ---
|
5
|
-
// @return [number]
|
6
|
-
// ---
|
7
|
-
@function bitwise($args) {
|
8
|
-
@if not arguments-validator($args) {
|
9
|
-
@return false;
|
10
|
-
}
|
11
|
-
|
12
|
-
// Handling not first
|
13
|
-
@if nth($args, 1) == "~" {
|
14
|
-
@return bw-not(nth($args, 2));
|
15
|
-
}
|
16
|
-
|
17
|
-
// Then all others
|
18
|
-
$operator: to-lower-case(nth($args, 2));
|
19
|
-
$x: nth($args, 1);
|
20
|
-
$y: nth($args, 3);
|
21
|
-
|
22
|
-
@if $operator == "^" {
|
23
|
-
@return bw-xor($x, $y);
|
24
|
-
}
|
25
|
-
|
26
|
-
@else if $operator == "|" {
|
27
|
-
@return bw-or($x, $y);
|
28
|
-
}
|
29
|
-
|
30
|
-
@else if $operator == "&" {
|
31
|
-
@return bw-and($x, $y);
|
32
|
-
}
|
33
|
-
|
34
|
-
@else if $operator == "<<" {
|
35
|
-
@return bw-shift-left($x, $y);
|
36
|
-
}
|
37
|
-
|
38
|
-
@else if $operator == ">>" {
|
39
|
-
@return bw-shift-right($x, $y);
|
40
|
-
}
|
41
|
-
|
42
|
-
@else {
|
43
|
-
@warn "Wrong operator `#{$operator}` for `bitwise` function.";
|
44
|
-
@return false
|
45
|
-
}
|
46
|
-
}
|
1
|
+
// Bitwise helper function
|
2
|
+
// ---
|
3
|
+
// @param [list] $args: list of parameters
|
4
|
+
// ---
|
5
|
+
// @return [number]
|
6
|
+
// ---
|
7
|
+
@function bitwise($args) {
|
8
|
+
@if not arguments-validator($args) {
|
9
|
+
@return false;
|
10
|
+
}
|
11
|
+
|
12
|
+
// Handling not first
|
13
|
+
@if nth($args, 1) == "~" {
|
14
|
+
@return bw-not(nth($args, 2));
|
15
|
+
}
|
16
|
+
|
17
|
+
// Then all others
|
18
|
+
$operator: to-lower-case(nth($args, 2));
|
19
|
+
$x: nth($args, 1);
|
20
|
+
$y: nth($args, 3);
|
21
|
+
|
22
|
+
@if $operator == "^" {
|
23
|
+
@return bw-xor($x, $y);
|
24
|
+
}
|
25
|
+
|
26
|
+
@else if $operator == "|" {
|
27
|
+
@return bw-or($x, $y);
|
28
|
+
}
|
29
|
+
|
30
|
+
@else if $operator == "&" {
|
31
|
+
@return bw-and($x, $y);
|
32
|
+
}
|
33
|
+
|
34
|
+
@else if $operator == "<<" {
|
35
|
+
@return bw-shift-left($x, $y);
|
36
|
+
}
|
37
|
+
|
38
|
+
@else if $operator == ">>" {
|
39
|
+
@return bw-shift-right($x, $y);
|
40
|
+
}
|
41
|
+
|
42
|
+
@else {
|
43
|
+
@warn "Wrong operator `#{$operator}` for `bitwise` function.";
|
44
|
+
@return false
|
45
|
+
}
|
46
|
+
}
|
@@ -1,9 +1,9 @@
|
|
1
|
-
// Returns binary length
|
2
|
-
// ---
|
3
|
-
// @param [number] $value: value
|
4
|
-
// ---
|
5
|
-
// @return [number]
|
6
|
-
// ---
|
7
|
-
@function binary-length($value) {
|
8
|
-
@return str-length(decimal-to-binary($value) + unquote(""))
|
9
|
-
}
|
1
|
+
// Returns binary length
|
2
|
+
// ---
|
3
|
+
// @param [number] $value: value
|
4
|
+
// ---
|
5
|
+
// @return [number]
|
6
|
+
// ---
|
7
|
+
@function binary-length($value) {
|
8
|
+
@return str-length(decimal-to-binary($value) + unquote(""))
|
9
|
+
}
|
@@ -1,27 +1,27 @@
|
|
1
|
-
// Convert from base 2 to base 10
|
2
|
-
// ---
|
3
|
-
// @param [number] $value: binary to convert
|
4
|
-
// ---
|
5
|
-
// @return [number]
|
6
|
-
// ---
|
7
|
-
@function binary-to-decimal($value) {
|
8
|
-
$value: $value + unquote('');
|
9
|
-
$result: if(str-slice($value, 1, 1) == "0", 0, 1);
|
10
|
-
|
11
|
-
@for $i from 2 through str-length($value) {
|
12
|
-
$c: str-slice($value, $i, $i);
|
13
|
-
|
14
|
-
@if not index("0" "1", $c) {
|
15
|
-
@warn "Not binary.";
|
16
|
-
@return false
|
17
|
-
}
|
18
|
-
|
19
|
-
$result: $result * 2;
|
20
|
-
|
21
|
-
@if $c == "1" {
|
22
|
-
$result: $result + 1
|
23
|
-
}
|
24
|
-
}
|
25
|
-
|
26
|
-
@return $result
|
27
|
-
}
|
1
|
+
// Convert from base 2 to base 10
|
2
|
+
// ---
|
3
|
+
// @param [number] $value: binary to convert
|
4
|
+
// ---
|
5
|
+
// @return [number]
|
6
|
+
// ---
|
7
|
+
@function binary-to-decimal($value) {
|
8
|
+
$value: $value + unquote('');
|
9
|
+
$result: if(str-slice($value, 1, 1) == "0", 0, 1);
|
10
|
+
|
11
|
+
@for $i from 2 through str-length($value) {
|
12
|
+
$c: str-slice($value, $i, $i);
|
13
|
+
|
14
|
+
@if not index("0" "1", $c) {
|
15
|
+
@warn "Not binary.";
|
16
|
+
@return false
|
17
|
+
}
|
18
|
+
|
19
|
+
$result: $result * 2;
|
20
|
+
|
21
|
+
@if $c == "1" {
|
22
|
+
$result: $result + 1
|
23
|
+
}
|
24
|
+
}
|
25
|
+
|
26
|
+
@return $result
|
27
|
+
}
|
@@ -1,24 +1,24 @@
|
|
1
|
-
// Convert from base 10 to base 2
|
2
|
-
// ---
|
3
|
-
// @param [number] $value: decimal to convert
|
4
|
-
// ---
|
5
|
-
// @return [number]
|
6
|
-
// ---
|
7
|
-
@function decimal-to-binary($value) {
|
8
|
-
$largest: largest-power-of-2($value);
|
9
|
-
$result: 0;
|
10
|
-
|
11
|
-
@while $largest >= 1 {
|
12
|
-
@if $value - $largest >= 0 {
|
13
|
-
$value: $value - $largest;
|
14
|
-
$result: $result * 10 + 1
|
15
|
-
}
|
16
|
-
@else {
|
17
|
-
$result: $result * 10
|
18
|
-
}
|
19
|
-
|
20
|
-
$largest: $largest / 2
|
21
|
-
}
|
22
|
-
|
23
|
-
@return $result
|
24
|
-
}
|
1
|
+
// Convert from base 10 to base 2
|
2
|
+
// ---
|
3
|
+
// @param [number] $value: decimal to convert
|
4
|
+
// ---
|
5
|
+
// @return [number]
|
6
|
+
// ---
|
7
|
+
@function decimal-to-binary($value) {
|
8
|
+
$largest: largest-power-of-2($value);
|
9
|
+
$result: 0;
|
10
|
+
|
11
|
+
@while $largest >= 1 {
|
12
|
+
@if $value - $largest >= 0 {
|
13
|
+
$value: $value - $largest;
|
14
|
+
$result: $result * 10 + 1
|
15
|
+
}
|
16
|
+
@else {
|
17
|
+
$result: $result * 10
|
18
|
+
}
|
19
|
+
|
20
|
+
$largest: $largest / 2
|
21
|
+
}
|
22
|
+
|
23
|
+
@return $result
|
24
|
+
}
|
@@ -1,16 +1,16 @@
|
|
1
|
-
// Returns largest power of 2 lesser than $value
|
2
|
-
// ---
|
3
|
-
// @param [number] $value: value
|
4
|
-
// ---
|
5
|
-
// @return [number]
|
6
|
-
// ---
|
7
|
-
@function largest-power-of-2($value) {
|
8
|
-
$result: 1;
|
9
|
-
@while $result <= $value {
|
10
|
-
@if $result * 2 > $value {
|
11
|
-
@return $result
|
12
|
-
}
|
13
|
-
$result: $result * 2
|
14
|
-
}
|
15
|
-
@return $result
|
16
|
-
}
|
1
|
+
// Returns largest power of 2 lesser than $value
|
2
|
+
// ---
|
3
|
+
// @param [number] $value: value
|
4
|
+
// ---
|
5
|
+
// @return [number]
|
6
|
+
// ---
|
7
|
+
@function largest-power-of-2($value) {
|
8
|
+
$result: 1;
|
9
|
+
@while $result <= $value {
|
10
|
+
@if $result * 2 > $value {
|
11
|
+
@return $result
|
12
|
+
}
|
13
|
+
$result: $result * 2
|
14
|
+
}
|
15
|
+
@return $result
|
16
|
+
}
|
@@ -0,0 +1,15 @@
|
|
1
|
+
// Order arguments decreasing
|
2
|
+
// ---
|
3
|
+
// @param [number] $x: first value
|
4
|
+
// @param [number] $y: second value
|
5
|
+
// ---
|
6
|
+
// @return [number]
|
7
|
+
// ---
|
8
|
+
@function order-args($x, $y) {
|
9
|
+
@if $x >= $y {
|
10
|
+
@return $x $y;
|
11
|
+
}
|
12
|
+
@else {
|
13
|
+
@return $y $x;
|
14
|
+
}
|
15
|
+
}
|
@@ -1,25 +1,25 @@
|
|
1
|
-
// Power function
|
2
|
-
// Using Compass if defined
|
3
|
-
// ---
|
4
|
-
// @param [number] $x: first value
|
5
|
-
// @param [number] $y: second value
|
6
|
-
// ---
|
7
|
-
// @return [number]
|
8
|
-
// ---
|
9
|
-
@function power($x, $y) {
|
10
|
-
@if function-exists('pow') == true {
|
11
|
-
@return pow($x, $y)
|
12
|
-
}
|
13
|
-
|
14
|
-
$ret: 1;
|
15
|
-
@if $y >= 0 {
|
16
|
-
@for $i from 1 through $y {
|
17
|
-
$ret: $ret * $x
|
18
|
-
}
|
19
|
-
} @else {
|
20
|
-
@for $i from $y to 0 {
|
21
|
-
$ret: $ret / $x
|
22
|
-
}
|
23
|
-
}
|
24
|
-
@return $ret
|
25
|
-
}
|
1
|
+
// Power function
|
2
|
+
// Using Compass if defined
|
3
|
+
// ---
|
4
|
+
// @param [number] $x: first value
|
5
|
+
// @param [number] $y: second value
|
6
|
+
// ---
|
7
|
+
// @return [number]
|
8
|
+
// ---
|
9
|
+
@function power($x, $y) {
|
10
|
+
@if function-exists('pow') == true {
|
11
|
+
@return pow($x, $y)
|
12
|
+
}
|
13
|
+
|
14
|
+
$ret: 1;
|
15
|
+
@if $y >= 0 {
|
16
|
+
@for $i from 1 through $y {
|
17
|
+
$ret: $ret * $x
|
18
|
+
}
|
19
|
+
} @else {
|
20
|
+
@for $i from $y to 0 {
|
21
|
+
$ret: $ret / $x
|
22
|
+
}
|
23
|
+
}
|
24
|
+
@return $ret
|
25
|
+
}
|
@@ -1,9 +1,9 @@
|
|
1
|
-
// Returns sign of $x
|
2
|
-
// ---
|
3
|
-
// @param [number] $x: value
|
4
|
-
// ---
|
5
|
-
// @return [number]
|
6
|
-
// ---
|
7
|
-
@function sign($x) {
|
8
|
-
@return if($x > 0, 1, if($x < 0, -1, 0))
|
9
|
-
}
|
1
|
+
// Returns sign of $x
|
2
|
+
// ---
|
3
|
+
// @param [number] $x: value
|
4
|
+
// ---
|
5
|
+
// @return [number]
|
6
|
+
// ---
|
7
|
+
@function sign($x) {
|
8
|
+
@return if($x > 0, 1, if($x < 0, -1, 0))
|
9
|
+
}
|
@@ -1,19 +1,22 @@
|
|
1
|
-
// `and` bitwise operator
|
2
|
-
// $x & $y
|
3
|
-
// ---
|
4
|
-
// @param [number] $x: first value
|
5
|
-
// @param [number] $y: second value
|
6
|
-
// ---
|
7
|
-
// @return [number]
|
8
|
-
// ---
|
9
|
-
@function bw-and($x, $y) {
|
10
|
-
$
|
11
|
-
$
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
}
|
1
|
+
// `and` bitwise operator
|
2
|
+
// $x & $y
|
3
|
+
// ---
|
4
|
+
// @param [number] $x: first value
|
5
|
+
// @param [number] $y: second value
|
6
|
+
// ---
|
7
|
+
// @return [number]
|
8
|
+
// ---
|
9
|
+
@function bw-and($x, $y) {
|
10
|
+
$args: order-args($x, $y);
|
11
|
+
$x: nth($args, 1);
|
12
|
+
$y: nth($args, 2);
|
13
|
+
$b: binary-length($x);
|
14
|
+
$res: 0;
|
15
|
+
|
16
|
+
@for $i from 0 through $b {
|
17
|
+
$h: power(2, $i);
|
18
|
+
$res: $res + $h * (floor($x / $h) % 2) * (floor($y / $h) % 2)
|
19
|
+
}
|
20
|
+
|
21
|
+
@return $res
|
22
|
+
}
|
@@ -1,10 +1,10 @@
|
|
1
|
-
// `not` bitwise operator
|
2
|
-
// ~ $x
|
3
|
-
// ---
|
4
|
-
// @param [number] $x: value
|
5
|
-
// ---
|
6
|
-
// @return [number]
|
7
|
-
// ---
|
8
|
-
@function bw-not($x) {
|
9
|
-
@return ($x + sign($x)) * -1
|
10
|
-
}
|
1
|
+
// `not` bitwise operator
|
2
|
+
// ~ $x
|
3
|
+
// ---
|
4
|
+
// @param [number] $x: value
|
5
|
+
// ---
|
6
|
+
// @return [number]
|
7
|
+
// ---
|
8
|
+
@function bw-not($x) {
|
9
|
+
@return ($x + sign($x)) * -1
|
10
|
+
}
|
@@ -1,21 +1,24 @@
|
|
1
|
-
// `or` bitwise operator
|
2
|
-
// $x | $y
|
3
|
-
// ---
|
4
|
-
// @param [number] $x: first value
|
5
|
-
// @param [number] $y: second value
|
6
|
-
// ---
|
7
|
-
// @return [number]
|
8
|
-
// ---
|
9
|
-
@function bw-or($x, $y) {
|
10
|
-
$
|
11
|
-
$
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
$
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
}
|
1
|
+
// `or` bitwise operator
|
2
|
+
// $x | $y
|
3
|
+
// ---
|
4
|
+
// @param [number] $x: first value
|
5
|
+
// @param [number] $y: second value
|
6
|
+
// ---
|
7
|
+
// @return [number]
|
8
|
+
// ---
|
9
|
+
@function bw-or($x, $y) {
|
10
|
+
$args: order-args($x, $y);
|
11
|
+
$x: nth($args, 1);
|
12
|
+
$y: nth($args, 2);
|
13
|
+
$b: binary-length($x);
|
14
|
+
$res: 0;
|
15
|
+
|
16
|
+
@for $i from 0 through $b {
|
17
|
+
$h: power(2, $i);
|
18
|
+
$tx: floor($x / $h) % 2;
|
19
|
+
$ty: floor($y / $h) % 2;
|
20
|
+
$res: $res + $h * (($tx + $ty + $tx * $ty % 2) % 2)
|
21
|
+
}
|
22
|
+
|
23
|
+
@return $res
|
24
|
+
}
|
@@ -1,11 +1,11 @@
|
|
1
|
-
// `<<` bitwise operator
|
2
|
-
// $x << $y
|
3
|
-
// ---
|
4
|
-
// @param [number] $x: first value
|
5
|
-
// @param [number] $y: second value
|
6
|
-
// ---
|
7
|
-
// @return [number]
|
8
|
-
// ---
|
9
|
-
@function bw-shift-left($x, $y) {
|
10
|
-
@return $x * power(2, $y)
|
11
|
-
}
|
1
|
+
// `<<` bitwise operator
|
2
|
+
// $x << $y
|
3
|
+
// ---
|
4
|
+
// @param [number] $x: first value
|
5
|
+
// @param [number] $y: second value
|
6
|
+
// ---
|
7
|
+
// @return [number]
|
8
|
+
// ---
|
9
|
+
@function bw-shift-left($x, $y) {
|
10
|
+
@return $x * power(2, $y)
|
11
|
+
}
|
@@ -1,11 +1,11 @@
|
|
1
|
-
// `>>` bitwise operator
|
2
|
-
// $x >> $y
|
3
|
-
// ---
|
4
|
-
// @param [number] $x: first value
|
5
|
-
// @param [number] $y: second value
|
6
|
-
// ---
|
7
|
-
// @return [number]
|
8
|
-
// ---
|
9
|
-
@function bw-shift-right($x, $y) {
|
10
|
-
@return floor($x / power(2, $y))
|
11
|
-
}
|
1
|
+
// `>>` bitwise operator
|
2
|
+
// $x >> $y
|
3
|
+
// ---
|
4
|
+
// @param [number] $x: first value
|
5
|
+
// @param [number] $y: second value
|
6
|
+
// ---
|
7
|
+
// @return [number]
|
8
|
+
// ---
|
9
|
+
@function bw-shift-right($x, $y) {
|
10
|
+
@return floor($x / power(2, $y))
|
11
|
+
}
|
@@ -1,19 +1,22 @@
|
|
1
|
-
// `xor` bitwise operator
|
2
|
-
// $x ^ $y
|
3
|
-
// ---
|
4
|
-
// @param [number] $x: first value
|
5
|
-
// @param [number] $y: second value
|
6
|
-
// ---
|
7
|
-
// @return [number]
|
8
|
-
// ---
|
9
|
-
@function bw-xor($x, $y) {
|
10
|
-
$
|
11
|
-
$
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
}
|
1
|
+
// `xor` bitwise operator
|
2
|
+
// $x ^ $y
|
3
|
+
// ---
|
4
|
+
// @param [number] $x: first value
|
5
|
+
// @param [number] $y: second value
|
6
|
+
// ---
|
7
|
+
// @return [number]
|
8
|
+
// ---
|
9
|
+
@function bw-xor($x, $y) {
|
10
|
+
$args: order-args($x, $y);
|
11
|
+
$x: nth($args, 1);
|
12
|
+
$y: nth($args, 2);
|
13
|
+
$b: binary-length($x);
|
14
|
+
$res: 0;
|
15
|
+
|
16
|
+
@for $i from 0 through $b {
|
17
|
+
$h: power(2, $i);
|
18
|
+
$res: $res + $h * (((floor($x / $h) % 2) + (floor($y / $h) % 2)) % 2)
|
19
|
+
}
|
20
|
+
|
21
|
+
@return $res
|
22
|
+
}
|
@@ -1,45 +1,45 @@
|
|
1
|
-
// Checks whether argument list is valid
|
2
|
-
// ---
|
3
|
-
// @param [list] $args: argument list
|
4
|
-
// ---
|
5
|
-
// @return [bool]
|
6
|
-
// ---
|
7
|
-
@function arguments-validator($args) {
|
8
|
-
$valid-operators: "^", "|", "&", "<<", ">>";
|
9
|
-
|
10
|
-
@if length($args) == 2 {
|
11
|
-
@if nth($args, 1) != "~" {
|
12
|
-
@warn "Only 2 arguments specified but first is not `~`.";
|
13
|
-
@return false;
|
14
|
-
}
|
15
|
-
|
16
|
-
@if not is-number(nth($args, 2)) {
|
17
|
-
@warn "Only 2 arguments specified but second is not a valid unitless number.";
|
18
|
-
@return false;
|
19
|
-
}
|
20
|
-
}
|
21
|
-
|
22
|
-
@else if length($args) == 3 {
|
23
|
-
@if not index($valid-operators, nth($args, 2)) {
|
24
|
-
@warn "Invalid operator: `#{nth($args, 2)}` given, one of #{inspect($valid-operators)} expected.";
|
25
|
-
@return false;
|
26
|
-
}
|
27
|
-
|
28
|
-
@if not is-number(nth($args, 1)) {
|
29
|
-
@warn "Invalid number as first argument: `#{nth($args, 1)} given, valid unitless number expected.";
|
30
|
-
@return false;
|
31
|
-
}
|
32
|
-
|
33
|
-
@if not is-number(nth($args, 3)) {
|
34
|
-
@warn "Invalid number as third argument: `#{nth($args, 3)} given, valid unitless number expected.";
|
35
|
-
@return false;
|
36
|
-
}
|
37
|
-
}
|
38
|
-
|
39
|
-
@else {
|
40
|
-
@warn "Invalid number of arguments: #{length($args)} given, 2 or 3 expected.";
|
41
|
-
@return false;
|
42
|
-
}
|
43
|
-
|
44
|
-
@return true;
|
45
|
-
}
|
1
|
+
// Checks whether argument list is valid
|
2
|
+
// ---
|
3
|
+
// @param [list] $args: argument list
|
4
|
+
// ---
|
5
|
+
// @return [bool]
|
6
|
+
// ---
|
7
|
+
@function arguments-validator($args) {
|
8
|
+
$valid-operators: "^", "|", "&", "<<", ">>";
|
9
|
+
|
10
|
+
@if length($args) == 2 {
|
11
|
+
@if nth($args, 1) != "~" {
|
12
|
+
@warn "Only 2 arguments specified but first is not `~`.";
|
13
|
+
@return false;
|
14
|
+
}
|
15
|
+
|
16
|
+
@if not is-number(nth($args, 2)) {
|
17
|
+
@warn "Only 2 arguments specified but second is not a valid unitless number.";
|
18
|
+
@return false;
|
19
|
+
}
|
20
|
+
}
|
21
|
+
|
22
|
+
@else if length($args) == 3 {
|
23
|
+
@if not index($valid-operators, nth($args, 2)) {
|
24
|
+
@warn "Invalid operator: `#{nth($args, 2)}` given, one of #{inspect($valid-operators)} expected.";
|
25
|
+
@return false;
|
26
|
+
}
|
27
|
+
|
28
|
+
@if not is-number(nth($args, 1)) {
|
29
|
+
@warn "Invalid number as first argument: `#{nth($args, 1)} given, valid unitless number expected.";
|
30
|
+
@return false;
|
31
|
+
}
|
32
|
+
|
33
|
+
@if not is-number(nth($args, 3)) {
|
34
|
+
@warn "Invalid number as third argument: `#{nth($args, 3)} given, valid unitless number expected.";
|
35
|
+
@return false;
|
36
|
+
}
|
37
|
+
}
|
38
|
+
|
39
|
+
@else {
|
40
|
+
@warn "Invalid number of arguments: #{length($args)} given, 2 or 3 expected.";
|
41
|
+
@return false;
|
42
|
+
}
|
43
|
+
|
44
|
+
@return true;
|
45
|
+
}
|
@@ -1,9 +1,9 @@
|
|
1
|
-
// Checks whether $value is valid number
|
2
|
-
// ---
|
3
|
-
// @param [number] $value
|
4
|
-
// ---
|
5
|
-
// @return [bool]
|
6
|
-
// ---
|
7
|
-
@function is-number($value) {
|
8
|
-
@return type-of($value) == "number" and unitless($value)
|
9
|
-
}
|
1
|
+
// Checks whether $value is valid number
|
2
|
+
// ---
|
3
|
+
// @param [number] $value
|
4
|
+
// ---
|
5
|
+
// @return [bool]
|
6
|
+
// ---
|
7
|
+
@function is-number($value) {
|
8
|
+
@return type-of($value) == "number" and unitless($value)
|
9
|
+
}
|
@@ -1,15 +1,16 @@
|
|
1
|
-
@import "SassyBitwise/helpers/power";
|
2
|
-
@import "SassyBitwise/helpers/sign";
|
3
|
-
@import "SassyBitwise/helpers/
|
4
|
-
@import "SassyBitwise/helpers/
|
5
|
-
@import "SassyBitwise/helpers/
|
6
|
-
@import "SassyBitwise/helpers/binary
|
7
|
-
@import "SassyBitwise/
|
8
|
-
@import "SassyBitwise/validators/
|
9
|
-
@import "SassyBitwise/
|
10
|
-
@import "SassyBitwise/operators/
|
11
|
-
@import "SassyBitwise/operators/
|
12
|
-
@import "SassyBitwise/operators/
|
13
|
-
@import "SassyBitwise/operators/
|
14
|
-
@import "SassyBitwise/operators/shift-
|
15
|
-
@import "SassyBitwise/
|
1
|
+
@import "SassyBitwise/helpers/power";
|
2
|
+
@import "SassyBitwise/helpers/sign";
|
3
|
+
@import "SassyBitwise/helpers/order-args";
|
4
|
+
@import "SassyBitwise/helpers/largest-power-of-2";
|
5
|
+
@import "SassyBitwise/helpers/binary-to-decimal";
|
6
|
+
@import "SassyBitwise/helpers/decimal-to-binary";
|
7
|
+
@import "SassyBitwise/helpers/binary-length";
|
8
|
+
@import "SassyBitwise/validators/is-number";
|
9
|
+
@import "SassyBitwise/validators/arguments-validator";
|
10
|
+
@import "SassyBitwise/operators/and";
|
11
|
+
@import "SassyBitwise/operators/not";
|
12
|
+
@import "SassyBitwise/operators/or";
|
13
|
+
@import "SassyBitwise/operators/xor";
|
14
|
+
@import "SassyBitwise/operators/shift-left";
|
15
|
+
@import "SassyBitwise/operators/shift-right";
|
16
|
+
@import "SassyBitwise/api/bitwise";
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: SassyBitwise
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Hugo Giraudel
|
@@ -47,11 +47,13 @@ extra_rdoc_files: []
|
|
47
47
|
files:
|
48
48
|
- CHANGELOG.md
|
49
49
|
- lib/SassyBitwise.rb
|
50
|
+
- stylesheets/_SassyBitwise.scss
|
50
51
|
- stylesheets/SassyBitwise/api/_bitwise.scss
|
51
52
|
- stylesheets/SassyBitwise/helpers/_binary-length.scss
|
52
53
|
- stylesheets/SassyBitwise/helpers/_binary-to-decimal.scss
|
53
54
|
- stylesheets/SassyBitwise/helpers/_decimal-to-binary.scss
|
54
55
|
- stylesheets/SassyBitwise/helpers/_largest-power-of-2.scss
|
56
|
+
- stylesheets/SassyBitwise/helpers/_order-args.scss
|
55
57
|
- stylesheets/SassyBitwise/helpers/_power.scss
|
56
58
|
- stylesheets/SassyBitwise/helpers/_sign.scss
|
57
59
|
- stylesheets/SassyBitwise/operators/_and.scss
|
@@ -62,7 +64,6 @@ files:
|
|
62
64
|
- stylesheets/SassyBitwise/operators/_xor.scss
|
63
65
|
- stylesheets/SassyBitwise/validators/_arguments-validator.scss
|
64
66
|
- stylesheets/SassyBitwise/validators/_is-number.scss
|
65
|
-
- stylesheets/_SassyBitwise.scss
|
66
67
|
homepage: http://github.com/HugoGiraudel/SassyBitwise
|
67
68
|
licenses: []
|
68
69
|
metadata: {}
|
@@ -82,7 +83,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
82
83
|
version: 1.3.6
|
83
84
|
requirements: []
|
84
85
|
rubyforge_project: SassyBitwise
|
85
|
-
rubygems_version: 2.
|
86
|
+
rubygems_version: 2.0.14
|
86
87
|
signing_key:
|
87
88
|
specification_version: 4
|
88
89
|
summary: An implementation of bitwise operators in Sass without the use of Ruby.
|