Update package for Gleam 0.28

This commit is contained in:
Mikko Ahlroth 2023-04-15 20:48:41 +03:00
parent eeac5c80b8
commit 11260fae1a
7 changed files with 31 additions and 15 deletions

View file

@ -1,3 +1,3 @@
gleam 0.27.0
gleam 0.28.2
erlang 25.2.2
nodejs 18.14.0

View file

@ -1,3 +1,9 @@
3.0.0
-----
* Update for Gleam 0.28.
* Enable JavaScript target.
2.0.0
-----

View file

@ -1,5 +1,5 @@
name = "glentities"
version = "2.0.0"
version = "3.0.0"
description = "HTML entity encoder/decoder for Gleam"
# Fill out these fields if you intend to generate HTML documentation or publish
@ -9,8 +9,10 @@ licences = ["MIT"]
repository = { type = "gitlab", user = "Nicd", repo = "glentities" }
links = []
internal_modules = ["glentities/internal/*"]
[dependencies]
gleam_stdlib = "~> 0.27.0"
gleam_stdlib = "~> 0.28.0"
[dev-dependencies]
gleeunit = "~> 0.10"

View file

@ -2,10 +2,10 @@
# You typically do not need to edit this file
packages = [
{ name = "gleam_stdlib", version = "0.27.0", build_tools = ["gleam"], requirements = [], otp_app = "gleam_stdlib", source = "hex", outer_checksum = "9DBDD21B48C654182CDD8AA15ACF85E8E74A0438583C68BD7EF08BE89F999C6F" },
{ name = "gleam_stdlib", version = "0.28.1", build_tools = ["gleam"], requirements = [], otp_app = "gleam_stdlib", source = "hex", outer_checksum = "73F0A89FADE5022CBEF6D6C3551F9ADCE7054AFCE0CB1DC4C6D5AB4CA62D0111" },
{ name = "gleeunit", version = "0.10.1", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleeunit", source = "hex", outer_checksum = "ECEA2DE4BE6528D36AFE74F42A21CDF99966EC36D7F25DEB34D47DD0F7977BAF" },
]
[requirements]
gleam_stdlib = "~> 0.27.0"
gleam_stdlib = "~> 0.28.0"
gleeunit = "~> 0.10"

View file

@ -2,6 +2,7 @@ import gleam/string
import gleam/string_builder.{StringBuilder}
import gleam/int
import gleam/list
import glentities/internal/string_utils
pub type EncodeMode {
/// Encode all characters that have a specified named entity using that name, except tab and newline.
@ -2289,7 +2290,7 @@ pub fn decode_named(entity: String) {
/// Encode characters in text as HTML entities with given encoding mode.
pub fn encode(text: String, mode: EncodeMode) {
let input = normalise(text)
let input = string_utils.normalise(text)
case mode {
Named -> encode_named(input, string_builder.new())
Hex -> encode_hex(input)
@ -4058,7 +4059,3 @@ pub fn encode_named(text: String, acc: StringBuilder) -> String {
}
}
}
// Assuming here that it can never fail on UTF-8 string input
external fn normalise(text: String) -> String =
"unicode" "characters_to_nfc_binary"

View file

@ -0,0 +1,13 @@
if erlang {
pub external fn normalise(text: String) -> String =
"unicode" "characters_to_nfc_binary"
}
if javascript {
pub fn normalise(text: String) -> String {
normalise_js(text, "NFC")
}
pub external fn normalise_js(text: String, mode: String) -> String =
"" "String.prototype.normalize.call"
}

View file

@ -1,6 +1,7 @@
import gleeunit
import gleeunit/should
import glentities
import glentities/internal/string_utils
pub fn main() {
gleeunit.main()
@ -38,7 +39,7 @@ pub fn encode_hex_test() {
pub fn roundtrip_named_test() {
let input =
normalise(
string_utils.normalise(
"Ἰοὺ ἰού· τὰ πάντʼ ἂν ἐξήκοι σαφῆ. ஸ்றீனிவாஸ ராமானுஜன் ஐயங்கார் A ∩ B = { c : c ∈ A, c ∈ B }",
)
@ -52,7 +53,7 @@ pub fn roundtrip_named_test() {
pub fn roundtrip_hex_test() {
let input =
normalise(
string_utils.normalise(
"Ἰοὺ ἰού· τὰ πάντʼ ἂν ἐξήκοι σαφῆ. ஸ்றீனிவாஸ ராமானுஜன் ஐயங்கார் A ∩ B = { c : c ∈ A, c ∈ B }",
)
@ -63,6 +64,3 @@ pub fn roundtrip_hex_test() {
input,
)
}
external fn normalise(text: String) -> String =
"unicode" "characters_to_nfc_binary"