Skip to content

Commit

Permalink
Add external modules to packages directory
Browse files Browse the repository at this point in the history
  • Loading branch information
watson committed Feb 28, 2020
1 parent ab45bdc commit dc6ea29
Show file tree
Hide file tree
Showing 16 changed files with 980 additions and 13 deletions.
10 changes: 10 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -530,6 +530,16 @@ module.exports = {
},
},

/**
* object-prototype package specific rules
*/
{
files: ['packages/object-prototype/**/*.js'],
rules: {
'mocha/handle-done-callback': 'off', // TODO: Find a way to disable all mocha rules
},
},

/**
* APM overrides
*/
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@
"ngreact": "0.5.1",
"node-fetch": "1.7.3",
"node-forge": "^0.9.1",
"object-prototype": "^3.0.1",
"object-prototype": "3.0.4",
"opn": "^5.5.0",
"oppsy": "^2.0.0",
"pegjs": "0.10.0",
Expand Down
1 change: 1 addition & 0 deletions packages/object-prototype-functions/.npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
test.js
48 changes: 48 additions & 0 deletions packages/object-prototype-functions/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# object-prototype-functions

An array containing the names of the functions on `Object.prototype`.

[![npm](https://img.shields.io/npm/v/object-prototype-functions.svg)](https://www.npmjs.com/package/object-prototype-functions)

## Installation

```
npm install object-prototype-functions --save
```

## Usage

```js
const ObjectPrototypeFunctions = require('object-prototype-functions')

console.log('The functions of Object.prototype are:')
console.log(ObjectPrototypeFunctions.join(', ')) // hasOwnProperty, isPrototypeOf...
```

## API

### `ObjectPrototypeFunctions`

An array containing the names of the functions on `Object.prototype`.

### `ObjectPrototypeFunctions.deprecated`

An array containing the names of the deprecated functions on
`Object.prototype`.

### `ObjectPrototypeFunctions.nonSpec`

An array containing the names of the non-spec'd functions on
`Object.prototype`.

### `ObjectPrototypeFunctions.nodejs`

An array containing the all names of the functions on `Object.prototype`
that are normally available in Node.js - both the spec'd and deprecated
functions.

### `ObjectPrototypeFunctions.all`

An array containing the all names of the functions on
`Object.prototype`, both the spec'd, deprecated, and non-spec'd
functions.
40 changes: 40 additions & 0 deletions packages/object-prototype-functions/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

module.exports = [
'hasOwnProperty',
'isPrototypeOf',
'propertyIsEnumerable',
'toLocaleString',
'toString',
'valueOf',
];

module.exports.deprecated = [
'__defineGetter__',
'__defineSetter__',
'__lookupGetter__',
'__lookupSetter__',
];

module.exports.nonSpec = ['eval', 'unwatch', 'watch'];

module.exports.nodejs = module.exports.concat(module.exports.deprecated);

module.exports.all = module.exports.concat(module.exports.deprecated, module.exports.nonSpec);
28 changes: 28 additions & 0 deletions packages/object-prototype-functions/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"name": "object-prototype-functions",
"version": "1.2.0",
"description": "An array containing the names of the functions on `Object.prototype`",
"main": "index.js",
"dependencies": {},
"devDependencies": {},
"scripts": {
"test": "node test.js"
},
"repository": {
"type": "git",
"url": "git+https://github.com/elastic/kibana.git"
},
"keywords": [
"object",
"prototype",
"function",
"functions",
"name"
],
"author": "Thomas Watson <w@tson.dk> (https://twitter.com/wa7son)",
"license": "Apache-2.0",
"bugs": {
"url": "https://github.com/elastic/kibana/issues"
},
"homepage": "https://github.com/elastic/kibana/blob/master/packages/object-prototype-functions/README.md"
}
52 changes: 52 additions & 0 deletions packages/object-prototype-functions/test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

const assert = require('assert');
const ObjectPrototypeFunctions = require('./');

assert(Array.isArray(ObjectPrototypeFunctions));
assert(ObjectPrototypeFunctions.length > 0);

ObjectPrototypeFunctions.forEach(name => {
assert.strictEqual(typeof Object.prototype[name], 'function');
});

assert(Array.isArray(ObjectPrototypeFunctions.deprecated));
assert(ObjectPrototypeFunctions.deprecated.length > 0);

ObjectPrototypeFunctions.deprecated.forEach(name => {
assert.strictEqual(typeof Object.prototype[name], 'function');
});

assert(Array.isArray(ObjectPrototypeFunctions.nonSpec));
assert(ObjectPrototypeFunctions.nonSpec.length > 0);

assert(Array.isArray(ObjectPrototypeFunctions.nodejs));
assert.strictEqual(
ObjectPrototypeFunctions.nodejs.length,
ObjectPrototypeFunctions.length + ObjectPrototypeFunctions.deprecated.length
);

assert(Array.isArray(ObjectPrototypeFunctions.all));
assert.strictEqual(
ObjectPrototypeFunctions.all.length,
ObjectPrototypeFunctions.length +
ObjectPrototypeFunctions.deprecated.length +
ObjectPrototypeFunctions.nonSpec.length
);
1 change: 1 addition & 0 deletions packages/object-prototype/.npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
test
82 changes: 82 additions & 0 deletions packages/object-prototype/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
# object-prototype

A replacement prototype for `Object.prototype` with all the same
functions.

[![npm](https://img.shields.io/npm/v/object-prototype.svg)](https://www.npmjs.com/package/object-prototype)

## Installation

```
npm install object-prototype --save
```

## Usage

```js
const { create, ObjectPrototype } = require('object-prototype');

const obj1 = create();
const obj2 = {};

console.log(Object.prototype.isPrototypeOf(obj1)); // false
console.log(ObjectPrototype.isPrototypeOf(obj1)); // true

console.log(Object.prototype.isPrototypeOf(obj2)); // true
console.log(ObjectPrototype.isPrototypeOf(obj2)); // false

Object.prototype.foo = 42;

console.log(obj1.foo); // undefined
console.log(obj2.foo); // 42
```

## API

### `ObjectPrototype`

The `ObjectPrototype` property exposed by this module is ment as a
replacement to `Object.prototype` and has the following ECMAScript
spec'd functions:

- [`ObjectPrototype.hasOwnProperty()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/hasOwnProperty)
- [`ObjectPrototype.isPrototypeOf()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/isPrototypeOf)
- [`ObjectPrototype.propertyIsEnumerable()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/propertyIsEnumerable)
- [`ObjectPrototype.toLocaleString()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/toLocaleString)
- [`ObjectPrototype.toString()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/toString)
- [`ObjectPrototype.valueOf()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/valueOf)

And the following functions which are considered deprecated according to
the ECMAScript specification:

- [`ObjectPrototype.__defineGetter__()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/__defineGetter__)
- [`ObjectPrototype.__defineSetter__()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/__defineSetter__)
- [`ObjectPrototype.__lookupGetter__()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/__lookupGetter__)
- [`ObjectPrototype.__lookupSetter__()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/__lookupSetter__)

### `object = create()`

The `create` function is a convenience function that returns a new
object with `ObjectPrototype` as its prototype.

This is equivalent to writing `Object.create(ObjectPrototype)`.

### `object = assign([...objects])`

The `assign` function is a convenience function that returns a new
object with all the same properties as the provided objects, but with
`ObjectPrototype` as its prototype.

This is equivalent to writing
`Object.assign(Object.create(ObjectPrototype), ...objects)`.

### `FunctionPrototype`

The `FunctionPrototype` property exposed by this module is ment as a
replacement to `Function.prototype` and exposes the same properties.

### `function = safePrototypeFunction(function)`

Given a function as the first argument, `safePrototypeFunction` will
return another function which wraps the given function in a way so that
it doesn't leak `Object.prototype`.
Loading

0 comments on commit dc6ea29

Please sign in to comment.