type-checking stylesheet functions

is-string, is-keyword, is-color, is-number
This commit is contained in:
Alexis Sellier
2012-01-03 18:45:31 +01:00
parent 77c8df029b
commit 5ec708c3f4
4 changed files with 35 additions and 0 deletions

View File

@@ -174,6 +174,21 @@ tree.functions = {
} else {
throw { type: "Argument", message: "argument must be a string" };
}
},
'is-color': function (n) {
return this._isa(n, tree.Color);
},
'is-number': function (n) {
return this._isa(n, tree.Dimension);
},
'is-string': function (n) {
return this._isa(n, tree.Quoted);
},
'is-keyword': function (n) {
return this._isa(n, tree.Keyword);
},
_isa: function (n, Type) {
return (n instanceof Type) ? tree.True : tree.False;
}
};

View File

@@ -13,4 +13,7 @@ tree.Keyword.prototype = {
}
};
tree.True = new(tree.Keyword)('true');
tree.False = new(tree.Keyword)('false');
})(require('../tree'));