Download pool/shard001/JavaScript/0006062_dimension.js from Variable-role/sajaniemi_variable_dataset_large: direct link, hf CLI and curl.
- Browser
- Download file 1.26 kB
-
https://huggingface.co/datasets/Variable-role/sajaniemi_variable_dataset_large/resolve/main/pool/shard001/JavaScript/0006062_dimension.js
- Command line
-
hf download hf://datasets/Variable-role/sajaniemi_variable_dataset_large/pool/shard001/JavaScript/0006062_dimension.js
-
curl -L -o 0006062_dimension.js https://huggingface.co/datasets/Variable-role/sajaniemi_variable_dataset_large/resolve/main/pool/shard001/JavaScript/0006062_dimension.js
1.26 kB
| (function (tree) { | |
| // | |
| // A number with a unit | |
| // | |
| tree.Dimension = function (value, unit) { | |
| this.value = parseFloat(value); | |
| this.unit = unit || null; | |
| }; | |
| tree.Dimension.prototype = { | |
| eval: function () { return this }, | |
| toColor: function () { | |
| return new(tree.Color)([this.value, this.value, this.value]); | |
| }, | |
| toCSS: function () { | |
| var css = this.value + this.unit; | |
| return css; | |
| }, | |
| // In an operation between two Dimensions, | |
| // we default to the first Dimension's unit, | |
| // so `1px + 2em` will yield `3px`. | |
| // In the future, we could implement some unit | |
| // conversions such that `100cm + 10mm` would yield | |
| // `101cm`. | |
| operate: function (op, other) { | |
| return new(tree.Dimension) | |
| (tree.operate(op, this.value, other.value), | |
| this.unit || other.unit); | |
| }, | |
| // TODO: Perform unit conversion before comparing | |
| compare: function (other) { | |
| if (other instanceof tree.Dimension) { | |
| if (other.value > this.value) { | |
| return -1; | |
| } else if (other.value < this.value) { | |
| return 1; | |
| } else { | |
| return 0; | |
| } | |
| } | |
| } | |
| }; | |
| })(require('../tree')); | |