Sha256: e50ae553cbf72fea50f38e15b0e2f3f834a8e71206ddfee768506f18ae37209d

Contents?: true

Size: 1023 Bytes

Versions: 20

Compression:

Stored size: 1023 Bytes

Contents

// An @int node is any literal integer in Ruby. They can come in a number of
// bases, and look like the following:
//
// Binary (2)       - 0b0110
// Octal (8)        - 0o34 or 034
// Decimal (10)     - a normal number like 159
// Hexidecimal (16) - 0xac5
//
// If it's a decimal number, it can be optional separated by any number of
// arbitrarily places underscores. This can be useful for dollars and cents
// (34_99), dates (2020_11_30), and normal 3 digit separation (1_222_333).
function printInt(path, _opts, _print) {
  const { body } = path.getValue();

  // If the number is a base 10 number, is sufficiently large, and is not
  // already formatted with underscores, then add them in in between the
  // numbers every three characters starting from the right.
  if (!body.startsWith("0") && body.length >= 5 && !body.includes("_")) {
    return `  ${body}`
      .slice((body.length + 2) % 3)
      .match(/.{3}/g)
      .join("_")
      .trim();
  }

  return body;
}

module.exports = {
  "@int": printInt
};

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
prettier-1.6.1 src/ruby/nodes/ints.js
prettier-1.6.0 src/ruby/nodes/ints.js
prettier-1.5.5 src/ruby/nodes/ints.js
prettier-1.5.4 src/ruby/nodes/ints.js
prettier-1.5.3 src/ruby/nodes/ints.js
prettier-1.5.2 src/ruby/nodes/ints.js
prettier-1.5.1 src/ruby/nodes/ints.js
prettier-1.5.0 src/ruby/nodes/ints.js
prettier-1.4.0 src/ruby/nodes/ints.js
prettier-1.3.0 src/ruby/nodes/ints.js
prettier-1.2.5 src/ruby/nodes/ints.js
prettier-1.2.4 src/ruby/nodes/ints.js
prettier-1.2.3 src/ruby/nodes/ints.js
prettier-1.2.2 src/nodes/ints.js
prettier-1.2.1 src/nodes/ints.js
prettier-1.2.0 src/nodes/ints.js
prettier-1.1.0 src/nodes/ints.js
prettier-1.0.1 src/nodes/ints.js
prettier-1.0.0 src/nodes/ints.js
prettier-1.0.0.pre.rc2 src/nodes/ints.js