Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 0 additions & 26 deletions .eslintrc.json

This file was deleted.

33 changes: 16 additions & 17 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,30 +6,29 @@ on:
pull_request:
branches: [master]

permissions:
contents: read

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2

- uses: purescript-contrib/setup-purescript@main
with:
purescript: "unstable"

- uses: actions/setup-node@v2
- uses: actions/checkout@v6
- uses: actions/setup-node@v6
with:
node-version: "14.x"
node-version: "24"

- name: Install dependencies
run: |
npm install -g bower
npm install
bower install --production
run: npm install

- name: Build source
run: npm run-script build
run: npm run build

- name: Build examples
run: npm test

- name: Lint
run: npm run lint

- name: Run tests
run: |
bower install
npm run-script test --if-present
- name: Check formatting
run: npm run format:check
6 changes: 4 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
/.*
!/.gitignore
!/.eslintrc.json
!/.tidyrc.json
!/.oxfmtrc.json
!/.github/
/bower_components/
/node_modules/
/output/
package-lock.json
/package-lock.json
/spago.lock
3 changes: 3 additions & 0 deletions .oxfmtrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"trailingComma": "es5"
}
10 changes: 10 additions & 0 deletions .tidyrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"importSort": "ide",
"importWrap": "source",
"indent": 2,
"operatorsFile": null,
"ribbon": 1,
"typeArrowPlacement": "first",
"unicode": "never",
"width": null
}
24 changes: 15 additions & 9 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,24 @@ Bugfixes:

Other improvements:

## [v7.0.1](https://github.com/purescript/purescript-foreign/releases/tag/v7.0.1) - 2026-10-17

Other improvements:

- Migrate from Bower/Pulp to Spago and update CI, linting, and formatting (#89 by @thomashoneyman).

## [v7.0.0](https://github.com/purescript/purescript-foreign/releases/tag/v7.0.0) - 2022-04-27

Breaking changes:

- Migrate FFI to ES modules (#86 by @kl0tl and @JordanMartinez)

New features:

Bugfixes:

Other improvements:

- Replace all usages of `F` and `FT` with `Except`/`ExceptT (NonEmptyList ForeignError)` (#87 by @JordanMartinez)

Often times, the `F` and `FT` aliases did more to hinder usage of this library than help. These aliases
Expand All @@ -31,14 +39,17 @@ Other improvements:
## [v6.0.1](https://github.com/purescript/purescript-foreign/releases/tag/v6.0.1) - 2021-04-20

Other improvements:

- Fix warnings revealed by v0.14.1 PureScript release (#85 by @JordanMartinez)

## [v6.0.0](https://github.com/purescript/purescript-foreign/releases/tag/v6.0.0) - 2021-02-26

Breaking changes:

- Added support for PureScript 0.14 and dropped support for all previous versions (#80)

Other improvements:

- Migrated CI to GitHub Actions and updated installation instructions to use Spago (#81)
- Added a CHANGELOG.md file and pull request template (#82, #83)
- Replaced `unsafeToForeign` and `unsafeFromForeign` with `unsafeCoerce` (#72)
Expand All @@ -59,8 +70,8 @@ Fix `Show` instance for `ForeignError` (@rightfold)

- Updated for PureScript 0.11
- The library has been drastically simplified to focus on its core use; validating and extracting data from foreign values. This involves changes such as:
- Removal of `IsForeign` / `AsForeign` classes
- Removal of `parseJSON` as this library is not intended for general JSON parsing
- Removal of `IsForeign` / `AsForeign` classes
- Removal of `parseJSON` as this library is not intended for general JSON parsing
- New functions were added for `readNull`, `readUndefined`, `readNullOrUndefined` rather than using the newtypes to direct `IsForeign` choice as it was before
- The `(!)` index/property reading operator has been enhanced to work with `Foreign` or `F Foreign` on the left hand side, allowing for chained property reads

Expand Down Expand Up @@ -138,6 +149,7 @@ Updated docs
## [v0.4.0](https://github.com/purescript/purescript-foreign/releases/tag/v0.4.0) - 2015-02-21

**This release requires PureScript v0.6.8 or later**

- Updated dependencies

## [v0.3.0](https://github.com/purescript/purescript-foreign/releases/tag/v0.3.0) - 2015-01-10
Expand All @@ -150,15 +162,14 @@ Updated docs

## [v0.2.2](https://github.com/purescript/purescript-foreign/releases/tag/v0.2.2) - 2014-11-19



## [v0.2.1](https://github.com/purescript/purescript-foreign/releases/tag/v0.2.1) - 2014-11-18

- `IsForeign` instance for `Foreign`. (@MichaelXavier)

## [v0.2.0](https://github.com/purescript/purescript-foreign/releases/tag/v0.2.0) - 2014-08-20

Quite a few breaking changes to both names and types:

- A type for errors instead of using string concatenation.
- Breaking a few functions out into their own submodules.
- Adding types and instances to handle null-like values.
Expand Down Expand Up @@ -189,9 +200,4 @@ Quite a few breaking changes to both names and types:

## [v0.1.1](https://github.com/purescript/purescript-foreign/releases/tag/v0.1.1) - 2014-04-27



## [v0.1.0](https://github.com/purescript/purescript-foreign/releases/tag/v0.1.0) - 2014-04-26



18 changes: 9 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@ spago install foreign

## Examples

- [Simple types](examples/SimpleTypes.purs)
- [Arrays](examples/Arrays.purs)
- [Objects](examples/Objects.purs)
- [Complex objects](examples/Complex.purs)
- [Applicative style parser](examples/Applicative.purs)
- [Maybe for nulls](examples/MaybeNullable.purs)
- [Nested objects](examples/Nested.purs)
- [Unions](examples/Union.purs)
- [Parser errors](examples/ParseErrors.purs)
- [Simple types](examples/src/SimpleTypes.purs)
- [Arrays](examples/src/Arrays.purs)
- [Objects](examples/src/Objects.purs)
- [Complex objects](examples/src/Complex.purs)
- [Applicative style parser](examples/src/Applicative.purs)
- [Maybe for nulls](examples/src/MaybeNullable.purs)
- [Nested objects](examples/src/Nested.purs)
- [Unions](examples/src/Union.purs)
- [Parser errors](examples/src/ParseErrors.purs)

## Documentation

Expand Down
36 changes: 0 additions & 36 deletions bower.json

This file was deleted.

15 changes: 15 additions & 0 deletions examples/spago.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package:
name: foreign-examples
build:
strict: true
pedanticPackages: true
dependencies:
- console: ">=6.0.0 <7.0.0"
- effect: ">=4.0.0 <5.0.0"
- foldable-traversable: ">=6.0.0 <7.0.0"
- foreign: "*"
- functions: ">=6.0.0 <7.0.0"
- lists: ">=7.0.0 <8.0.0"
- maybe: ">=6.0.0 <7.0.0"
- prelude: ">=6.0.0 <7.0.0"
- transformers: ">=6.0.0 <7.0.0"
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import Foreign.Index ((!))
data Point = Point Number Number Number

instance showPoint :: Show Point where
show (Point x y z) = "(Point " <> show [x, y, z] <> ")"
show (Point x y z) = "(Point " <> show [ x, y, z ] <> ")"

readPoint :: Foreign -> Except (NonEmptyList ForeignError) Point
readPoint value = do
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion examples/Complex.purs → examples/src/Complex.purs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import Data.Traversable (traverse)
import Effect (Effect)
import Effect.Console (logShow)
import Example.Util.Value (foreignValue)
import Foreign (Foreign, ForeignError, readArray, readBoolean, readNumber, readString, readNullOrUndefined)
import Foreign (Foreign, ForeignError, readArray, readBoolean, readNullOrUndefined, readNumber, readString)
import Foreign.Index ((!))

type SomeObject =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,12 @@ module Example.MaybeNullable where

import Prelude

import Effect (Effect)
import Effect.Console (logShow)
import Control.Monad.Except (runExcept)

import Foreign (readBoolean, readNull)
import Data.Traversable (traverse)

import Effect (Effect)
import Effect.Console (logShow)
import Example.Util.Value (foreignValue)
import Foreign (readBoolean, readNull)

-- Parsing values that are allowed to null or undefined is possible by
-- using Maybe types.
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import Control.Monad.Except (runExcept)
import Effect (Effect)
import Effect.Console (logShow)
import Example.Util.Value (foreignValue)
import Foreign (readString, readNumber, readBoolean)
import Foreign (readBoolean, readNumber, readString)

-- Parsing of the simple JSON String, Number and Boolean types is provided
-- out of the box.
Expand Down
9 changes: 5 additions & 4 deletions examples/Union.purs → examples/src/Union.purs
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,11 @@ instance showStringList :: Show StringList where

readStringList :: Foreign -> Except (NonEmptyList ForeignError) StringList
readStringList value =
value ! "nil" >>=
readBoolean >>=
if _
then pure Nil
value ! "nil"
>>= readBoolean
>>=
if _ then
pure Nil
else
Cons
<$> (value ! "head" >>= readString)
Expand Down
File renamed without changes.
1 change: 0 additions & 1 deletion examples/Util/Value.purs → examples/src/Util/Value.purs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import Prelude
import Control.Monad.Except (Except)
import Data.Function.Uncurried (Fn3, runFn3)
import Data.List.NonEmpty (NonEmptyList)

import Foreign (Foreign, ForeignError(..), fail)

foreign import foreignValueImpl :: forall r. Fn3 (String -> r) (Foreign -> r) String r
Expand Down
17 changes: 10 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
{
"private": true,
"scripts": {
"clean": "rimraf output && rimraf .pulp-cache",
"build": "eslint src && pulp build -- --censor-lib --strict",
"test": "pulp build -I examples -- --censor-lib --strict"
"build": "spago build -p foreign",
"test": "spago build -p foreign-examples",
"lint": "oxlint --deny-warnings src examples/src",
"format": "purs-tidy format-in-place src examples/src && oxfmt --write .",
"format:check": "purs-tidy check src examples/src && oxfmt --check ."
},
"devDependencies": {
"eslint": "^7.15.0",
"pulp": "16.0.0-0",
"purescript-psa": "^0.8.2",
"rimraf": "^3.0.2"
"oxfmt": "^0.73.0",
"oxlint": "^1.88.0",
"purescript": "^0.15.16",
"purs-tidy": "^0.11.1",
"spago": "^1.0.5"
}
}
23 changes: 23 additions & 0 deletions spago.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package:
name: foreign
description: Library for dealing with foreign data (JavaScript objects).
build:
strict: true
pedanticPackages: true
publish:
version: 7.0.1
license: BSD-3-Clause
location:
githubOwner: purescript
githubRepo: purescript-foreign
dependencies:
- either: ">=6.0.0 <7.0.0"
- functions: ">=6.0.0 <7.0.0"
- integers: ">=6.0.0 <7.0.0"
- lists: ">=7.0.0 <8.0.0"
- maybe: ">=6.0.0 <7.0.0"
- prelude: ">=6.0.0 <7.0.0"
- strings: ">=6.0.0 <7.0.0"
- transformers: ">=6.0.0 <7.0.0"
- unsafe-coerce: ">=6.0.0 <7.0.0"
workspace: {}
8 changes: 5 additions & 3 deletions src/Foreign.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ export function isUndefined(value) {
return value === undefined;
}

export const isArray = Array.isArray || function (value) {
return Object.prototype.toString.call(value) === "[object Array]";
};
export const isArray =
Array.isArray ||
function (value) {
return Object.prototype.toString.call(value) === "[object Array]";
};
Loading
Loading