{"id":18523285,"url":"https://github.com/nrkn/objectionablejs","last_synced_at":"2026-01-25T15:02:51.907Z","repository":{"id":11500278,"uuid":"13977497","full_name":"nrkn/objectionablejs","owner":"nrkn","description":null,"archived":false,"fork":false,"pushed_at":"2013-10-30T23:49:22.000Z","size":116,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-05-14T18:54:16.125Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":null,"has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/nrkn.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2013-10-30T04:44:43.000Z","updated_at":"2013-10-30T23:49:25.000Z","dependencies_parsed_at":"2022-09-22T23:11:33.118Z","dependency_job_id":null,"html_url":"https://github.com/nrkn/objectionablejs","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/nrkn/objectionablejs","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nrkn%2Fobjectionablejs","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nrkn%2Fobjectionablejs/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nrkn%2Fobjectionablejs/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nrkn%2Fobjectionablejs/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nrkn","download_url":"https://codeload.github.com/nrkn/objectionablejs/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nrkn%2Fobjectionablejs/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28754807,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-25T13:59:49.818Z","status":"ssl_error","status_checked_at":"2026-01-25T13:59:33.728Z","response_time":113,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-06T17:34:57.516Z","updated_at":"2026-01-25T15:02:51.845Z","avatar_url":"https://github.com/nrkn.png","language":null,"readme":"```javascript\n/*\nobjectionable-js\n\nexample code \n*/\n\n//interfaces like static languages but duck testing + primitives, enums etc.\nvar interfaces = {\n  //properties are primitives\n  Point: {\n    x: 'Number',\n    y: 'Number'\n  },  \n  \n  //properties are interfaces\n  Line: {\n    start: 'Point',\n    end: 'Point'\n  },\n  \n  //you can mix properties as primitives/interfaces, example elided for tersity\n  \n  //enum\n  Color: [ \n    'red', \n    'green', \n    'blue' \n  ],\n  \n  //extending primative\n  HexColor: 'String',\n  \n  //alt syntax for point as used by jQuery et al.\n  Position: {\n    left: 'Number',\n    top: 'Number'\n  }\n};\n\nvar mixins = {\n  //mixin on primitive\n  Number: {\n    square: function( num ){\n      return num * num;\n    },\n    add: function( num, value ){\n      return num + value;\n    }\n  },\n  //mixin on interface\n  Point: {\n    square: function( point ){\n      return {\n        x: _( point.x ).square(),\n        y: _( point.y ).square()\n      };\n    }\n  },\n  //mixin with same name as existing mixins but on specific interface\n  Line: {\n    square: function( line ){\n      return {\n        start: _( line.start ).square(),\n        end: _( line.end ).square()\n      };\n    }\n  }\n};\n\nvar mappings = {\n  Point: {\n    Position: function( point ){\n      return {\n        left: point.x,\n        top: point.y\n      };\n    },\n    Line: function( point ){\n      return {\n        start: { x: 0, y: 0 },\n        end: point\n      };\n    }\n  },\n  Line: {\n    Point: function( line ){\n      return {\n        x: line.end.x - line.start.x,\n        y: line.end.y - line.start.y\n      };\n    }\n  },\n  Position: {\n    Point: function( position ){\n      return {\n        x: position.left,\n        y: position.top\n      };\n    }\n  },\n  Color: {\n    Hex: function( color ){\n      return {\n        red: '#f00',\n        green: '#0f0',\n        blue: '#00f'\n      }[ color ];\n    }\n  }\n};\n\n//standard args constructor - all args optional\nvar obj = new Objectionable( interfaces, mixins, mappings );\n\n//object constructor, all properties optional\nvar obj2 = new Objectionable({\n  interfaces: {\n    //...\n  },\n  mixins: {\n    //...\n  },\n  mappings: {\n    //...\n  }\n});\n\n//get underscore reference with mixins added\nvar _ = obj._;\n\n//alias autogenerated constructors\nvar Point = obj.Point;\nvar Line = obj.Line;\nvar Color = obj.Color;\n\n//standard constructor syntax\nvar point1 = new Point( 5, 1.5 );\n\n//square method is on Point\nconsole.log( point1.square() ); // { x: 25, y: 2.25 }\n\n//literal syntax\nvar point2 = { x: 5, y: 1.5 };\n\n//square method on literal via mixin\nconsole.log( _( point2 ).square() ); // { x: 25, y: 2.25 }\n\n//interface test on Point\npoint1.isPoint(); //true\n\n//interface test via mixin\n_( point2 ).isPoint()\n\n//there is a mapping from Point to Line\npoint1.mapsToLine(); //true\n\n//what interfaces?\nconsole.log( obj.has( point1 ) ); // [ 'Point', 'Line', 'Object' ]\n\n//standard constructor syntax\nvar line1 = new Line( 5, 1.5, 25, 2.25 );\n\nconsole.log( line1 ); // { start: { x: 5, y: 1.5 }, end: { x: 25, y: 2.25 } }\n\n//literal syntax\nvar line2 = { start: point1, end: _( point2 ).square() }; \n\nconsole.log( line2 ); // { start: { x: 5, y: 1.5 }, end: { x: 25, y: 2.25 } }\n\n//autogenerated converter method on Point\nvar line3 = point1.toLine();\n\nconsole.log( line3 ); // { start: { x: 0, y: 0 }, end: { x: 5, y: 1.5 } }\n\n//autogenerated converter method on Line\nvar point3 = _( line1 ).toPoint();\n\nconsole.log( point3 ); // { x: 20, y: 0.75 }\n\n//standard syntax, enum\nvar color1 = new Color( 'red' );\n\n//maps to string, but requires weak testing via == \nvar color1IsRed1 = color1 == 'red'; // true\nvar color1IsRed2 = color1 === 'red'; // false\n\n//enums also have a valueOf method for strict testing\nvar color1IsRed3 = color1.valueOf() === 'red'; // true\n\n//test interface for enum from literal via mixin\n_( 'red' ).isColor(); // true\n\n//toHexColor converter is on Color\nconsole.log( color1.toHexColor() ); // '#f00'\n\n//throws:\ntry {\n  var color2 = new Color( 42 );\n} catch( e ){}\n\n//mixin on third party object\nif( window \u0026\u0026 jQuery ){\n  //offset method return value matches interface Position which maps to Point:\n  var point4 = _( jQuery( 'html' ).offset() ).toPoint();\n  \n  //probably it's 0,0\n  console.log( _( point4 ).toPoint() ); // { x: 0, y: 0 } \n}\n```","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnrkn%2Fobjectionablejs","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnrkn%2Fobjectionablejs","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnrkn%2Fobjectionablejs/lists"}