Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

create

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

create - npm Package Compare versions

Comparing version 0.0.1 to 0.0.2

array.js

90

index.js

@@ -26,67 +26,46 @@ /**

//console.error('Setting Up: %s', ctor.name)
if (ctor.create) {
//console.error('create() already exists; bail')
return ctor
}
switch (ctor.name) {
case 'Function':
setupFunction(ctor)
break;
case 'RegExp':
setupRegexp(ctor)
break;
default:
throw new Error('Constructor is unknown or unimplemented: ' + ctor.name)
var m;
try {
m = require('./' + ctor.name.toLowerCase())
} catch (e) {
throw new Error('Constructor is unknown or unimplemented: ' + ctor.name + '\n' + e)
}
return ctor
}
exports.setup = setup
if (!ctor.create) {
/**
* Extends the Function constructor
*/
function setupFunction (ctor) {
function create () {
var argv = arguments.length
if (argv < 2) {
throw new Error('Function.create() requires at least 2 arguments.')
}
var objectDescriptor = arguments[argv - 1]
, instance = null
, proto = null
if (exports.isObjectDescriptor(objectDescriptor)) {
proto = arguments[argv - 2]
} else {
proto = objectDescriptor
objectDescriptor = null
}
var func = arguments[0]
if (typeof func === 'function') {
instance = function () {
return func.apply(instance, arguments)
function create () {
var argc = arguments.length
if (argc < 1) {
throw new TypeError(ctor.name + ' prototype may only be an Object or null')
}
} else {
throw new Error('TODO: invoke the constructor')
var objectDescriptor = arguments[--argc]
, instance = null
, proto = null
if (exports.isObjectDescriptor(objectDescriptor)) {
proto = arguments[--argc]
} else {
proto = objectDescriptor
objectDescriptor = null
}
var instance = m.newInstance(ctor, argc, arguments)
// Set the instance's `prototype`
instance.__proto__ = proto
if (objectDescriptor) {
// If an object descriptor was passed in, define those
Object.defineProperties(instance, objectDescriptor)
}
return instance
}
instance.__proto__ = proto
if (objectDescriptor) {
Object.defineProperties(instance, objectDescriptor)
}
return instance
ctor.create = create
}
ctor.create = create
function isFunction (v) {
return v instanceof ctor
|| typeof v === 'function'
|| Object.prototype.toString.call(v) == '[object Function]'
var is = 'is' + ctor.name
if (!ctor[is]) {
//console.error('Setting up %s.%s()', ctor.name, is)
ctor[is] = m.getIsFunc(ctor)
}
ctor.isFunction = isFunction
return ctor
}
exports.setup = setup

@@ -161,2 +140,3 @@

if (typeof o !== 'object')
//if (typeof o !== 'object' || o === null)
return false

@@ -163,0 +143,0 @@ return 'value' in o

{ "name": "create"
, "description": "The missing Native.create() functions that ECMA forgot."
, "keywords": [ "create", "ecma", "function", "subclass", "prototype", "array", "number" ]
, "version": "0.0.1"
, "version": "0.0.2"
, "author": "Nathan Rajlich <nathan@tootallnate.net> (http://tootallnate.net)"

@@ -9,5 +9,5 @@ , "repository": { "type": "git", "url": "git://github.com/TooTallNate/create.git" }

, "scripts": {
"test": "for i in test/*.js; do node \"$i\"; done;"
"test": "./test/run.sh"
}
, "engines": { "node": ">= 0.4.0 && < 0.7.0" }
}

@@ -5,3 +5,3 @@ create

`create` is a module or node.js (and someday the browser too) that implements the
`create` is a module for node.js (and someday the browser too) that implements the
*"missing"* `.create()` functions on the rest of the native data types in

@@ -70,2 +70,2 @@ JavaScript.

From a browser standpoint, this module will only work in browsers where that is
true (`__proto__` *MAY* be changed). In node this will work.
true (`__proto__` *MAY* be changed). In node this will _always_ work.

@@ -28,1 +28,4 @@ var create = require('../')

assert.ok(!create.isObjectDescriptor(false3))
var false4 = false
assert.ok(!create.isObjectDescriptor(false4))

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