https://github.com/purescript/purescript-foreign-object
Functions for working with homogeneous JavaScript objects
https://github.com/purescript/purescript-foreign-object
Last synced: 10 months ago
JSON representation
Functions for working with homogeneous JavaScript objects
- Host: GitHub
- URL: https://github.com/purescript/purescript-foreign-object
- Owner: purescript
- License: bsd-3-clause
- Created: 2018-05-03T16:11:45.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2022-10-27T16:36:57.000Z (about 3 years ago)
- Last Synced: 2024-10-29T21:05:41.370Z (about 1 year ago)
- Language: PureScript
- Homepage:
- Size: 323 KB
- Stars: 29
- Watchers: 8
- Forks: 16
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# purescript-foreign-object
[](https://github.com/purescript/purescript-foreign-object/releases)
[](https://github.com/purescript/purescript-foreign-object/actions?query=workflow%3ACI+branch%3Amaster)
[](https://pursuit.purescript.org/packages/purescript-foreign-object)
Functions for working with homogeneous JavaScript objects from PureScript. Similar to using `Map String a` but simply reusing JavaScript objects.
## Installation
```
spago install foreign-object
```
## Example
```purs
example = do
let
-- make an empty Object
empty = FO.empty
-- insert to an empty Object
inserted = FO.insert "a" 1 empty
-- or: use the singleton function
-- singleton FO.singleton "a" 1
-- lookup values for existing in the Object as a result of Maybe
let lookup = FO.lookup "a" inserted
Assert.assertEqual { actual: lookup, expected: Just 1 }
-- delete a value from an Object
let deleted = FO.delete "a" inserted
Assert.assertEqual { actual: deleted, expected: FO.empty }
let
-- convert homogeneous records to Object
converted = FO.fromHomogeneous { a: 1, b: 2, c: 3}
-- check that the converted is equal to a regularly built Object
built
= FO.empty
# FO.insert "a" 1
# FO.insert "b" 2
# FO.insert "c" 3
Assert.assertEqual { actual: converted, expected: built }
```
See the [tests](test/Main.purs) for more examples.
## Documentation
Module documentation is [published on Pursuit](http://pursuit.purescript.org/packages/purescript-foreign-object).