Huge News!Announcing our $40M Series B led by Abstract Ventures.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.5 to 1.0.0

2

lib/impl.js

@@ -23,3 +23,3 @@ 'use strict';

var setter = target.prototype ? function (name, fn) {
(0, _util.is_static_method)(fn) ? target[name] = fn : target.prototype[name] = function () {
name[0] === '$' ? target[(0, _util.format_static_method_name)(name)] = fn : target.prototype[name] = function () {
return fn.apply({}, [this].concat(Array.prototype.slice.call(arguments, 0)));

@@ -26,0 +26,0 @@ };

@@ -10,2 +10,3 @@ 'use strict';

exports.is_empty_function = is_empty_function;
exports.format_static_method_name = format_static_method_name;
exports.check_type = check_type;

@@ -20,2 +21,6 @@ function is_static_method(fn) {

function format_static_method_name(name) {
return name[0] === '$' ? name.slice(1) : name;
}
function check_type(type, value) {

@@ -22,0 +27,0 @@ var is_constructor = typeof type === 'function',

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

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

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

These features will support us on writing program with functional way.
These features will help our functional programming.

@@ -110,4 +110,4 @@ ## Feature

impl(SomeStruct,{
// without placing `self` argument at first, we can declare associated function (static method)
new(x,y){
// You can define associated function (static method) by starting method name with "$".
$new(x,y){
return SomeStruct({x,y});

@@ -120,3 +120,3 @@ },

let some_struct=SomeStruct.new(2,3);
let some_struct=SomeStruct.new(2,3); // You don't need to attach "$" at first. "$" was removed at attaching proccess
some_struct.print(); // > (2,3)

@@ -123,0 +123,0 @@

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

import {is_static_method,is_empty_function} from './util';
import {
is_empty_function,
format_static_method_name
} from './util';

@@ -21,4 +24,4 @@ let impl=function(/*trait?, target, block*/){

? (name,fn)=>{
is_static_method(fn)
? (target[name]=fn)
(name[0]==='$')
? (target[format_static_method_name(name)]=fn)
: (target.prototype[name]=function(){

@@ -25,0 +28,0 @@ return fn.apply({},[this].concat(Array.prototype.slice.call(arguments,0)));

@@ -9,2 +9,6 @@ export function is_static_method(fn){

export function format_static_method_name(name){
return name[0]==='$'?name.slice(1):name;
}
export function check_type(type,value){

@@ -11,0 +15,0 @@ let is_constructor=typeof type==='function',

@@ -62,3 +62,3 @@ let expect=require('chai').expect;

},
fuga(){
$fuga(){
return Foo.Foo;

@@ -81,3 +81,3 @@ }

},
from_array(arr){
$from_array(arr){
return Position({x:arr[0],y:arr[1]});

@@ -99,3 +99,3 @@ }

impl(Foo,{
new(x,y){
$new(x,y){
return Foo({x:x||0,y:y||0});

@@ -109,3 +109,3 @@ }

impl(Array,{
foo(el){
$foo(el){
return el.reverse();

@@ -121,3 +121,3 @@ },

let FooTrait=trait({
foo(){
$foo(){
return true;

@@ -128,3 +128,3 @@ },

},
new(){
$new(){
},

@@ -140,3 +140,3 @@ print(self){}

impl(FooTrait,Bar,{
new(){
$new(){
return Bar({x:0,y:0});

@@ -162,3 +162,3 @@ },

let FooTrait=trait({
foo(){}
$foo(){}
});

@@ -172,10 +172,10 @@ let Bar=struct({});

let FooTrait=trait({
foo(){}
$foo(){}
});
let Bar=struct({});
impl(FooTrait,Bar,{
foo(){
$foo(){
return true;
},
bar(){
$bar(){
return true;

@@ -182,0 +182,0 @@ }

@@ -97,3 +97,3 @@ import {expect} from 'chai';

impl(Unit,{
foo(){
$foo(){
return 3;

@@ -100,0 +100,0 @@ },

@@ -49,2 +49,10 @@ import {expect} from 'chai';

});
describe('#format_static_method_name',()=>{
it('should slice name when "$foo" was passed',()=>{
expect(util.format_static_method_name('$foo')).to.equal('foo');
});
it('should not slice name when "foo" was passed',()=>{
expect(util.format_static_method_name('foo')).to.equal('foo');
});
});
});
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