Sha256: c9aa340885a696e6c3a9a42089d6d43849bb78d16820d9b805ceb552cfa236aa

Contents?: true

Size: 1.06 KB

Versions: 24

Compression:

Stored size: 1.06 KB

Contents

var OMIT_PLUSSIGN = /^(?:\+|(-))?0*(\d*)(?:\.0*|(\.\d*?)0*)?$/;
var KEEP_PLUSSIGN = /^([\+\-])?0*(\d*)(?:\.0*|(\.\d*?)0*)?$/;
var unsafeToRemovePlusSignAfter = {
    Dimension: true,
    HexColor: true,
    Identifier: true,
    Number: true,
    Raw: true,
    UnicodeRange: true
};

function packNumber(value, item) {
    // omit plus sign only if no prev or prev is safe type
    var regexp = item && item.prev !== null && unsafeToRemovePlusSignAfter.hasOwnProperty(item.prev.data.type)
        ? KEEP_PLUSSIGN
        : OMIT_PLUSSIGN;

    // 100 -> '100'
    // 00100 -> '100'
    // +100 -> '100' (only when safe, e.g. omitting plus sign for 1px+1px leads to single dimension instead of two)
    // -100 -> '-100'
    // 0.123 -> '.123'
    // 0.12300 -> '.123'
    // 0.0 -> ''
    // 0 -> ''
    // -0 -> '-'
    value = String(value).replace(regexp, '$1$2$3');

    if (value === '' || value === '-') {
        value = '0';
    }

    return value;
}

module.exports = function(node, item) {
    node.value = packNumber(node.value, item);
};
module.exports.pack = packNumber;

Version data entries

24 entries across 24 versions & 7 rubygems

Version Path
optimacms-0.1.61 spec/dummy/node_modules/csso/lib/replace/Number.js
disco_app-0.18.0 test/dummy/node_modules/csso/lib/replace/Number.js
disco_app-0.18.2 test/dummy/node_modules/csso/lib/replace/Number.js
disco_app-0.16.1 test/dummy/node_modules/csso/lib/replace/Number.js
disco_app-0.15.2 test/dummy/node_modules/csso/lib/replace/Number.js
disco_app-0.18.4 test/dummy/node_modules/csso/lib/replace/Number.js
disco_app-0.18.1 test/dummy/node_modules/csso/lib/replace/Number.js
disco_app-0.12.7.pre.puma.pre.3 test/dummy/node_modules/csso/lib/replace/Number.js
disco_app-0.14.0 test/dummy/node_modules/csso/lib/replace/Number.js
disco_app-0.13.6.pre.puma.pre.3 test/dummy/node_modules/csso/lib/replace/Number.js
tang-0.2.1 spec/tang_app/node_modules/csso/lib/replace/Number.js
tang-0.2.0 spec/tang_app/node_modules/csso/lib/replace/Number.js
tang-0.1.0 spec/tang_app/node_modules/csso/lib/replace/Number.js
tang-0.0.9 spec/tang_app/node_modules/csso/lib/replace/Number.js
enju_library-0.3.8 spec/dummy/node_modules/csso/lib/replace/Number.js
jester-data-8.0.0 node_modules/csso/lib/replace/Number.js
ezii-os-5.2.1 node_modules/csso/lib/replace/Number.js
ezii-os-2.0.1 node_modules/csso/lib/replace/Number.js
ezii-os-1.1.0 node_modules/csso/lib/replace/Number.js
ezii-os-1.0.0 node_modules/csso/lib/replace/Number.js