source: trip-planner-front/node_modules/csso/lib/replace/Number.js

Last change on this file was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 1.1 KB
Line 
1var OMIT_PLUSSIGN = /^(?:\+|(-))?0*(\d*)(?:\.0*|(\.\d*?)0*)?$/;
2var KEEP_PLUSSIGN = /^([\+\-])?0*(\d*)(?:\.0*|(\.\d*?)0*)?$/;
3var unsafeToRemovePlusSignAfter = {
4 Dimension: true,
5 Hash: true,
6 Identifier: true,
7 Number: true,
8 Raw: true,
9 UnicodeRange: true
10};
11
12function packNumber(value, item) {
13 // omit plus sign only if no prev or prev is safe type
14 var regexp = item && item.prev !== null && unsafeToRemovePlusSignAfter.hasOwnProperty(item.prev.data.type)
15 ? KEEP_PLUSSIGN
16 : OMIT_PLUSSIGN;
17
18 // 100 -> '100'
19 // 00100 -> '100'
20 // +100 -> '100' (only when safe, e.g. omitting plus sign for 1px+1px leads to single dimension instead of two)
21 // -100 -> '-100'
22 // 0.123 -> '.123'
23 // 0.12300 -> '.123'
24 // 0.0 -> ''
25 // 0 -> ''
26 // -0 -> '-'
27 value = String(value).replace(regexp, '$1$2$3');
28
29 if (value === '' || value === '-') {
30 value = '0';
31 }
32
33 return value;
34}
35
36module.exports = function(node, item) {
37 node.value = packNumber(node.value, item);
38};
39module.exports.pack = packNumber;
Note: See TracBrowser for help on using the repository browser.