Skip to content

Commit a0c4de2

Browse files
authored
Implement encode in PureScript (#186)
1 parent 0f64855 commit a0c4de2

File tree

2 files changed

+8
-9
lines changed

2 files changed

+8
-9
lines changed

staging/src/TryPureScript.js

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,6 @@ exports.setInnerHTML = function(html) {
66
};
77
};
88

9-
exports.encode = function(text) {
10-
return text
11-
.replace('<', '&lt;')
12-
.replace('>', '&gt;')
13-
.replace('&', '&amp;')
14-
.replace('"', '&quot;');
15-
};
16-
179
exports.withConsoleImpl = function(f) {
1810
return function() {
1911
var oldLog = console.log;

staging/src/TryPureScript.purs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,18 @@ module TryPureScript
2020
import Prelude
2121
import Data.Foldable (class Foldable, foldMap)
2222
import Data.String (joinWith)
23+
import Data.String.Common (replace)
24+
import Data.String.Pattern (Pattern(..), Replacement(..))
2325
import Effect (Effect)
2426

2527
foreign import setInnerHTML :: String -> Effect Unit
2628

27-
foreign import encode :: String -> String
29+
encode :: String -> String
30+
encode =
31+
replace (Pattern "<") (Replacement "&lt;")
32+
<<< replace (Pattern ">") (Replacement "&gt;")
33+
<<< replace (Pattern "&") (Replacement "&amp;")
34+
<<< replace (Pattern "\"") (Replacement "&quot;")
2835

2936
foreign import withConsoleImpl
3037
:: forall a

0 commit comments

Comments
 (0)