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

rusted

Package Overview
Dependencies
Maintainers
1
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

rusted - npm Package Compare versions

Comparing version 0.1.2 to 0.1.3

.travis.yml

29

lib/result.js

@@ -20,2 +20,4 @@ 'use strict';

var _option = require('./option');
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

@@ -41,7 +43,22 @@

},
//ok(self){
//},
//err(self){
//},
ok: function ok(self) {
return (0, _match2.default)(self, {
Ok: function Ok(x) {
return (0, _option.Some)(x);
},
Err: function Err(_) {
return _option.None;
}
});
},
err: function err(self) {
return (0, _match2.default)(self, {
Ok: function Ok(_) {
return _option.None;
},
Err: function Err(x) {
return (0, _option.Some)(x);
}
});
},
map: function map(self, op) {

@@ -153,3 +170,3 @@ return (0, _match2.default)(self, {

Ok: function Ok(t) {
return unwrap_failed('called `Result::unwrap_err()` on an `Ok` value', e);
return unwrap_failed('called `Result::unwrap_err()` on an `Ok` value', t);
},

@@ -156,0 +173,0 @@ Err: function Err(e) {

{
"name": "rusted",
"version": "0.1.2",
"version": "0.1.3",
"description": "Rust like enum, Result and Option for javascript",

@@ -8,3 +8,4 @@ "main": "lib/index.js",

"test": "$(npm bin)/babel-node ./node_modules/mocha/bin/_mocha",
"cover": "$(npm bin)/babel-node ./node_modules/isparta/bin/isparta cover --report html ./node_modules/mocha/bin/_mocha"
"cover": "$(npm bin)/babel-node ./node_modules/isparta/bin/isparta cover --report lcov --report html ./node_modules/mocha/bin/_mocha",
"coveralls": "$(npm bin)/babel-node ./node_modules/isparta/bin/isparta cover --report lcovonly ./node_modules/mocha/bin/_mocha && cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js"
},

@@ -35,3 +36,4 @@ "repository": {

"babel-cli": "~6.4.5",
"isparta": "~4.0.0"
"isparta": "~4.0.0",
"coveralls": "~2.11.6"
},

@@ -38,0 +40,0 @@ "dependencies": {

@@ -0,4 +1,8 @@

[![npm version](https://badge.fury.io/js/rusted.svg)](https://badge.fury.io/js/rusted)
[![Coverage Status](https://coveralls.io/repos/github/pocka/rusted/badge.svg?branch=master)](https://coveralls.io/github/pocka/rusted?branch=master)
[![Build Status](https://travis-ci.org/pocka/rusted.svg?branch=master)](https://travis-ci.org/pocka/rusted)
# rusted
Rust-like enum, impl and match for javascript.
Rust-like enum, Result, Option, impl and match for javascript.

@@ -11,5 +15,33 @@ ## Install

## Example
This example requires es6 transpiler.
These examples require es6 transpiler.
### enum
```rust
enum Message {
Quit,
ChangeColor(i32,i32,i32),
Move {x:i32, y:i32},
Write(String),
}
let x: Message = Message::Move { x: 3, y: 4 };
let y: Message = Message::Quit;
```
the above could written as below
```javascript
import {Enum} from 'rusted';
let Message=Enum({
Quit:null,
ChangeColor:[0,0,0],
Move:{x:0,y:0},
Write:''
});
let x=Message.Move({x:3,y:4});
let y=Message.Quit;
```
### Result
```javascript
import {Ok,Err,match} from 'rusted';

@@ -16,0 +48,0 @@

import Enum from './enum';
import impl from './impl';
import match from './match';
import {Some,None} from './option';

@@ -22,6 +23,14 @@ let Result=Enum({

},
//ok(self){
//},
//err(self){
//},
ok(self){
return match(self,{
Ok:x=>Some(x),
Err:_=>None
});
},
err(self){
return match(self,{
Ok:_=>None,
Err:x=>Some(x)
});
},
map(self,op){

@@ -91,3 +100,3 @@ return match(self,{

return match(self,{
Ok:t=>unwrap_failed('called `Result::unwrap_err()` on an `Ok` value',e),
Ok:t=>unwrap_failed('called `Result::unwrap_err()` on an `Ok` value',t),
Err:e=>e

@@ -94,0 +103,0 @@ });

@@ -24,2 +24,24 @@ let expect=require('chai').expect;

});
describe('#ok',()=>{
it('should returns Some(2)',()=>{
let x=Ok(2);
expect(x.ok().unwrap()).to.equal(2);
expect(x.ok().is_some()).to.be.true;
});
it('should returns None',()=>{
let x=Err('Nothing here');
expect(x.ok().is_none()).to.be.true;
});
});
describe('#err',()=>{
it('should returns None',()=>{
let x=Ok(2);
expect(x.err().is_none()).to.be.true;
});
it('should returns Some("Nothing here")',()=>{
let x=Err('Nothing here');
expect(x.err().unwrap()).to.equal('Nothing here');
expect(x.err().is_some()).to.be.true;
});
});
describe('#map',()=>{

@@ -26,0 +48,0 @@ it('should apply handler',()=>{

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