Skip to content

Commit 866a0d8

Browse files
authored
Merge pull request #1 from purescript-web/compiler/0.12
Compiler/0.12
2 parents 2ce0cd1 + 7a6afd6 commit 866a0d8

File tree

15 files changed

+387
-9
lines changed

15 files changed

+387
-9
lines changed

.eslintrc.json

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
{
2+
"parserOptions": {
3+
"ecmaVersion": 5
4+
},
5+
"extends": "eslint:recommended",
6+
"env": {
7+
"commonjs": true,
8+
"browser": true
9+
},
10+
"rules": {
11+
"strict": [2, "global"],
12+
"block-scoped-var": 2,
13+
"consistent-return": 2,
14+
"eqeqeq": [2, "smart"],
15+
"guard-for-in": 2,
16+
"no-caller": 2,
17+
"no-extend-native": 2,
18+
"no-loop-func": 2,
19+
"no-new": 2,
20+
"no-param-reassign": 2,
21+
"no-return-assign": 2,
22+
"no-unused-expressions": 2,
23+
"no-use-before-define": 2,
24+
"radix": [2, "always"],
25+
"indent": [2, 2],
26+
"quotes": [2, "double"],
27+
"semi": [2, "always"]
28+
}
29+
}

.gitignore

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
# Dependencies
2-
.psci_modules
3-
bower_components
4-
node_modules
5-
6-
# Generated files
7-
.psci
8-
output
1+
/.*
2+
!/.gitignore
3+
!/.eslintrc.json
4+
!/.travis.yml
5+
package-lock.json
6+
/bower_components/
7+
/node_modules/
8+
/output/

.travis.yml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
language: node_js
2+
dist: trusty
3+
sudo: required
4+
node_js: stable
5+
env:
6+
- PATH=$HOME/purescript:$PATH
7+
install:
8+
- TAG=$(wget -q -O - https://github.com/purescript/purescript/releases/latest --server-response --max-redirect 0 2>&1 | sed -n -e 's/.*Location:.*tag\///p')
9+
- wget -O $HOME/purescript.tar.gz https://github.com/purescript/purescript/releases/download/$TAG/linux64.tar.gz
10+
- tar -xvf $HOME/purescript.tar.gz -C $HOME/
11+
- chmod a+x $HOME/purescript
12+
- npm install -g bower
13+
- npm install
14+
script:
15+
- bower install
16+
- npm run -s build
17+
after_success:
18+
- >-
19+
test $TRAVIS_TAG &&
20+
echo $GITHUB_TOKEN | pulp login &&
21+
echo y | pulp publish --no-push

README.md

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,16 @@
1-
# purescript-web-file
1+
# purescript-web-file
2+
3+
[![Latest release](http://img.shields.io/github/release/purescript-web/purescript-web-file.svg)](https://github.com/purescript-web/purescript-web-file/releases)
4+
[![Build status](https://travis-ci.org/purescript-web/purescript-web-file.svg?branch=master)](https://travis-ci.org/purescript-web/purescript-web-file)
5+
6+
Type definitions and low level interface implementations for the W3C File API.
7+
8+
## Installation
9+
10+
```
11+
bower install purescript-web-file
12+
```
13+
14+
## Documentation
15+
16+
Module documentation is [published on Pursuit](http://pursuit.purescript.org/packages/purescript-web-file).

bower.json

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

package.json

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"private": true,
3+
"scripts": {
4+
"clean": "rimraf output && rimraf .pulp-cache",
5+
"build": "eslint src && pulp build -- --censor-lib --strict"
6+
},
7+
"devDependencies": {
8+
"eslint": "^4.19.1",
9+
"pulp": "^12.2.0",
10+
"purescript-psa": "^0.6.0",
11+
"rimraf": "^2.6.2"
12+
}
13+
}

src/Web/File/Blob.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
"use strict";
2+
3+
exports.typeImpl = function (blob) { return blob.type; };
4+
5+
exports.size = function (blob) { return blob.size; };
6+
7+
exports.slice = function (contentType) {
8+
return function (start) {
9+
return function (end) {
10+
return function (blob) {
11+
return blob.slice(start, end, contentType);
12+
};
13+
};
14+
};
15+
};

src/Web/File/Blob.purs

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
module Web.File.Blob
2+
( Blob
3+
, type_
4+
, size
5+
, StartByte(..)
6+
, EndByte(..)
7+
, ByteIdx
8+
, idxFromInt
9+
, idxFromNumber
10+
, slice
11+
, slice'
12+
) where
13+
14+
import Data.Int (toNumber)
15+
import Data.Maybe (Maybe(..))
16+
import Data.MediaType (MediaType(..))
17+
import Math (round)
18+
import Prelude ((==), (>>>))
19+
import Unsafe.Coerce (unsafeCoerce)
20+
21+
foreign import data Blob :: Type
22+
23+
foreign import typeImpl :: Blob -> String
24+
25+
-- | `MediaType` of the data contained in the `Blob`.
26+
-- | Returns `Nothing` if the `MediaType` is unknown.
27+
type_ :: Blob -> Maybe MediaType
28+
type_ blob =
29+
let
30+
blobType = typeImpl blob
31+
in
32+
if blobType == ""
33+
then Nothing
34+
else Just (MediaType blobType)
35+
36+
-- | The size (in bytes) of the data contained in the `Blob`.
37+
foreign import size :: Blob -> Number
38+
39+
-- | An index into the Blob indicating the first byte to include in the new Blob.
40+
-- | If you specify a negative value, it's treated as an offset from the end of the
41+
-- | string toward the beginning. For example, -10 would be the 10th from last byte
42+
-- | in the Blob. If you specify a value for start that is larger than the size
43+
-- | of the source Blob, the returned Blob has size 0 and contains no data.
44+
newtype StartByte = StartByte ByteIdx
45+
46+
-- | An index into the Blob indicating the first byte that will *not* be included
47+
-- | in the new Blob (i.e. the byte exactly at this index is not included).
48+
-- | If you specify a negative value, it's treated as an offset from the end of
49+
-- | the string toward the beginning. For example, -10 would be the 10th from
50+
-- | last byte in the Blob. The default value is size.
51+
newtype EndByte = EndByte ByteIdx
52+
53+
foreign import data ByteIdx :: Type
54+
55+
-- | Creates `ByteIdx` from `Int` value
56+
idxFromInt :: Int -> ByteIdx
57+
idxFromInt = toNumber >>> unsafeCoerce
58+
59+
-- | Creates `ByteIdx` from `Number` value using `Math.round`.
60+
idxFromNumber :: Number -> ByteIdx
61+
idxFromNumber = round >>> unsafeCoerce
62+
63+
-- | Creates a new `Blob` object (with specified `MediaType`), containing the
64+
-- | data in the specified range of bytes of the source Blob, by setting .
65+
foreign import slice MediaType -> StartByte -> EndByte -> Blob -> Blob
66+
67+
-- | Creates a new `Blob` object containing the data in the specified range
68+
-- | of bytes of the source Blob.
69+
slice' StartByte -> EndByte -> Blob -> Blob
70+
slice' = slice (MediaType "")

src/Web/File/File.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
"use strict";
2+
3+
exports.name = function (file) { return file.name; };

src/Web/File/File.purs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
module Web.File.File where
2+
3+
import Prelude
4+
5+
import Data.Maybe (Maybe)
6+
import Data.MediaType (MediaType)
7+
import Unsafe.Coerce (unsafeCoerce)
8+
import Web.File.Blob as Blob
9+
10+
foreign import data File :: Type
11+
12+
toBlob :: File -> Blob.Blob
13+
toBlob = unsafeCoerce
14+
15+
foreign import name :: File -> String
16+
17+
-- | (Inherited from `Blob`) `MediaType` of the data contained in the `Blob`.
18+
-- | Returns `Nothing` if the `MediaType` is unknown.
19+
type_ :: File -> Maybe MediaType
20+
type_ = unsafeCoerce >>> Blob.type_
21+
22+
-- | (Inherited from `Blob`) The size (in bytes) of the data contained in the `File`.
23+
size :: File -> Number
24+
size = unsafeCoerce >>> Blob.size

0 commit comments

Comments
 (0)