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..cda9369 100644 --- a/src/Data/String/Common.purs +++ b/src/Data/String/Common.purs @@ -1,27 +1,39 @@ 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 s = s == "" +null :: Warn (Text "'null' is deprecated, use 'isEmpty'") => String -> Boolean +null = isEmpty + +-- | 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 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