diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a9d110d..28243e2 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -50,6 +50,3 @@ jobs: npm install bower pulp@16.0.0-0 npx bower install npx pulp build -- --censor-lib --strict - if [ -d "test" ]; then - npx pulp test - fi diff --git a/CHANGELOG.md b/CHANGELOG.md index ad44db1..7e1187c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,12 @@ Bugfixes: Other improvements: +## [v13.1.0](https://github.com/purescript-contrib/purescript-arraybuffer/releases/tag/v13.1.0) - 2022-12-01 + +New features: + +- `Data.ArrayBuffer.Cast` (#46 by @jamesdbrock) + ## [v13.0.0](https://github.com/purescript-contrib/purescript-arraybuffer/releases/tag/v13.0.0) - 2022-04-27 Breaking Changes: diff --git a/bower.json b/bower.json index 74106e6..d7d9ae7 100644 --- a/bower.json +++ b/bower.json @@ -1,33 +1,30 @@ { - "name": "purescript-arraybuffer", - "license": [ - "MIT" - ], - "repository": { - "type": "git", - "url": "https://github.com/purescript-contrib/purescript-arraybuffer" - }, - "ignore": [ - "**/.*", - "node_modules", - "bower_components", - "output" - ], - "dependencies": { - "purescript-arraybuffer-types": "^3.0.2", - "purescript-arrays": "^7.0.0", - "purescript-effect": "^4.0.0", - "purescript-float32": "^2.0.0", - "purescript-functions": "^6.0.0", - "purescript-gen": "^4.0.0", - "purescript-maybe": "^6.0.0", - "purescript-nullable": "^6.0.0", - "purescript-prelude": "^6.0.0", - "purescript-tailrec": "^6.0.0", - "purescript-uint": "^7.0.0", - "purescript-unfoldable": "^6.0.0" - }, - "devDependencies": { - "purescript-quickcheck-laws": "^7.0.0" - } + "name": "purescript-arraybuffer", + "license": [ + "MIT" + ], + "repository": { + "type": "git", + "url": "https://github.com/purescript-contrib/purescript-arraybuffer" + }, + "ignore": [ + "**/.*", + "node_modules", + "bower_components", + "output" + ], + "dependencies": { + "purescript-arraybuffer-types": "^v3.0.2", + "purescript-arrays": "^v7.1.0", + "purescript-effect": "^v4.0.0", + "purescript-float32": "^v2.0.0", + "purescript-functions": "^v6.0.0", + "purescript-gen": "^v4.0.0", + "purescript-maybe": "^v6.0.0", + "purescript-nullable": "^v6.0.0", + "purescript-prelude": "^v6.0.1", + "purescript-tailrec": "^v6.1.0", + "purescript-uint": "^v7.0.0", + "purescript-unfoldable": "^v6.0.0" + } } diff --git a/packages.dhall b/packages.dhall index 582d6d3..2ffa9a7 100644 --- a/packages.dhall +++ b/packages.dhall @@ -1,4 +1,5 @@ let upstream = - https://raw.githubusercontent.com/purescript/package-sets/prepare-0.15/src/packages.dhall + https://github.com/purescript/package-sets/releases/download/psc-0.15.4-20221102/packages.dhall + sha256:8628e413718876ce26983db1d0ce9d9e1588129117fa3bb8ed9f618db6914127 in upstream diff --git a/spago-test.dhall b/spago-test.dhall index ab1a012..7037d90 100644 --- a/spago-test.dhall +++ b/spago-test.dhall @@ -5,7 +5,6 @@ in conf // { , "foldable-traversable" , "partial" , "refs" - , "typelevel-prelude" , "tuples" , "quickcheck" , "quickcheck-laws" diff --git a/src/Data/ArrayBuffer/Cast.purs b/src/Data/ArrayBuffer/Cast.purs new file mode 100644 index 0000000..10e5b0a --- /dev/null +++ b/src/Data/ArrayBuffer/Cast.purs @@ -0,0 +1,46 @@ +-- | `DataView` represents unaligned memory of unknown endianness. +-- | +-- | `ArrayView` represents arrays of aligned elements of +-- | local-machine endianness. +-- | For the cases of `Int8Array`, `Uint8Array`, `Uint8ClampedArray`, +-- | the elements +-- | are single bytes, so they are always aligned and they have no +-- | endianness. Therefore in those cases we can freely cast back and forth +-- | to `DataView`. +module Data.ArrayBuffer.Cast + ( fromInt8Array + , fromUint8Array + , fromUint8ClampedArray + , toInt8Array + , toUint8Array + , toUint8ClampedArray + ) where + +import Data.ArrayBuffer.DataView as DV +import Data.ArrayBuffer.Typed as AT +import Data.ArrayBuffer.Types (DataView, Uint8Array, Uint8ClampedArray, Int8Array) +import Effect (Effect) + +-- | Cast an `Int8Array` to a `DataView`. +fromInt8Array :: Int8Array -> Effect DataView +fromInt8Array x = DV.part (AT.buffer x) (AT.byteOffset x) (AT.byteLength x) + +-- | Cast a `DataView` to an `Int8Array`. +toInt8Array :: DataView -> Effect Int8Array +toInt8Array x = AT.part (DV.buffer x) (DV.byteOffset x) (DV.byteLength x) + +-- | Cast a `UInt8Array` to a `DataView`. +fromUint8Array :: Uint8Array -> Effect DataView +fromUint8Array x = DV.part (AT.buffer x) (AT.byteOffset x) (AT.byteLength x) + +-- | Cast a `DataView` to a `Uint8Array`. +toUint8Array :: DataView -> Effect Uint8Array +toUint8Array x = AT.part (DV.buffer x) (DV.byteOffset x) (DV.byteLength x) + +-- | Cast a `UInt8ClampedArray` to a `DataView`. +fromUint8ClampedArray :: Uint8ClampedArray -> Effect DataView +fromUint8ClampedArray x = DV.part (AT.buffer x) (AT.byteOffset x) (AT.byteLength x) + +-- | Cast a `DataView` to a `Uint8ClampedArray`. +toUint8ClampedArray :: DataView -> Effect Uint8ClampedArray +toUint8ClampedArray x = AT.part (DV.buffer x) (DV.byteOffset x) (DV.byteLength x) diff --git a/src/Data/ArrayBuffer/ValueMapping.purs b/src/Data/ArrayBuffer/ValueMapping.purs index 70ac4f7..8694a19 100644 --- a/src/Data/ArrayBuffer/ValueMapping.purs +++ b/src/Data/ArrayBuffer/ValueMapping.purs @@ -12,7 +12,8 @@ import Data.Float32 (Float32) as F import Data.UInt (UInt) import Type.Proxy (Proxy) --- | Map of each `ArrayViewType` to the number of bytes of storage it requires. +-- | Type-level map of each `ArrayViewType` to the number of bytes of storage +-- | it requires. class BytesPerType (a :: ArrayViewType) where byteWidth :: (Proxy a) -> Int @@ -43,7 +44,8 @@ instance bytesPerTypeFloat32 :: BytesPerType Float32 where instance bytesPerTypeFloat64 :: BytesPerType Float64 where byteWidth _ = 8 --- | Maps a `TypedArray`’s binary casted value to its computable representation in JavaScript. +-- | Type-level map of `TypedArray`’s binary casted value to its +-- | representation in JavaScript. class BinaryValue (a :: ArrayViewType) (t :: Type) | a -> t instance binaryValueUint8Clamped :: BinaryValue Uint8Clamped UInt @@ -56,6 +58,7 @@ instance binaryValueInt8 :: BinaryValue Int8 Int instance binaryValueFloat32 :: BinaryValue Float32 F.Float32 instance binaryValueFloat64 :: BinaryValue Float64 Number +-- | Type-level map of `TypedArray` to its element type name. class ShowArrayViewType (a :: ArrayViewType) (name :: Symbol) | a -> name instance showArrayViewTypeUint8Clamped :: ShowArrayViewType Uint8Clamped "Uint8Clamped"