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.4.3 to 0.4.4

17

lib/struct.js

@@ -17,3 +17,5 @@ 'use strict';

var factory = function factory(def) {
var factory = function factory() {
var def = arguments.length <= 0 || arguments[0] === undefined ? {} : arguments[0];
var prop_info = Object.keys(def).map(function (key) {

@@ -35,2 +37,5 @@ var _ref = def[key] instanceof _mutability.Mutability ? { type: def[key].data, mutable: def[key].mutable } : { type: def[key], mutable: false };

if (!(this instanceof struct)) {
return new struct(props);
}
prop_info.forEach(function (_ref2) {

@@ -58,7 +63,3 @@ var name = _ref2.name;

var creator = function creator(props) {
return new struct(props);
};
creator.toString = function () {
struct.toString = function () {
var props = prop_info.map(function (prop) {

@@ -70,7 +71,5 @@ return prop.name + ': ' + prop.type;

struct.prototype = creator.prototype;
return creator;
return struct;
};
exports.default = factory;
{
"name": "rusted",
"version": "0.4.3",
"version": "0.4.4",
"description": "Rust like enum, Result and Option for javascript",

@@ -5,0 +5,0 @@ "main": "lib/index.js",

@@ -19,2 +19,4 @@ [![npm version](https://badge.fury.io/js/rusted.svg)](https://badge.fury.io/js/rusted)

+ [x] mutable property
+ [ ] tuple struct
+ [ ] unit struct
- [x] `impl`

@@ -21,0 +23,0 @@ - [x] static method (associated function)

@@ -7,3 +7,3 @@ import panic from './panic';

let factory=function(def){
let factory=function(def={}){
let prop_info=Object.keys(def).map((key)=>{

@@ -21,2 +21,5 @@ let {type,mutable}=def[key] instanceof Mutability

let struct=function(props){
if(!(this instanceof struct)){
return new struct(props);
}
prop_info.forEach(({name,type,mutable})=>{

@@ -39,16 +42,10 @@ name in props

let creator=(props)=>{
return new struct(props);
};
creator.toString=()=>{
let props=prop_info.map((prop)=>`${prop.name}: ${prop.type}`).join(',');
struct.toString=function(){
let props=prop_info.map(prop=>`${prop.name}: ${prop.type}`).join(',');
return `rusted struct type: {${props} }`;
};
struct.prototype=creator.prototype;
return creator;
return struct;
};
export default factory;

@@ -5,2 +5,4 @@ import {expect} from 'chai';

import impl from '../src/impl';
import {imm,mut} from '../src/mutability';

@@ -91,2 +93,17 @@

});
it('should works properly if no arguments (Unit-like struct)',()=>{
let Unit=struct();
impl(Unit,{
foo(){
return 3;
},
bar(self){
return 4;
}
});
let value=Unit();
expect(value.bar()).to.equal(4);
expect(Unit.foo()).to.equal(3);
});
it('should works properly',()=>{

@@ -93,0 +110,0 @@ let OtherStruct=struct({

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