From 7e510874e5d55ce39ca54380c69aac465cb0b926 Mon Sep 17 00:00:00 2001 From: sigma-andex <77549848+sigma-andex@users.noreply.github.com> Date: Tue, 28 Jun 2022 10:34:07 +0100 Subject: [PATCH 1/2] Add isEmpty and deprecate null --- CHANGELOG.md | 1 + src/Data/String.purs | 2 +- src/Data/String/Common.purs | 22 +++++++++++++++++----- test/Test/Data/String.purs | 6 +++--- 4 files changed, 22 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 52a8669..d39b0b4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ Notable changes to this project are documented in this file. The format is based Breaking changes: New features: +- Add `isEmpty` and add deprecation warning for `null` (by @sigma-andex) Bugfixes: diff --git a/src/Data/String.purs b/src/Data/String.purs index 742f265..b3bcc32 100644 --- a/src/Data/String.purs +++ b/src/Data/String.purs @@ -6,5 +6,5 @@ module Data.String import Data.String.CodePoints -import Data.String.Common (joinWith, localeCompare, null, replace, replaceAll, split, toLower, toUpper, trim) +import Data.String.Common (joinWith, localeCompare, null, isEmpty, replace, replaceAll, split, toLower, toUpper, trim) import Data.String.Pattern (Pattern(..), Replacement(..)) diff --git a/src/Data/String/Common.purs b/src/Data/String/Common.purs index 9e3132e..2d5e291 100644 --- a/src/Data/String/Common.purs +++ b/src/Data/String/Common.purs @@ -1,28 +1,40 @@ module Data.String.Common - ( null + ( isEmpty + , joinWith , localeCompare + , null , replace , replaceAll , split , toLower , toUpper , trim - , joinWith - ) where + ) + where import Prelude import Data.String.Pattern (Pattern, Replacement) +import Prim.TypeError (class Warn, Text) --- | Returns `true` if the given string is empty. +-- | Returns `true` if the given string is empty. Alias for isEmpty. -- | -- | ```purescript -- | null "" == true -- | null "Hi" == false -- | ``` -null :: String -> Boolean +null :: Warn (Text "'null' is deprecated, use 'isEmpty'") => String -> Boolean null s = s == "" +-- | Returns `true` if the given string is empty. +-- | +-- | ```purescript +-- | isEmpty "" == true +-- | isEmpty "Hi" == false +-- | ``` +isEmpty :: String -> Boolean +isEmpty s = s == "" + -- | Compare two strings in a locale-aware fashion. This is in contrast to -- | the `Ord` instance on `String` which treats strings as arrays of code -- | units: diff --git a/test/Test/Data/String.purs b/test/Test/Data/String.purs index 5c73153..5bb914d 100644 --- a/test/Test/Data/String.purs +++ b/test/Test/Data/String.purs @@ -12,9 +12,9 @@ import Test.Assert (assert, assertEqual) testString :: Effect Unit testString = do - log "null" - assert $ S.null "" - assert $ not (S.null "a") + log "isEmpty" + assert $ S.isEmpty "" + assert $ not (S.isEmpty "a") log "stripPrefix" -- this is a re-export from Data.String.CodeUnits, so the majority of tests are in there From d784c350a78f68890458584c207c2f24981c7804 Mon Sep 17 00:00:00 2001 From: sigma-andex <77549848+sigma-andex@users.noreply.github.com> Date: Tue, 28 Jun 2022 10:37:00 +0100 Subject: [PATCH 2/2] Alias function --- src/Data/String/Common.purs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Data/String/Common.purs b/src/Data/String/Common.purs index 2d5e291..cda9369 100644 --- a/src/Data/String/Common.purs +++ b/src/Data/String/Common.purs @@ -24,7 +24,7 @@ import Prim.TypeError (class Warn, Text) -- | null "Hi" == false -- | ``` null :: Warn (Text "'null' is deprecated, use 'isEmpty'") => String -> Boolean -null s = s == "" +null = isEmpty -- | Returns `true` if the given string is empty. -- |