Skip to content

Commit

Permalink
v.2.0.1 scala-js
Browse files Browse the repository at this point in the history
  • Loading branch information
gekomad committed Nov 14, 2024
1 parent d11cc02 commit 3ebb885
Show file tree
Hide file tree
Showing 13 changed files with 773 additions and 643 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@ dist
ojdbc6.jar
.pid
.attach_pid*
.bsp/
11 changes: 8 additions & 3 deletions .scalafmt.conf
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
style = defaultWithAlign
version = 3.8.3

runner.dialect = scala3

style = defaultWithAlign
maxColumn = 200
align.openParenDefnSite = false
continuationIndent.callSite = 2
continuationIndent.defnSite = 2
align.openParenCallSite = false
danglingParentheses = true
optIn.configStyleArguments = false

project.excludeFilters = ["target/"]
project.git = true
81 changes: 52 additions & 29 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@ Scala regex collection
=====================

Scala-regex-collection is a pure scala regex collection

## Add the library to your project

The latest version of the library is available for Scala 2.12, 2.13 and 3.0.
The latest version of the library is available for Scala 2.12, 2.13, 3 and ScalaJS.

`libraryDependencies += "com.github.gekomad" %% "scala-regex-collection" % "2.0.0"`
`libraryDependencies += "com.github.gekomad" %% "scala-regex-collection" % "2.0.1"`

## Using Library
## Using Library

### Patterns

Expand All @@ -28,16 +29,20 @@ Ciphers
- [UUID](https://github.com/gekomad/scala-regex-collection/wiki/UUID) (1CC3CCBB-C749-3078-E050-1AACBE064651)
- [MD5](https://github.com/gekomad/scala-regex-collection/wiki/MD5) (23f8e84c1f4e7c8814634267bd456194)
- [SHA1](https://github.com/gekomad/scala-regex-collection/wiki/SHA1) (1c18da5dbf74e3fc1820469cf1f54355b7eec92d)
- [SHA256](https://github.com/gekomad/scala-regex-collection/wiki/SHA256) (000020f89134d831f48541b2d8ec39397bc99fccf4cc86a3861257dbe6d819d1)
- [SHA256](https://github.com/gekomad/scala-regex-collection/wiki/SHA256) (
000020f89134d831f48541b2d8ec39397bc99fccf4cc86a3861257dbe6d819d1)

URL, IP, MAC Address

- [IP](https://github.com/gekomad/scala-regex-collection/wiki/IP) (10.192.168.1)
- [IP_6](https://github.com/gekomad/scala-regex-collection/wiki/IP_6) (2001:db8:a0b:12f0::1)
- [URLs](https://github.com/gekomad/scala-regex-collection/wiki/URLs) (http://</span>abc.def</span>.com)
- [Youtube](https://github.com/gekomad/scala-regex-collection/wiki/Youtube) (https://</span>www</span>.youtube</span>.com/watch?v=9bZkp7q19f0)
- [Facebook](https://github.com/gekomad/scala-regex-collection/wiki/Facebook) (https://</span>www</span>.facebook.</span>com/thesimpsons - https://</span>www</span>.facebook.</span>com/pages/)
- [Twitter](https://github.com/gekomad/scala-regex-collection/wiki/Twitter) (https://</span>twitter</span>.com/rtpharry)
- [Youtube](https://github.com/gekomad/scala-regex-collection/wiki/Youtube) (https://</span>www</span>.youtube</span>
.com/watch?v=9bZkp7q19f0)
- [Facebook](https://github.com/gekomad/scala-regex-collection/wiki/Facebook) (https://</span>www</span>
.facebook.</span>com/thesimpsons - https://</span>www</span>.facebook.</span>com/pages/)
- [Twitter](https://github.com/gekomad/scala-regex-collection/wiki/Twitter) (https://</span>twitter</span>
.com/rtpharry)
- [MAC Address](https://github.com/gekomad/scala-regex-collection/wiki/MACAddress) (fE:dC:bA:98:76:54)

HEX
Expand All @@ -46,13 +51,17 @@ HEX

Bitcoin

- [Bitcon Address](https://github.com/gekomad/scala-regex-collection/wiki/Bitcon-Address) (3Nxwenay9Z8Lc9JBiywExpnEFiLp6Afp8v)
- [Bitcon Address](https://github.com/gekomad/scala-regex-collection/wiki/Bitcon-Address) (
3Nxwenay9Z8Lc9JBiywExpnEFiLp6Afp8v)

Phone numbers

- [US phone number](https://github.com/gekomad/scala-regex-collection/wiki/US-phone-number) (555-555-5555 - (416)555-3456)
- [Italian Mobile Phone](https://github.com/gekomad/scala-regex-collection/wiki/ItalianMobilePhone) (+393471234561 - 3381234561)
- [Italian Phone](https://github.com/gekomad/scala-regex-collection/wiki/ItalianPhone) (02 645566 - 02/583725 - 02-583725)
- [US phone number](https://github.com/gekomad/scala-regex-collection/wiki/US-phone-number) (555-555-5555 - (416)
555-3456)
- [Italian Mobile Phone](https://github.com/gekomad/scala-regex-collection/wiki/ItalianMobilePhone) (+393471234561 -
3381234561)
- [Italian Phone](https://github.com/gekomad/scala-regex-collection/wiki/ItalianPhone) (02 645566 - 02/583725 -
02-583725)

Date time

Expand Down Expand Up @@ -81,19 +90,22 @@ Codes

- [Italian fiscal code](https://github.com/gekomad/scala-regex-collection/wiki/Italian-fiscal-code) (BDAPPP14A01A001R)
- [Italian VAT code](https://github.com/gekomad/scala-regex-collection/wiki/ItalianVAT) (13297040362)
- [Italian Iban](https://github.com/gekomad/scala-regex-collection/wiki/ItalianIban) (IT28 W800 0000 2921 0064 5211 151 - IT28W8000000292100645211151)
- [Italian Iban](https://github.com/gekomad/scala-regex-collection/wiki/ItalianIban) (IT28 W800 0000 2921 0064 5211
151 - IT28W8000000292100645211151)
- [US states](https://github.com/gekomad/scala-regex-collection/wiki/USstates) (FL - CA)
- [US states1](https://github.com/gekomad/scala-regex-collection/wiki/USstates1) (Connecticut - Colorado)
- [US zip code](https://github.com/gekomad/scala-regex-collection/wiki/USZipCode) (43802)
- [US streets](https://github.com/gekomad/scala-regex-collection/wiki/USStreets) (123 Park Ave Apt 123 New York City, NY 10002)
- [US streets](https://github.com/gekomad/scala-regex-collection/wiki/USStreets) (123 Park Ave Apt 123 New York City,
NY 10002)
- [US street numbers](https://github.com/gekomad/scala-regex-collection/wiki/USStreetNumber) (P.O. Box 432)
- [Italian zip code](https://github.com/gekomad/scala-regex-collection/wiki/ItalianZipCode) (23887)
- [German streets](https://github.com/gekomad/scala-regex-collection/wiki/GermanStreet) (Mühlenstr. 33)

Concurrency

- [USD Currency](https://github.com/gekomad/scala-regex-collection/wiki/USD-Currency) ($1.00 - 1,500.00)
- [EUR Currency](https://github.com/gekomad/scala-regex-collection/wiki/EurCurrency) (0,00 € - 133,89 EUR - 133,89 EURO)
- [EUR Currency](https://github.com/gekomad/scala-regex-collection/wiki/EurCurrency) (0,00 € - 133,89 EUR - 133,89
EURO)
- [YEN Currency](https://github.com/gekomad/scala-regex-collection/wiki/YenCurrency) (¥1.00 - 15.00 - ¥-1213,120.00)

Strings
Expand All @@ -106,7 +118,8 @@ Strings

Logs

- [Apache error](https://github.com/gekomad/scala-regex-collection/wiki/ApacheError) ([Fri Dec 16 02:25:55 2005] [error] [client 1.2.3.4] Client sent malformed Host header)
- [Apache error](https://github.com/gekomad/scala-regex-collection/wiki/ApacheError) ([Fri Dec 16 02:25:55 2005] [error] [client 1.2.3.4]
Client sent malformed Host header)

Numbers

Expand All @@ -123,7 +136,8 @@ Coordinates

- [Coordinate](https://github.com/gekomad/scala-regex-collection/wiki/Coordinate) (N90.00.00 E180.00.00)
- [Coordinate1](https://github.com/gekomad/scala-regex-collection/wiki/Coordinate1) (45°23'36.0" N 10°33'48.0" E)
- [Coordinate2](https://github.com/gekomad/scala-regex-collection/wiki/Coordinate2) (12:12:12.223546"N - 15:17:6"S - 12°30'23.256547"S)
- [Coordinate2](https://github.com/gekomad/scala-regex-collection/wiki/Coordinate2) (12:12:12.223546"N - 15:17:6"S -
12°30'23.256547"S)

Programming

Expand All @@ -138,12 +152,13 @@ Credit Cards
- [Discover](https://github.com/gekomad/scala-regex-collection/wiki/CreditCards) (/* 6011000000000004 */)
- [JCB](https://github.com/gekomad/scala-regex-collection/wiki/CreditCards) (/* 3588000000000009 */)

## Use the library

## Use the library

### Validate String
Returns Option[String] with the matched string
```

Returns `Option[String]` with the matched string

```scala
import com.github.gekomad.regexcollection._
import com.github.gekomad.regexcollection.Validate.validate
import java.time.LocalDateTime
Expand All @@ -155,8 +170,10 @@ assert(validate[LocalDateTime]("2000-12-31T11:21:19") == Some("2000-12-31T11:21:
```

### findAll

Example extracting all emails from a string
```

```scala
import com.github.gekomad.regexcollection.Email
import com.github.gekomad.regexcollection.Validate.findAll

Expand All @@ -166,8 +183,10 @@ assert(findAll[Email]("ddddd") == List())
```

### findFirst

Example extracting first email from a string
```

```scala
trait Bar
import com.github.gekomad.regexcollection.Validate.findFirst
import com.github.gekomad.regexcollection.Validate.findFirstIgnoreCase
Expand All @@ -179,8 +198,10 @@ assert(findFirst[Bar]("bar abc@google.com hi hello Bar@yahoo.com 123 bar@foo.com
```

### Get pattern

Returns the current pattern used for that type, for example for Email type:
```

```scala
import com.github.gekomad.regexcollection.Email
import com.github.gekomad.regexcollection.Validate.regexp

Expand All @@ -191,7 +212,7 @@ assert(regexp[Email] == """[a-zA-Z0-9\.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA

It's possible modify the default pattern for all types, example for Email

```
```scala
import com.github.gekomad.regexcollection.Email
import com.github.gekomad.regexcollection.Validate.validate
import com.github.gekomad.regexcollection.Collection.Validator
Expand All @@ -209,7 +230,8 @@ assert(validate[Email](email) == Some("abc,a@%.d"))
### Matching your own type

Defining a pattern for Bar type
```

```scala
trait Bar

import com.github.gekomad.regexcollection.Validate.validate
Expand All @@ -230,8 +252,7 @@ assert(validateIgnoreCase[Bar]("bar foo") == Some("bar foo"))

Retrieve all emails using findAll and findAllCaseSensitive


```
```scala
trait Bar
import com.github.gekomad.regexcollection.Collection.Validator
import com.github.gekomad.regexcollection.Validate._
Expand All @@ -250,7 +271,7 @@ Instead of using a regular expression to match a string it's possible defining a

Example matching even numbers

```
```scala
trait Foo

import com.github.gekomad.regexcollection.Validate.validate
Expand All @@ -273,7 +294,9 @@ assert(validate[Foo]("hello") == None)
```

## Bugs and Feedback
For bugs, questions and discussions please use [Github Issues](https://github.com/gekomad/scala-regex-collection/issues).

For bugs, questions and discussions please
use [Github Issues](https://github.com/gekomad/scala-regex-collection/issues).

## License

Expand Down
35 changes: 30 additions & 5 deletions build.sbt
Original file line number Diff line number Diff line change
@@ -1,12 +1,37 @@
name := "scala-regex-collection"

version := "2.0.0"
version := "2.0.1"

scalaVersion := "3.0.0"
scalaVersion := "3.5.2"
organization := "com.github.gekomad"

libraryDependencies += "org.typelevel" %% "discipline-scalatest" % "2.1.5" % Test
libraryDependencies += "org.scalameta" %% "munit" % "1.0.2" % Test
scalacOptions ++= Seq("-Xfatal-warnings")
crossScalaVersions := Seq("2.12.20", "2.13.15", "3.5.2")

crossScalaVersions := Seq("2.12.8", "2.13.5", "3.0.0")

publishTo := sonatypePublishTo.value
//sonatype

publishTo := sonatypePublishToBundle.value
logLevel := Level.Debug

pomExtra :=
<licenses>
<license>
<name>Apache 2</name>
<url>https://www.apache.org/licenses/LICENSE-2.0.txt</url>
<distribution>repo</distribution>
</license>
</licenses>
<developers>
<developer>
<id>gekomad</id>
<name>Giuseppe Cannella</name>
<url>https://github.com/gekomad</url>
</developer>
</developers>
<scm>
<url>https://github.com/gekomad/scala-regex-collection</url>
<connection>scm:git:https://github.com/gekomad/scala-regex-collection</connection>
</scm>
<url>https://github.com/gekomad/scala-regex-collection</url>
51 changes: 51 additions & 0 deletions build.sbt.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
name := "scala-regex-collection"
publishTo := sonatypePublishTo.value

import org.scalajs.linker.interface.{ESVersion, ModuleSplitStyle}

lazy val scalaJs = project
.in(file("."))
.enablePlugins(ScalaJSPlugin)
.settings(
version := "2.0.1",
scalaVersion := "2.13.15",
crossScalaVersions := Seq("2.12.20", "2.13.15", "3.5.2"),
organization := "com.github.gekomad",
scalaJSUseMainModuleInitializer := false,
scalaJSLinkerConfig ~= (_.withESFeatures(_.withESVersion(ESVersion.ES2018))),
scalaJSLinkerConfig ~= {
_.withModuleKind(ModuleKind.ESModule)
.withModuleSplitStyle(ModuleSplitStyle.SmallModulesFor(List("scalaJs")))
},
scalacOptions ++= Seq("-Xfatal-warnings"),
libraryDependencies += "org.scala-js" %%% "scalajs-dom" % "2.8.0",
libraryDependencies += "io.github.cquiroz" %%% "scala-java-time" % "2.6.0",
libraryDependencies += "io.github.cquiroz" %%% "scala-java-time-tzdb" % "2.6.0",
libraryDependencies += "org.scalameta" %%% "munit" % "1.0.2" % Test
)

//sonatype

publishTo := sonatypePublishToBundle.value
logLevel := Level.Debug

pomExtra :=
<licenses>
<license>
<name>Apache 2</name>
<url>https://www.apache.org/licenses/LICENSE-2.0.txt</url>
<distribution>repo</distribution>
</license>
</licenses>
<developers>
<developer>
<id>gekomad</id>
<name>Giuseppe Cannella</name>
<url>https://github.com/gekomad</url>
</developer>
</developers>
<scm>
<url>https://github.com/gekomad/scala-regex-collection</url>
<connection>scm:git:https://github.com/gekomad/scala-regex-collection</connection>
</scm>
<url>https://github.com/gekomad/scala-regex-collection</url>
3 changes: 2 additions & 1 deletion project/build.properties
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
sbt.version = 1.5.2
sbt.version=1.10.5

1 change: 1 addition & 0 deletions project/plugins.sbt
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
addSbtPlugin("org.xerial.sbt" % "sbt-sonatype" % "3.9.5")
addSbtPlugin("com.github.sbt" % "sbt-pgp" % "2.1.2")
addSbtPlugin("org.scala-js" % "sbt-scalajs" % "1.17.0")
1 change: 0 additions & 1 deletion publish.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ pomExtra :=
</scm>
<url>https://github.com/gekomad/scala-regex-collection</url>


ThisBuild / publishMavenStyle := true

publishConfiguration := publishConfiguration.value.withOverwrite(true)
22 changes: 14 additions & 8 deletions src/main/scala/com/github/gekomad/regexcollection/Validator.scala
Original file line number Diff line number Diff line change
Expand Up @@ -119,13 +119,19 @@ object Collection {
}

object Validator {
def apply[A](reg: String): Validator[A] = new Validator[A] {
override val regexp: String = reg
val regex: Regex = reg.r
val regexIgn: Regex = s"(?i)$reg".r
val regexExact: Regex = s"^$reg$$".r
val regexExactIgn: Regex = s"^(?i)$reg$$".r
def f(reg: String) = {

val reg3 = reg.replace("(?i)(?i)", "(?i)")
val reg4 = reg3.replace("^(?i)", "(?i)^")
reg4
}

def apply[A](reg: String): Validator[A] = new Validator[A] {
override val regexp: String = f(reg)
val regex: Regex = f(reg).r
val regexIgn: Regex = f(s"(?i)$reg").r
val regexExact: Regex = f(s"^$reg$$").r
val regexExactIgn: Regex = f(s"^(?i)$reg$$").r
override def validateIgnoreCase(a: String): Option[String] = regexExactIgn.findFirstMatchIn(a).map(_ => a)
override def validateCaseSensitive(a: String): Option[String] = regexExact.findFirstMatchIn(a).map(_ => a)
def validateCaseInsensitive(a: String): Option[String] = regexExactIgn.findFirstMatchIn(a).map(_ => a)
Expand Down Expand Up @@ -271,8 +277,8 @@ object Collection {

implicit val validatorComment: Validator[Comments] = Validator[Comments]("""(\/\*([^*]|[\r\n]|(\*+([^*/]|[\r\n])))*\*+\/)""")

implicit val validatorCreditCardVisa: Validator[CreditCardVisa] = Validator[CreditCardVisa]("""4[0-9]{12}(?:[0-9]{3})?""")
implicit val validatorCreditCardMasterCard: Validator[CreditCardMasterCard] = Validator[CreditCardMasterCard]("""(?:5[1-5][0-9]{2}|222[1-9]|22[3-9][0-9]|2[3-6][0-9]{2}|27[01][0-9]|2720)[0-9]{12}""")
implicit val validatorCreditCardVisa: Validator[CreditCardVisa] = Validator[CreditCardVisa]("""4[0-9]{12}(?:[0-9]{3})?""")
implicit val validatorCreditCardMasterCard: Validator[CreditCardMasterCard] = Validator[CreditCardMasterCard]("""(?:5[1-5][0-9]{2}|222[1-9]|22[3-9][0-9]|2[3-6][0-9]{2}|27[01][0-9]|2720)[0-9]{12}""")
implicit val validatorCreditCardAmericanExpress: Validator[CreditCardAmericanExpress] = Validator[CreditCardAmericanExpress]("""3[47][0-9]{13}""")
implicit val validatorCreditCardDinersClub: Validator[CreditCardinersClub] = Validator[CreditCardinersClub]("""3(?:0[0-5]|[68][0-9])[0-9]{11}""")
implicit val validatorCreditCardDiscover: Validator[CreditCardDiscover] = Validator[CreditCardDiscover]("""6(?:011|5[0-9]{2})[0-9]{12}""")
Expand Down
Loading

0 comments on commit 3ebb885

Please sign in to comment.