New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

functionalscript

Package Overview
Dependencies
Maintainers
0
Versions
452
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

functionalscript - npm Package Compare versions

Comparing version 0.1.608 to 0.1.609

CHANGELOG.md

33

doc/LANGUAGE.md
# FunctionalScript Programming Language
Principals:
- FunctionalScript VM should behaves the same way as a JavaScript VM
Principles:
- FunctionalScript VM should behaves the same way as a JavaScript VM,
- Any unsupported feature should be reported at compile-time.

@@ -9,6 +10,6 @@

FunctionalScript uses [CommonJS](https://en.wikipedia.org/wiki/CommonJS) conventions as a module ecosystem. For example,
FunctionalScript uses ESM conventions as a module ecosystem. For example,
```js
const thirdPartyModule = require('third-party-package/module')
import thirdPartyModule from 'third-party-package/module'

@@ -43,6 +44,6 @@ const result = thirdPartyModule.someFunction('hello')

`./first.js`
`./first.f.mjs`
```js
// 1. references
const math = require('math')
import math from 'math'

@@ -57,3 +58,3 @@ // 2. definitions

// 3. exports
module.exports = {
export default {
addition,

@@ -65,6 +66,6 @@ add42,

`./second.js`
`./second.f.mjs`
```js
// 1. references
const first = require('./first.js')
import first from './first.f.mjs'

@@ -75,3 +76,3 @@ // 2. definitions

// 3. exports
module.exports = {
export default {
_42plus7,

@@ -83,8 +84,8 @@ }

The format of references is `const ANYNAME = require('PATH_TO_A_MODULE')`. For example,
The format of references is `import ANYNAME from 'PATH_TO_A_MODULE'`. For example,
```js
const math = require('math')
const algebra = require('math/algebra')
const localFile = require('../some-directory/some-file.js')
import math from 'math'
import algebra from 'math/algebra'
import localFile from '../some-directory/some-file.f.mjs'
```

@@ -116,7 +117,7 @@

The format of exports is `module.exports = { A_LIST_OF_EXPORTED_DEFINITIONS }`. There should be only one `module.exports` at
The format of exports is `export default { A_LIST_OF_EXPORTED_DEFINITIONS }`. There should be only one `export default` at
the end of a FunctionalScript file. For example,
```js
module.exports = {
export default {
nestedStructure,

@@ -123,0 +124,0 @@ array,

# Documentation
FunctionalScript files have `.f.cjs` file extensions because it's using a `Common.JS` module system. We plan to add
ESM support when we have the first parser working. See
[ESM. Resolver Algorithm Specification](https://nodejs.org/api/esm.html#resolver-algorithm-specification)
and [ESM. Enabling](https://nodejs.org/docs/latest-v13.x/api/esm.html#esm_enabling).
FunctionalScript files have `.f.mjs` file extensions because it's using the ES module system.
## 1. Creating a New Repository
## 1. Language
Creating from a template https://github.com/functionalscript/template/generate
### 1.1. Exports
## 1.1. Creating From Scratch
Prerequisites:
- [Git](https://git-scm.com/).
- [Node.js](https://nodejs.org/en/).
- GitHub account.
Creating a new GitHub repository
1. Create a public git repository on GitHub using Node template.
2. Clone the repository.
3. Go to the root directory of the cloned repository.
4. Run `npm init`. It should create `package.json` file.
5. Create a `main.f.cjs` file in the repository root directory.
6. Edit the `main.f.cjs` file. For example
```js
module.exports = "Hello world!"
```
11. Go to [functionalscript.com](https://functionalscript.com) and enter `github:YOUR_GITHUB_NAME/YOUR_REPOSITORY_NAME`. Press `Build`.
### 1.1. Optional
1. Install [Visual Studio Code](https://code.visualstudio.com/).
2. Add [TypeScript](https://www.typescriptlang.org/) to your repository for static type checking.
1. Run `npm install -D typescript`.
2. Run `npx tsc --init`. It should create `tsconfig.json` file.
3. Uncomment `"allowJs": true,` and `"checkJs": true` in the `tsconfig.json` file.
## 2. Language
### 2.1. Exports
```js
module.exports = 'Hello world!'
export default 'Hello world!'
```
```js
module.exports = { a: 'hello', b: 42 }
export default { a: 'hello', b: 42 }
```
```js
module.exports = x => x * x
export default x => x * x
```
### 2.2. Reference Another Module
### 1.2. Reference Another Module
#### 2.2.1. Local File
#### 1.2.1. Local File
```js
const x = require('./folder/main.f.cjs')
import x from './folder/main.f.mjs'
```
### 2.2.2. External Module
### 1.2.2. External Module

@@ -70,6 +34,6 @@ Run `npm install -D github:USER/REPO`

```js
const x = require(`REPO/DIR/FILE.f.cjs`)
import x from `REPO/DIR/FILE.f.mjs`
```
### 2.3. Functions
### 1.3. Functions

@@ -87,5 +51,5 @@ ```js

## 3. Advanced
## 2. Advanced
### 3.1. Generators
### 2.1. Generators

@@ -92,0 +56,0 @@ ```js

@@ -79,3 +79,2 @@ # FunctionalScript Compiler

- `export`
- `exports` <= non-standard
- `false`

@@ -90,7 +89,5 @@ - `function` ?

- `let`
- `module` <= non-standard
- `new` ?
- `null`
- `of`
- `require` <= non-standard
- `return`

@@ -97,0 +94,0 @@ - `super`

@@ -110,5 +110,5 @@ # FSM

```js
const map = require('./types/map/module.f.js')
import map from './types/map/module.f.mjs'
const a = map.fromEntries(Object.entries({ x: 5, y: 6 }))
const b = map.setReplace('z')(7)(a)
```

@@ -8,1 +8,25 @@ # HTML

|`<a href="https://example.com/">Example</a>`|`['a',{href:'https://example.com/'},['Example']]`|
## Example
```html
<html>
<head>
<title>Page</title>
</head>
<body>
<a href="https://example.com/">Example</a>
</body>
</html>
```
```js
['html', [
['head', [
['title', ['Page']]
]]
['body', [
['a', { href: 'https://example.com/' }, ['Example']]
]]
]]
```

@@ -13,1 +13,39 @@ # JSON

File extension: `.json`.
## NPN (Normal Polish Notation)
We will use [NPN](https://en.wikipedia.org/wiki/Polish_notation) as a command format for our VM because it allows us to allocate required objects during streaming as a stack automata.
```js
{2} "a" null "b" [3] -42.5 false "hello"
// evolution
<> {2} "a" null "b" [3] -42.5 false "hello"
{ ?: ?, ?: ? } <{4}> "a" null "b" [3] -42.5 false "hello"
{ "a": ?, ?: ? } <{3}> null "b" [3] -42.5 false "hello"
{ "a": null, ?: ? } <{2}> "b" [3] -42.5 false "hello"
{ "a": null, "b": ? } <{1}> [3] -42.5 false "hello"
{ "a": null, "b": [?, ?, ?] } <{0}[3]> -42.5 false "hello"
{ "a": null, "b": [-42.5, ?, ?] } <{0}[2]> false "hello"
{ "a": null, "b": [-42.5, false, ?] } <{0}[1]> "hello"
{ "a": null, "b": [-42.5, false, "hello"] } <>
```
## RPN, just for fun
[Reverse Polish Notation](https://en.wikipedia.org/wiki/Reverse_Polish_notation):
```js
"a" null "b" -42.5 false "hello" [3] {2}
// evolution:
"a" <> null "b" -42.5 false "hello" [3] {2}
"a" null <> "b" -42.5 false "hello" [3] {2}
"a" null "b" <> -42.5 false "hello" [3] {2}
"a" null "b" -42.5 <> false "hello" [3] {2}
"a" null "b" -42.5 false <> "hello" [3] {2}
"a" null "b" -42.5 false "hello" <> [3] {2}
"a" null "b" [-42.5, false, "hello"] <> {2}
{ "a" : null, "b": [-42.5, false, "hello"] } <>
```
# Default Export
Parse `export default` and then JSON. This's enough to have the same functionality as JSON.
Parse `export default` and then JSON. This is enough to have the same functionality as JSON.

@@ -9,4 +9,4 @@ ```js

Depends on [JSON](./1110-json.md)
Depends on [JSON](./1000-json.md)
See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/export#using_the_default_export.
# Undefined Type
```js
export default void 0
export default undefined
```
Depend on [default-export](./2110-default-export.md).
# Built-in Objects and Functions
The built-in objects are special. We can get a function, like `Object.getOwnPropertyDescriptor`, but not the `Object` itself.
The built-in objects are special. We can call a function, like `Object.getOwnPropertyDescriptor()`, but not the `Object` or the function.
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects
Some of the JS built-in objects and functions are "not allowed" in FS. It means, an FS compiler rejects code that contains "not allowed" objects and functions.
Some of the JS built-in objects and functions are "not allowed" in FS. It means, an FS compiler rejects code that contains "not allowed" objects and functions.

@@ -13,31 +13,28 @@ ## Object

Functions:
|Function |side-effect |
|-------------------------|---------------------------|
|assign |mutate |
|create |creates a special prototype|
|defineProperties |mutate |
|defineProperty |mutate |
|entries |no |
|freeze |mutate |
|fromEntries |no |
|getOwnPropertyDescriptor |no |
|getOwnPropertyDescriptors|no |
|getOwnPropertyNames |no |
|getOwnPropertySymbols |return symbols |
|getPrototypeOf |return prototypes |
|groupBy |return null-property object|
|hasOwn |no |
|is |no |
|isExtensible |no |
|isFrozen |no |
|isSealed |no |
|keys |no |
|preventExtensions |mutate |
|seal |mutate |
|setPrototypeOf |mutate |
|values |no |
|Function |Priority |
|-------------------------|-----------|
|constructor |not allowed|
|assign |not allowed|
|create |not allowed|
|defineProperties |not allowed|
|defineProperty |not allowed|
|entries |1 |
|freeze |not allowed|
|fromEntries |1 |
|getOwnPropertyDescriptor |1 |
|getOwnPropertyDescriptors|1 |
|getOwnPropertyNames |1 |
|getOwnPropertySymbols |not allowed|
|getPrototypeOf |not allowed|
|groupBy |1 |
|hasOwn |1 |
|is |1 |
|isExtensible |not allowed|
|isFrozen |not allowed|
|isSealed |not allowed|
|keys |1 |
|preventExtensions |not allowed|
|seal |not allowed|
|setPrototypeOf |not allowed|
|values |1 |
## Array

@@ -47,30 +44,40 @@

|Function |Priority |
|Function |side-effect|
|-------------------------|-----------|
|from |1 |
|fromAsync |1 |
|isArray |1 |
|of |1 |
|from |no |
|fromAsync |? |
|isArray |no |
|of |no |
## BigInt
|Function |Priority |
|Function |side-effect|
|-------------------------|-----------|
|asIntN |1 |
|asUintN |1 |
|asIntN |no |
|asUintN |no |
## JSON
|Function |Priority |
|Function |side-effects|
|-------------------------|-----------|
|`isRawJSON` |3 |
|`parse` |2 |
|`rawJSON` |3 |
|`stringify` |2 |
|`isRawJSON` |no |
|`parse` |no |
|`rawJSON` |no |
|`stringify` |no |
## Others
`Infinity`
`isFinite()`
`isNaN()`
`NaN`
|Function |side-effect|
|-------------------------|-----------|
|`decodeURI()` |no |
|`decodeURIComponent()` |no |
|`encodeURI()` |no |
|`encodeURIComponent()` |no |
|`eval()` |no |
|Property |side-effect|
|------------|-----------|
|`Infinity` |no |
|`isFinite()`|no |
|`isNaN()` |no |
|`NaN` |no |
# FunctionalScript Language
Two main FunctionsScript princples:
1. if FS code pass validation/compilation, then it doesn't have side-effects,
2. the code that passed validation/compilation should behave on FunctionalScript VM the same way as on any other modern JavaScript engine.
When we implement features of FunctionalScript, the first priority is a simplification of the VM.

@@ -19,2 +23,16 @@

**VM**:
We are introducing new commands in the order that every new command depends only on previous commands.
|format|any |Tag| |
|------|--------------|---|----------|
|JSON |null | 00| |
| |number | 01|u64 |
| |false | 02| |
| |true | 03| |
| |string | 04|String |
| |array | 05|Array<Any>|
| |object | 06|Object |
## 2. DJS

@@ -26,7 +44,19 @@

|format|any |Tag| |Notes |
|------|------------------------|---|----------|------------------------------------------------|
|DJS |const_ref | 07|u32 |[const](./2120-const.md) |
| |bigint_plus | 08|Array<u64>|[bigint](./2320-bigint.md) |
| |bigint_minus | 09|Array<u64>|[bigint](./2320-bigint.md) |
| |undefined | 0A| |[undefined](./2310-undefined.md) |
| |own_property | 0B| |[property-accessor](./2330-property-accessor.md)|
| |instance_property | 0C| |[property-accessor](./2330-property-accessor.md)|
| |instance_method_call | 0D| |[property-accessor](./2330-property-accessor.md)|
| |at | 0E| |[property-accessor](./2330-property-accessor.md)|
| |operators | | |[operators](./2340-operators.md) |
### 2.1. Required
1. [ ] [default-export](./2110-default-export.md)
2. [ ] [const](./2120-const.md)
3. [ ] [default-import](./2130-default-import.md)
1. [ ] [default-export](./2110-default-export.md),
2. [ ] [const](./2120-const.md),
3. [ ] [default-import](./2130-default-import.md).

@@ -37,24 +67,21 @@ ### 2.2. Priority 1

1. [ ] [block-comment](./2210-block-comment.md)
2. [ ] [namespace-import](./2220-namespace-import.md)
1. [ ] [block-comment](./2210-block-comment.md),
2. [ ] [namespace-import](./2220-namespace-import.md).
### 2.3. Priority 2
1. [ ] [undefined](./231-undefined.md)
2. [ ] [bigint](./232-bigint.md)
3. [ ] [grouping](./233-grouping.md)
4. [ ] [operators](./234-operators.md)
5. [ ] Property Accessors:
1. [ ] [property-accessor](./2351-property-accessor.md)
2. [ ] [property-call](./2352-property-call.md)
3. [ ] [at](./2353-at.md)
6. [ ] [global](./2360-built-in.md)
1. [ ] [undefined](./2310-undefined.md),
2. [ ] [bigint](./2320-bigint.md),
3. [ ] [property-accessor](./2330-property-accessor.md),
4. [ ] [operators](./2340-operators.md),
5. [ ] [grouping](./2350-grouping.md),
6. [ ] [built-in](./2360-built-in.md).
### 2.4. Syntactic Sugar
1. [ ] [identifier-property](./2410-identifier-property.md)
2. [ ] [line-comment](./2420-line-comment.md)
3. [ ] [trailing-comma](./2430-trailing-comma.md)
4. [ ] [shorthand](./2440-shorthand.md)
5. [ ] [destructuring](./2450-destructuring.md)
1. [ ] [identifier-property](./2410-identifier-property.md),
2. [ ] [line-comment](./2420-line-comment.md),
3. [ ] [trailing-comma](./2430-trailing-comma.md),
4. [ ] [shorthand](./2440-shorthand.md),
5. [ ] [destructuring](./2450-destructuring.md).

@@ -67,2 +94,6 @@ ## 3. FJS

|format|any |Tag| |Notes |
|------|--------|---|----|--------------------------------|
|FJS |function| |Func|[function](./3110-function.md) |
### 3.1. Required

@@ -76,10 +107,21 @@

1. [ ] `if`
1. [ ] `if`. See https://developer.mozilla.org/en-US/docs/Glossary/Falsy
2. [ ] [let](./3220-let.md)
3. [ ] `while`
4. [ ] [export](./3240-export.md)
### 3.3. Syntactic Sugar
1. [ ] [expression](./321-expression.md)
2. [ ] [one-parameter](./322-one-parameter.md)
1. [ ] [expression](./3210-expression.md)
2. [ ] [one-parameter](./3220-one-parameter.md)
3. [ ] [assignments](./3330-assignments.md)
## 4. ECMAScript Proposals
1. [ ] [Type Annotations](https://github.com/tc39/proposal-type-annotations), Stage 1:
- [Node.js](https://nodejs.org/en/learn/typescript/run-natively),
- `Deno` supports TypeScript,
- `Bun` supports TypeScript,
- most browsers don't support the feature.
2. [ ] [Pipe Operator `|>`](https://github.com/tc39/proposal-pipeline-operator), Stage 2.
3. [ ] [Records and Tuples](https://github.com/tc39/proposal-record-tuple), Stage 2.
# Issues
1. [X] [test-debug](./test-debug.md).
2. [X] [esm](./esm.md)
3. [ ] [djs](./djs.md)
1. [X] [test-debug](./01-test-debug.md).
2. [X] [esm](./02-esm.md)
3. [ ] [djs](./03-djs.md)
4. [ ] VM Rust project
5. [ ] [publish](publish.md)
5. [ ] [publish](./05-publish.md)
6. [ ] fix index generation by including sub modules `{ ...m, add: mAdd, remove: mRemove}`.
7. [ ] Conventions:
```js

@@ -15,11 +16,17 @@ import list, * as List from 'list.mjs'

```
8. Move logic from `.mjs` files to `.f.mjs` files.
9. Two sets of property filters:
- usage `.b`:
- `constructor`
- ...
- call `.b()`:
- `push`
- ...
10. [ ] Replace file extensions from `.mjs` to `.js`. Make sure `package.json/type` is equal to `module`. May be later: https://v8.dev/features/modules#mjs
11. [ ] [fs-load](./fs-load.md)
9. [ ] Generating a Website.
10. [ ] Short URL table.
11. [ ] [fs-load](./11-fs-load.md)
12. [ ] Replace file extensions from `.mjs` to `.js`. Make sure `package.json/type` is equal to `module`. May be later: https://v8.dev/features/modules#mjs
13. [ ] Docs for JSR. See https://jsr.io/@functionalscript/functionalscript/score
14. [ ] Combine `npm run index` and `npm run version`
15. [ ] Generate `package.json/exports` instead of `index.f.mjs`.
16. [ ] License in JSR file?
17. [ ] [djs-extension](./17-djs-extension.md).
18. [ ] Formatter for `.f.js` and `.f.ts` files.
19. [ ] Convert FunctionalScript code using non-default `export`.
20. [ ] Test framework should be able to run a subset of tests.
21. [ ] Test Framework silent mode. Show progress and failled tests only.
22. [ ] bit sequences based on bigint
{
"name": "@functionalscript/functionalscript",
"version": "0.1.608",
"version": "0.1.609",
"exports": {

@@ -5,0 +5,0 @@ "./com/cpp": "./com/cpp/module.f.mjs",

{
"name": "functionalscript",
"version": "0.1.608",
"version": "0.1.609",
"type": "module",

@@ -5,0 +5,0 @@ "description": "FunctionalScript is a functional subset of JavaScript",

@@ -6,3 +6,3 @@ # FunctionalScript

FunctionalScript is a purely functional programming language and a strict subset of
FunctionalScript is a safe, purely functional programming language and a strict subset of
[ECMAScript](https://en.wikipedia.org/wiki/ECMAScript)/[JavaScript](https://en.wikipedia.org/wiki/JavaScript). It's inspired by

@@ -9,0 +9,0 @@

@@ -37,3 +37,3 @@ # UNICODE

### utf8/module.f.cjs
### utf8/module.f.mjs

@@ -73,3 +73,3 @@ ```js

### utf16/module.f.cjs
### utf16/module.f.mjs

@@ -76,0 +76,0 @@ ```js

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc