Skip to content

Commit ee5f342

Browse files
committed
Initial commit
0 parents  commit ee5f342

File tree

9 files changed

+131
-0
lines changed

9 files changed

+131
-0
lines changed

.gitignore

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/bower_components/
2+
/node_modules/
3+
/.pulp-cache/
4+
/output/
5+
/generated-docs/
6+
/.psc-package/
7+
/.psc*
8+
/.purs*
9+
/.psa*

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2020 Awake Security
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# purescript-web-encoding

bower.json

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"name": "purescript-web-encoding",
3+
"homepage": "https://github.com/purescript-web/purescript-web-encoding",
4+
"license": "MIT",
5+
"repository": {
6+
"type": "git",
7+
"url": "git://github.com/purescript-web/purescript-web-encoding.git"
8+
},
9+
"ignore": [
10+
"**/.*",
11+
"bower_components",
12+
"node_modules",
13+
"output",
14+
"bower.json",
15+
"package.json"
16+
],
17+
"dependencies": {
18+
"purescript-prelude": "^4.0.0",
19+
"purescript-effect": "^2.0.0",
20+
"purescript-arraybuffer-types": "^2.0.0",
21+
"purescript-newtype": "^3.0.0"
22+
}
23+
}

src/Web/Encoding/TextDecoder.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
exports.new = function(label) {
2+
return function() {
3+
return new TextDecoder(label);
4+
};
5+
};
6+
7+
exports._decode = function(view, options, decoder) {
8+
return decoder.decode(view, options);
9+
};

src/Web/Encoding/TextDecoder.purs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
module Web.Encoding.TextDecoder where
2+
3+
import Data.ArrayBuffer.Types (ArrayView)
4+
import Effect (Effect)
5+
import Effect.Uncurried (EffectFn3, runEffectFn3)
6+
import Prim.Row as Row
7+
import Web.Encoding.UtfLabel (UtfLabel)
8+
9+
foreign import data TextDecoder :: Type
10+
11+
type DecodeOptions =
12+
( stream :: Boolean
13+
)
14+
15+
foreign import new :: UtfLabel -> Effect TextDecoder
16+
17+
foreign import _decode :: forall r t. EffectFn3 (ArrayView t) { | r } TextDecoder String
18+
19+
decode :: forall t. ArrayView t -> TextDecoder -> Effect String
20+
decode arr decoder = runEffectFn3 _decode arr {} decoder
21+
22+
decodeWithOptions :: forall r rx t. Row.Union r rx DecodeOptions => ArrayView t -> { | r } -> TextDecoder -> Effect String
23+
decodeWithOptions arr options decoder = runEffectFn3 _decode arr options decoder
24+

src/Web/Encoding/TextEncoder.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
exports.new = function() {
2+
return new TextEncoder();
3+
};
4+
5+
exports.encode = function(text) {
6+
return function(encoder) {
7+
return encoder.encode(text);
8+
};
9+
};
10+
11+
exports.encodeInto = function(text) {
12+
return function(view) {
13+
return function(encoder) {
14+
return function() {
15+
return encoder.encodeInto(text, view);
16+
};
17+
};
18+
};
19+
};

src/Web/Encoding/TextEncoder.purs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
module Web.Encoding.TextEncoder where
2+
3+
import Data.ArrayBuffer.Types (Uint8Array)
4+
import Effect (Effect)
5+
6+
foreign import data TextEncoder :: Type
7+
8+
foreign import new :: Effect TextEncoder
9+
10+
foreign import encode :: String -> TextEncoder -> Uint8Array
11+
12+
foreign import encodeInto :: String -> Uint8Array -> TextEncoder -> Effect { read :: Int, written :: Int }

src/Web/Encoding/UtfLabel.purs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
module Web.Encoding.UtfLabel where
2+
3+
import Data.Newtype (class Newtype)
4+
import Prelude (class Eq, class Ord)
5+
6+
newtype UtfLabel = UtfLabel String
7+
8+
derive instance newtypeUtfLabel :: Newtype UtfLabel _
9+
derive newtype instance eqUtfLabel :: Eq UtfLabel
10+
derive newtype instance ordUtfLabel :: Ord UtfLabel
11+
12+
utf8 :: UtfLabel
13+
utf8 = UtfLabel "utf8"

0 commit comments

Comments
 (0)