java 8 port of Underscore.js

The java 8 port of Underscore.js

License

License

GroupId

GroupId

com.github.javadev
ArtifactId

ArtifactId

underscore8
Last Version

Last Version

1.30
Release Date

Release Date

Type

Type

jar
Description

Description

java 8 port of Underscore.js
The java 8 port of Underscore.js
Project URL

Project URL

https://github.com/javadev/underscore-java8
Source Code Management

Source Code Management

https://github.com/javadev/underscore-java8

Download underscore8

How to add to project

<!-- https://jarcasting.com/artifacts/com.github.javadev/underscore8/ -->
<dependency>
    <groupId>com.github.javadev</groupId>
    <artifactId>underscore8</artifactId>
    <version>1.30</version>
</dependency>
// https://jarcasting.com/artifacts/com.github.javadev/underscore8/
implementation 'com.github.javadev:underscore8:1.30'
// https://jarcasting.com/artifacts/com.github.javadev/underscore8/
implementation ("com.github.javadev:underscore8:1.30")
'com.github.javadev:underscore8:jar:1.30'
<dependency org="com.github.javadev" name="underscore8" rev="1.30">
  <artifact name="underscore8" type="jar" />
</dependency>
@Grapes(
@Grab(group='com.github.javadev', module='underscore8', version='1.30')
)
libraryDependencies += "com.github.javadev" % "underscore8" % "1.30"
[com.github.javadev/underscore8 "1.30"]

Dependencies

test (2)

Group / Artifact Type Version
junit : junit jar 4.13.1
org.awaitility : awaitility jar 4.0.3

Project Modules

There are no modules declared in this project.

underscore-java8

Maven Central MIT License Build Status Run Status codecov Quality Gate Quality Gate Build Status Java Version

Requirements

Java 1.8 and later.

Installation

Include the following in your pom.xml for Maven:

<dependencies>
  <dependency>
    <groupId>com.github.javadev</groupId>
    <artifactId>underscore8</artifactId>
    <version>1.30</version>
  </dependency>
  ...
</dependencies>

Gradle:

compile 'com.github.javadev:underscore8:1.30'

Underscore-java is a java port of Underscore.js.

Usage

U.chain(/* array | list | set | map | anything based on Iterable interface */)
    .filter(..)
    .map(..)
    ...
    .sortWith()
    .forEach(..);
U.chain(value1, value2, value3)...
U.range(0, 10)...

U.chain(1, 2, 3) // or java.util.Arrays.asList(1, 2, 3) or new Integer[] {1, 2, 3}
    .filter(v -> v > 1)
    // 2, 3
    .map(v -> v + 1)
    // 3, 4
    .sortWith((a, b) -> b.compareTo(a))
    // 4, 3
    .forEach(System.out::println);
    // 4, 3
    
U.formatXml("<a><b>data</b></a>");
    // <a>
    //    <b>data</b>
    // </a>

U.formatJson("{\"a\":{\"b\":\"data\"}}");
    // {
    //    "a": {
    //      "b": "data"
    //    }
    // }

U.xmlToJson("<a><b>data</b></a>");
    // {
    //   "a": {
    //     "b": "data"
    //   },
    //   "#omit-xml-declaration": "yes"
    // }

U.jsonToXml("{\"a\":{\"b\":\"data\"}}");
    // <?xml version="1.0" encoding="UTF-8"?>
    // <a>
    //   <b>data</b>
    // </a>
    
Map<String, Object> value = U.objectBuilder()
    .add("firstName", "John")
    .add("lastName", "Smith")
    .add("age", 25)
    .add("address", U.arrayBuilder()
        .add(U.objectBuilder()
            .add("streetAddress", "21 2nd Street")
            .add("city", "New York")
            .add("state", "NY")
            .add("postalCode", "10021")))
    .add("phoneNumber", U.arrayBuilder()
        .add(U.objectBuilder()
            .add("type", "home")
            .add("number", "212 555-1234"))
        .add(U.objectBuilder()
            .add("type", "fax")
            .add("number", "646 555-4567")))
    .build();
    // {firstName=John, lastName=Smith, age=25, address=[{streetAddress=21 2nd Street,
    // city=New York, state=NY, postalCode=10021}], phoneNumber=[{type=home, number=212 555-1234},
    // {type=fax, number=646 555-4567}]}

In addition to porting Underscore's functionality, Underscore-java includes matching unit tests.

For docs, license, tests, and downloads, see: https://javadev.github.io/underscore-java

Thanks to Jeremy Ashkenas and all contributors to Underscore.js.

Versions

Version
1.30
1.29
1.28
1.27
1.26
1.25
1.24
1.23
1.22
1.21
1.20
1.19
1.18
1.16
1.15
1.14
1.13
1.12
1.11
1.10
1.9
1.8
1.7
1.6
1.5
1.4
1.3
1.2
1.1
1.0