Registry / serialization / psharp-js

psharp-js

JSON →
library0.1.0jsnpmunverified

An implementation of the P# programming language in JavaScript, including a transpiler from P# to JavaScript. Currently at version 0.1.0, this package provides tools to translate P# code (a probabilistic programming language) into executable JavaScript. As an early-stage release, it has limited documentation and may contain bugs. Key differentiators: it enables running P# programs in Node.js or browser environments, leveraging JavaScript's ecosystem. However, it is experimental and not suitable for production use.

npm install psharp-js
INSTALL
IMPORT
SIG · PSHARP-JS
P
psharp-js
serializationjavascriptv0.1.0
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

transpile
import { transpile } from 'psharp-js'
import transpile from 'psharp-js'
Default export is not available; use named import.
run
import { run } from 'psharp-js'
const { run } = require('psharp-js');
ESM-only; no CommonJS support in v0.1.0.
PSHARP_VERSION
import { VERSION } from 'psharp-js'
import { VERSION } from 'psharp-js/core'
Version constant is exported from main entry, not a subpath.

Transpile a simple P# program with a Bernoulli sample and execute the resulting JavaScript code.

import { transpile, run } from 'psharp-js'; // Example P# code const psharpCode = ` def main() { x = sample Bernoulli(0.5); return x; } `; // Transpile to JavaScript const jsCode = transpile(psharpCode); console.log('Transpiled code:', jsCode); // Run the transpiled code (requires a random number generator environment) const result = run(jsCode); console.log('Result:', result);
Debug
Known issues
breakingAPI changes may occur without notice as the package is pre-1.0.0.
fix
Pin to specific version and test thoroughly before upgrading.
affects: >=0.0.0
deprecatedNo deprecated features currently; all features are preliminary.
fix
None.
affects: >=0.1.0
gotchaTranspiled code may not be secure; avoid running untrusted P# input.
fix
Run in a sandboxed environment or only use trusted sources.
affects: >=0.1.0
Errors
Common errors & fixes
SyntaxError: Unexpected token 'export'
Using CommonJS require() on an ESM-only package.
fix
Use import statements or set type: 'module' in package.json.
TypeError: transpile is not a function
Incorrect import style (default import instead of named import).
fix
Use import { transpile } from 'psharp-js'.
Upgrade
Version history
0.1.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
4 hits · last 30 days
node
4
Resources
psharp-js — npm install psharp-js · libregistry