perfolation-macros


License

License

MIT
Categories

Categories

Native Development Tools
GroupId

GroupId

com.outr
ArtifactId

ArtifactId

perfolation-macros_native0.3_2.11
Last Version

Last Version

1.1.5
Release Date

Release Date

Type

Type

jar
Description

Description

perfolation-macros
perfolation-macros
Project URL

Project URL

https://github.com/outr/perfolation
Project Organization

Project Organization

com.outr
Source Code Management

Source Code Management

https://github.com/outr/perfolation

Download perfolation-macros_native0.3_2.11

How to add to project

<!-- https://jarcasting.com/artifacts/com.outr/perfolation-macros_native0.3_2.11/ -->
<dependency>
    <groupId>com.outr</groupId>
    <artifactId>perfolation-macros_native0.3_2.11</artifactId>
    <version>1.1.5</version>
</dependency>
// https://jarcasting.com/artifacts/com.outr/perfolation-macros_native0.3_2.11/
implementation 'com.outr:perfolation-macros_native0.3_2.11:1.1.5'
// https://jarcasting.com/artifacts/com.outr/perfolation-macros_native0.3_2.11/
implementation ("com.outr:perfolation-macros_native0.3_2.11:1.1.5")
'com.outr:perfolation-macros_native0.3_2.11:jar:1.1.5'
<dependency org="com.outr" name="perfolation-macros_native0.3_2.11" rev="1.1.5">
  <artifact name="perfolation-macros_native0.3_2.11" type="jar" />
</dependency>
@Grapes(
@Grab(group='com.outr', module='perfolation-macros_native0.3_2.11', version='1.1.5')
)
libraryDependencies += "com.outr" % "perfolation-macros_native0.3_2.11" % "1.1.5"
[com.outr/perfolation-macros_native0.3_2.11 "1.1.5"]

Dependencies

compile (6)

Group / Artifact Type Version
org.scala-lang : scala-library jar 2.11.12
org.scala-native : nativelib_native0.3_2.11 jar 0.3.8
org.scala-native : javalib_native0.3_2.11 jar 0.3.8
org.scala-native : auxlib_native0.3_2.11 jar 0.3.8
org.scala-native : scalalib_native0.3_2.11 jar 0.3.8
org.scala-lang : scala-reflect jar 2.11.12

test (1)

Group / Artifact Type Version
org.scala-native : test-interface_native0.3_2.11 jar 0.3.8

Project Modules

There are no modules declared in this project.

perfolation

Build Status Gitter Maven Central Latest version

Originally designed for interpolation performance improvements, but as Scala's built-in interpolation has improved, this has become redundant. However, formatted interpolation is still both slow and painful to work with. To that end, this library has changed to providing convenient features for formatting dates and numbers.

Setup

Perfolation supports Scala on JVM, JS, and Native with support for 2.11, 2.12, 2.13, and 3

Load the core dependency with SBT:

libraryDependencies += "com.outr" %% "perfolation" % "1.2.5"

Or the unit dependency for size conversions with SBT:

libraryDependencies += "com.outr" %% "perfolation-unit" % "1.2.5"

Main Features

Numeric Formatting

Numeric implicits are supported for Int, Long, Double, and BigDecimal exposing a simple method f:

def f(i: Int,               // Minimum integer digits. Defaults to 1
      f: Int = 0,           // Minimum fraction digits. Defaults to 0 for Int/Long and 2 for Double/BigDecimal 
      maxI: Int,            // Maximum integer digits. Defaults to -1 for no maximum
      maxF: Int,            // Maximum fraction digits. Defaults to -1 to use the same as `f`
      g: Grouping,          // Grouping mode (Defaults to Grouping.None)
      rm: RoundingMode      // Rounding mode (Defaults to RoundingMode.HalfUp)
     ): String

Some simple examples:

import perfolation._

4.f(i = 2)                            // 04
40.f(f = 2)                           // 40.00
400.0.f()                             // 400.00
4000.0.f(f = 3, g = Grouping.US)      // 4,000.000

Most of this follows a similar concept to f interpolation, but with a type-safe mechanism. Most commonly, you are likely to find this useful in interpolations like:

println(s"The value is: ${value.f(g = Grouping.US)}")

Date Formatting

Perfolation provides a convenient CrossDate to make working with dates much easier between the JVM, JS, and Native. Similar to numeric formatting, date implicits are supported for Int, Long, Double, and BigDecimal although this is most commonly just used on Long for timestamps. Perfolation exposes a simple method t:

def t: CrossDate

Some simple examples:

import perfolation._

val date = System.currentTimeMillis()
date.t.milliseconds                 // Milliseconds on date
date.t.hour24                       // Hour in 24-hour time
date.t.dayOfWeek                    // Numeric day of the week
date.t.A                            // Full named day of the week (ex. "Tuesday")

See the docs for CrossDate for a complete reference.

Unit Formatting

Unit formatting requires the perfolation-unit module, but provides conversion between byte-based sizes. For example:

import perfolation.unit._

Information.useBinary()       // Configure Information to use binary conversions
5.kb.bytes                    // 5120L
5.gb.bytes                    // 5368709120L

Information.useDecimal()      // Configure Information to use decimal conversions
5.kb.bytes                    // 5000L
5.gb.bytes                    // 5000000000L

(5 * 1000 * 1000).b.format()  // "5.00 mb"

The format method has a similar signature to that of f in numeric formatting:

def format(i: Int = 1,
           f: Int = 2,
           maxI: Int = -1,
           maxF: Int = -1,
           g: Grouping = Grouping.None,
           rm: RoundingMode = RoundingMode.HalfUp,
           showUnit: ShowUnit = ShowUnit.Abbreviation): String
com.outr

OUTR Technologies

Versions

Version
1.1.5
1.1.4
1.1.3
1.1.2
1.1.1
1.1.0
1.0.4
1.0.3
1.0.2
1.0.1
1.0.0