Skip to content

Commit 45b4b62

Browse files
AlexaDeWitjacereda
authored andcommitted
Remove text encoding dependency
1 parent 680f00f commit 45b4b62

File tree

5 files changed

+7
-97
lines changed

5 files changed

+7
-97
lines changed

bower.json

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,12 @@
1616
"purescript-arraybuffer-types": "^2.0.0",
1717
"purescript-maybe": "^4.0.0",
1818
"purescript-effect": "^2.0.0",
19-
"purescript-uint": "^4.0.0",
20-
"purescript-text-encoding": "^0.0.9"
19+
"purescript-uint": "^4.0.0"
2120
},
2221
"devDependencies": {
2322
"purescript-debug": "^4.0.0",
2423
"purescript-quickcheck": "^5.0.0",
2524
"purescript-partial": "^2.0.0",
2625
"purescript-unicode": "^4.0.1"
2726
}
28-
}
27+
}

package.json

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
11
{
22
"name": "purescript-arraybuffer",
3-
"version": "7.0.0",
3+
"version": "9.0.0",
44
"main": "index.js",
55
"repository": "[email protected]:jacereda/purescript-arraybuffer.git",
66
"author": "https://github.com/jacereda",
77
"license": "MIT",
8-
"devDependencies": {
9-
"text-encoding": "^0.6.4"
10-
}
11-
12-
}
8+
"devDependencies": {}
9+
}

src/Data/ArrayBuffer/ArrayBuffer.purs

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,11 @@ module Data.ArrayBuffer.ArrayBuffer ( create
33
, slice
44
, fromArray
55
, fromIntArray
6-
, fromString
7-
, decodeToString
86
) where
97

10-
import Data.ArrayBuffer.DataView (whole, buffer)
11-
import Data.ArrayBuffer.Typed (asUint8Array, dataView)
128
import Data.ArrayBuffer.Types (ArrayBuffer, ByteOffset, ByteLength)
13-
import Data.Either (Either)
149
import Data.Function.Uncurried (Fn3, runFn3)
15-
import Data.TextDecoder (decodeUtf8)
16-
import Data.TextEncoder (encodeUtf8)
1710
import Effect (Effect)
18-
import Effect.Exception (Error)
19-
import Prelude ((<<<))
2011

2112

2213
-- | Create an `ArrayBuffer` with the given capacity.
@@ -35,18 +26,4 @@ slice = runFn3 sliceImpl
3526
foreign import fromArray :: Array Number -> ArrayBuffer
3627

3728
-- | Convert an array into an `ArrayBuffer` representation.
38-
foreign import fromIntArray :: Array Int -> ArrayBuffer
39-
40-
-- | Convert a UTF-8 encoded `ArrayBuffer` into a `String`.
41-
-- | Serves as a quick utility function for a common use-case. For more use-cases,
42-
-- | see: [purescript-text-encoding](https://pursuit.purescript.org/packages/purescript-text-encoding/0.0.8)
43-
-- | Requires the TextDecoder class available. A polyfill can be found in the npm package "text-encoding"
44-
decodeToString :: ArrayBuffer -> Either Error String
45-
decodeToString = decodeUtf8 <<< asUint8Array <<< whole
46-
47-
-- | Convert a `String` into a UTF-8 encoded `ArrayBuffer`.
48-
-- | Serves as a quick utility function for a common use-case. For more use-cases,
49-
-- | see: [purescript-text-encoding](https://pursuit.purescript.org/packages/purescript-text-encoding/0.0.8)
50-
-- | Requires the TextDecoder class available. A polyfill can be found in the npm package "text-encoding"
51-
fromString :: String -> ArrayBuffer
52-
fromString = buffer <<< dataView <<< encodeUtf8
29+
foreign import fromIntArray :: Array Int -> ArrayBuffer

test/Input.purs

Lines changed: 0 additions & 44 deletions
This file was deleted.

test/Main.purs

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,9 @@ import Effect (Effect)
66
import Data.ArrayBuffer.ArrayBuffer as AB
77
import Data.ArrayBuffer.DataView as DV
88
import Data.ArrayBuffer.Typed as TA
9-
import Data.Either (fromRight)
109
import Data.Maybe (Maybe(..), isNothing)
1110
import Data.UInt (fromInt, pow)
12-
import Partial.Unsafe (unsafePartial)
13-
import Test.QuickCheck (quickCheck', (<?>), quickCheck)
14-
import Test.Input (WellFormedInput(..))
11+
import Test.QuickCheck (quickCheck', (<?>))
1512

1613

1714
assertEffEquals :: forall a. Eq a => Show a => a -> Effect a -> Effect Unit
@@ -27,19 +24,6 @@ assertEquals expected actual = do
2724

2825
main :: Effect Unit
2926
main = do
30-
assertEquals "釺椱�밸造ə㊡癥闗" (unsafePartial $ fromRight $ AB.decodeToString $ AB.fromString "釺椱�밸造ə㊡癥闗")
31-
32-
quickCheck
33-
\(WellFormedInput s) ->
34-
let
35-
result = (unsafePartial $ fromRight $ AB.decodeToString $ AB.fromString s)
36-
in
37-
s == result
38-
<?> "Isormorphic arraybuffer conversion with string failed for input\n"
39-
<> s
40-
<> " which, after the round trip, result in\n"
41-
<> result
42-
4327
ab4 <- AB.create 4
4428
ab8 <- AB.create 8
4529
assertEquals 4 $ AB.byteLength ab4
@@ -52,9 +36,6 @@ main = do
5236
assertEquals (Just 2) $ DV.byteLength <$> DV.slice 2 2 ab4
5337
assertEquals 4 $ AB.byteLength $ AB.fromArray [1.0, 2.0, 3.0, 4.0]
5438
assertEquals 4 $ AB.byteLength $ AB.fromIntArray [1, 2, 3, 4]
55-
assertEquals 4 $ AB.byteLength $ AB.fromString "hola"
56-
assertEquals 5 $ AB.byteLength $ AB.fromString "hóla"
57-
assertEquals 7 $ AB.byteLength $ AB.fromString "hóla¡"
5839
assertEquals 8 $ AB.byteLength $ DV.buffer $ DV.whole ab8
5940
assertEquals 8 $ AB.byteLength $ DV.buffer $ TA.dataView $ TA.asInt8Array $ DV.whole ab8
6041

0 commit comments

Comments
 (0)