Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
barionleg authored Jan 2, 2025
1 parent b629449 commit 6b0a0ef
Show file tree
Hide file tree
Showing 12 changed files with 666 additions and 0 deletions.
30 changes: 30 additions & 0 deletions javascript-extras/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
Copyright Louis Pan (c) 2017

All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.

* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following
disclaimer in the documentation and/or other materials provided
with the distribution.

* Neither the name of Louis Pan nor the names of other
contributors may be used to endorse or promote products derived
from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
22 changes: 22 additions & 0 deletions javascript-extras/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
[![Hackage](https://img.shields.io/hackage/v/javascript-extras.svg)](https://hackage.haskell.org/package/javascript-extras)

Extra javascript functions when using GHCJS

# Changelog

* 0.5.0.0
- flipped the args of `getProperty` and `setProperty`
This makes it easier for chaining.

* 0.4.0.0
- Renamed `JSVar` to `JSRep` to avoid confusion with `JSVal`
- Renamed `toJS'` to `toJSR`
- Renamed `fromJS'` to `fromJSR`
- `getProperty` and `setProperty` uses `JE.ToJS a` instead of `Coercible a J.JSVal`
- flipped the args of `getProperty` and `setProperty`
- Moved `justSnds` to esoteric-extras `Data.Maybe.Esoteric.keepMaybes`
- Renamed `safeModularIncrement` to `safeIncrement`
- Renamed `safeModularDecrement` to `safeDecrement`

* 0.3.3.0
- Added `classNames`, `justSnds`
2 changes: 2 additions & 0 deletions javascript-extras/Setup.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import Distribution.Simple
main = defaultMain
54 changes: 54 additions & 0 deletions javascript-extras/javascript-extras.cabal
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
name: javascript-extras
version: 0.5.0.0
synopsis: Extra javascript functions when using GHCJS
description: Extra javascript functions when using GHCJS
homepage: https://github.com/louispan/javascript-extras#readme
license: BSD3
license-file: LICENSE
author: Louis Pan
maintainer: louis@pan.me
copyright: 2017 Louis Pan
category: Web
build-type: Simple
extra-source-files: README.md
cabal-version: >=1.10

library
hs-source-dirs: src
js-sources: jsbits/extras.js
exposed-modules: JavaScript.Extras
JavaScript.Extras.Cast
JavaScript.Extras.Number
JavaScript.Extras.Property
JavaScript.Extras.JSRep
JavaScript.Extras.JSRep.Unsafe
build-depends: base >= 4.7 && < 5
, deepseq >= 1.4
, newtype-generics >= 0.5
, parallel >= 3.2
, text >= 1.2
default-language: Haskell2010
ghc-options: -Wall
if impl(ghcjs)
build-depends: ghcjs-base
if !impl(ghcjs)
build-depends: ghcjs-base-stub >= 0.2

executable javascript-extras-test
hs-source-dirs: test/hs
main-is: Main.hs
ghc-options: -Wall -threaded -rtsopts -with-rtsopts=-N
cpp-options: -DGHCJS_BROWSER
build-depends: base >= 4.7 && < 5
, javascript-extras
default-language: Haskell2010
default-extensions: ApplicativeDo
if impl(ghcjs)
build-depends: ghcjs-base
, ghcjs-prim >= 0.1
if !impl(ghcjs)
build-depends: ghcjs-base-stub >= 0.2

source-repository head
type: git
location: https://github.com/louispan/javascript-extras
35 changes: 35 additions & 0 deletions javascript-extras/jsbits/extras.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// Node module dependencies
// Example package.json:
// {
// "dependencies": {
// "javascript-stringify": "^1.6.0"
// }
// }

#include <ghcjs/rts.h>

// zip list of string and JSVal to object, lists must have been completely forced first
// Using the idea from JavaScript.Array.Internal.fromList h$fromHsListJSVal
function hje$fromHsZipListJSVal(names, xs) {
var obj = {};
while(IS_CONS(names) && IS_CONS(xs)) {
obj[JSVAL_VAL(CONS_HEAD(names))] = JSVAL_VAL(CONS_HEAD(xs));
names = CONS_TAIL(names);
xs = CONS_TAIL(xs);
}
return obj;
}

var hge$javascriptStringify_ = null;
function hje$stringify(v) {
if (!hge$javascriptStringify_) {
hge$javascriptStringify_ = require('javascript-stringify');
}
return hge$javascriptStringify_(v, null, null, { references: true })
}

// Injection attack! Use with care
function hje$unstringify(str) {
eval("var ret=" + str);
return ret;
}
11 changes: 11 additions & 0 deletions javascript-extras/src/JavaScript/Extras.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
module JavaScript.Extras
( module JavaScript.Extras.Cast
, module JavaScript.Extras.JSRep
, module JavaScript.Extras.Number
, module JavaScript.Extras.Property
) where

import JavaScript.Extras.Cast
import JavaScript.Extras.JSRep
import JavaScript.Extras.Number
import JavaScript.Extras.Property
Loading

0 comments on commit 6b0a0ef

Please sign in to comment.