Skip to content

Commit

Permalink
features: list operate, update docs, fixes
Browse files Browse the repository at this point in the history
- operate lists (array numbers)
- fix error `=>`
- update docs
- new file structure
- more test cases
  • Loading branch information
juliandavidmr committed Jul 10, 2017
1 parent 19c6757 commit 3b11ae7
Show file tree
Hide file tree
Showing 17 changed files with 851 additions and 223 deletions.
4 changes: 1 addition & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
# js
src/parser.js

# Logs
logs
*.log
Expand Down Expand Up @@ -61,3 +58,4 @@ typings/
.env

/.idea/
/src/parser.js
File renamed without changes.
91 changes: 91 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
# Contributing

When contributing to this repository, please first discuss the change you wish to make via issue,
email, or any other method with the owners of this repository before making a change.

Please note we have a code of conduct, please follow it in all your interactions with the project.

## Pull Request Process

1. Fork it repo.
2. Clone repo: ```git clone https://github.com/juliandavidmr/sylver```
3. Ensure any install or build dependencies are removed before the end of the layer when doing a
build.
4. Do your magic.
5. Update the README.md with details of changes.
6. Send a PR _(pull request)_ with your changes.

## Code of Conduct

### Our Pledge

In the interest of fostering an open and welcoming environment, we as
contributors and maintainers pledge to making participation in our project and
our community a harassment-free experience for everyone, regardless of age, body
size, disability, ethnicity, gender identity and expression, level of experience,
nationality, personal appearance, race, religion, or sexual identity and
orientation.

### Our Standards

Examples of behavior that contributes to creating a positive environment
include:

* Using welcoming and inclusive language
* Being respectful of differing viewpoints and experiences
* Gracefully accepting constructive criticism
* Focusing on what is best for the community
* Showing empathy towards other community members

Examples of unacceptable behavior by participants include:

* The use of sexualized language or imagery and unwelcome sexual attention or
advances
* Trolling, insulting/derogatory comments, and personal or political attacks
* Public or private harassment
* Publishing others' private information, such as a physical or electronic
address, without explicit permission
* Other conduct which could reasonably be considered inappropriate in a
professional setting

### Our Responsibilities

Project maintainers are responsible for clarifying the standards of acceptable
behavior and are expected to take appropriate and fair corrective action in
response to any instances of unacceptable behavior.

Project maintainers have the right and responsibility to remove, edit, or
reject comments, commits, code, wiki edits, issues, and other contributions
that are not aligned to this Code of Conduct, or to ban temporarily or
permanently any contributor for other behaviors that they deem inappropriate,
threatening, offensive, or harmful.

### Scope

This Code of Conduct applies both within project spaces and in public spaces
when an individual is representing the project or its community. Examples of
representing a project or community include using an official project e-mail
address, posting via an official social media account, or acting as an appointed
representative at an online or offline event. Representation of a project may be
further defined and clarified by project maintainers.

### Enforcement

Instances of abusive, harassing, or otherwise unacceptable behavior may be
reported by contacting the project team at [INSERT EMAIL ADDRESS]. All
complaints will be reviewed and investigated and will result in a response that
is deemed necessary and appropriate to the circumstances. The project team is
obligated to maintain confidentiality with regard to the reporter of an incident.
Further details of specific enforcement policies may be posted separately.

Project maintainers who do not follow or enforce the Code of Conduct in good
faith may face temporary or permanent repercussions as determined by other
members of the project's leadership.

### Attribution

This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
available at [http://contributor-covenant.org/version/1/4][version]

[homepage]: http://contributor-covenant.org
[version]: http://contributor-covenant.org/version/1/4/
7 changes: 7 additions & 0 deletions CONTRIBUTORS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
## Contributors

* **Julian David** - *Initial work* - [@juliandavidmr](https://github.com/juliandavidmr)
- [Twitter](https://twitter.com/anlijudavid)


> #### You could be a contributor. ☺
117 changes: 90 additions & 27 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,8 @@
- Compatible with JavaScript.
- Contains a flexible expression parser.
- Comes with a large set of built-in functions and constants.
- Has no dependencies. Runs on any JavaScript engine.
Can be used as a command line application as well.
Is easily extensible.
- Developed using [jison](https://zaa.ch/jison)
- Has no dependencies. Runs on any JavaScript engine.
- Can be used as a command line application as well.
- Open source.

## Usage
Expand Down Expand Up @@ -47,7 +45,12 @@ sylver("if(3+8<=23)12:3") // 12

// intervals
sylver("2 to 8") // [2, 3, 4, 5, 6, 7, 8]
sylver("(4*PI) to (23/2)") // [11.5, 12.5]
sylver("(4*PI) to (23/2)") // [11.5, 12.5]
sylver("2 * (6 to 10)") // [ 12, 14, 16, 18, 20 ]

// list
sylver("[2, 3, 5, 1] * [6, 3, 5, 4, 102]") // [ 12, 9, 25, 4, 102 ]
sylver("")

// algebra
sylver("cos(4)") // -0.6536436208636119
Expand All @@ -72,9 +75,70 @@ Enter from the command terminal:
sylver --help
```

## Documentation

### Mathematical operators

| Operator | Description |
| -------- | ----------- |
| + | addition |
| - | subtraction |
|| multiplication |
| / | right division, i.e. `x/y` |
| ˆ | power, i.e. `x^y` |


### Mathematical functions: trigonometry

| functions |
| ----------- |
| log log10 log1p log2 sqrt, cos, tan, sin, atan, asin, acos, atanh, acosh, asinh |

### Intervals

Sylver is able to generate lists of numbers from a range:
````js
sylver("1 to 7") // [ 1, 2, 3, 4, 5, 6, 7 ]
sylver("2 * (6 to 10)") // [12, 14, 16, 18, 20]
sylver("(1 to 4) * [2, 4, 6, 7]") // [ 2, 8, 18, 28 ]
sylver("(1 to 4) * 3") // [ 3, 6, 9, 12 ]
sylver("1 to (10/2) + 10") // [11, 12, 13, 14, 15]
````

The order of the operators is important:
````js
sylver("10 / [2, 5, 4]") // [5, 2, 2.5]

// This is different from:
sylver("[2, 5, 4] / 10") // [0.2, 0.5, 0.4]
````

### Conditions
Evaluate expressions and returns a decision:
```js
sylver(`if((5*2)>(6*2)) 80 : 35 `) // 35
```
You can use the returned result to operate with other expressions:
```js
sylver("(if(3>0)1:2)*5)") // 5
```

### Constants

Currently there are two constants available: `PI`, `E`
```js
sylver("PI") // 3.141592653589793
sylver("E") // 2.718281828459045
```

## Browser support
__// TODO__
Sylver works on any ES5 compatible JavaScript engine: node.js 0.10, and Internet Explorer 9 and newer, and all other browsers (Chrome, Firefox, Safari). If support for old browsers like Internet Explorer 8 is required, the es5-shim library has to be loaded.
__// TODO: Version for browsers in development__
Sylver works on any ES5 compatible JavaScript engine: node.js 0.10,
and Internet Explorer 9 and newer, and all other browsers (Chrome, Firefox, Safari).
If support for old browsers like Internet Explorer 8 is required,
the es5-shim library has to be loaded.
Use function parser from [parser.js](https://github.com/juliandavidmr/sylver/blob/master/src/parser.js) file.


## Build

Expand Down Expand Up @@ -107,26 +171,25 @@ npm test
The tests are run with [ava](https://github.com/avajs/ava)


### [See changelog](./CHANGELOG)
## Built With
* [jison](https://zaa.ch/jison) - Bison in JavaScript

## Contributing

Please read [CONTRIBUTING.md](./CONTRIBUTING.md) for details on our code of conduct, and the process for submitting pull requests to us.

## Versioning

We use [SemVer](http://semver.org/) for versioning.

## Authors

* **Julian David** - *Initial work* - [@juliandavidmr](https://github.com/juliandavidmr)

See also the list of [contributors](./CONTRIBUTORS.md) who participated in this project.

### [See changelog](CHANGELOG.md)

## License

Copyright (c) 2017 Julian David

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
This project is licensed under the MIT License - see the [LICENSE](./LICENSE) file for details
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@
"ava": {
"files": [
"test/*.js",
"!**/lib.js"
"!**/lib.js",
"!test/test.js"
],
"source": [
"**/*.{js,jsx}",
Expand Down
Loading

0 comments on commit 3b11ae7

Please sign in to comment.