diff --git a/.tool-versions b/.tool-versions index 2304456..a9cc8ed 100644 --- a/.tool-versions +++ b/.tool-versions @@ -1,3 +1,3 @@ -gleam 0.27.0 +gleam 0.28.2 erlang 25.2.2 nodejs 18.14.0 diff --git a/CHANGELOG b/CHANGELOG index baf8e57..f05d930 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,9 @@ +3.0.0 +----- + +* Update for Gleam 0.28. +* Enable JavaScript target. + 2.0.0 ----- diff --git a/gleam.toml b/gleam.toml index 3bc2722..830a5b6 100644 --- a/gleam.toml +++ b/gleam.toml @@ -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" diff --git a/manifest.toml b/manifest.toml index f358c18..a5115b3 100644 --- a/manifest.toml +++ b/manifest.toml @@ -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" diff --git a/src/glentities.gleam b/src/glentities.gleam index f1abb35..57366b1 100644 --- a/src/glentities.gleam +++ b/src/glentities.gleam @@ -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" diff --git a/src/glentities/internal/string_utils.gleam b/src/glentities/internal/string_utils.gleam new file mode 100644 index 0000000..0657c0a --- /dev/null +++ b/src/glentities/internal/string_utils.gleam @@ -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" +} diff --git a/test/glentities_test.gleam b/test/glentities_test.gleam index 8748347..c172875 100644 --- a/test/glentities_test.gleam +++ b/test/glentities_test.gleam @@ -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"