extension 0.2.0 → 1.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +18 -17
- package/README.md +80 -135
- package/dist/cli.d.ts +1 -0
- package/dist/cli.js +16 -0
- package/dist/module.d.ts +1 -0
- package/dist/module.js +28 -0
- package/package.json +40 -15
- package/.npmignore +0 -2
- package/lib/array.js +0 -77
- package/lib/extension.js +0 -122
- package/lib/object.js +0 -60
- package/lib/string.js +0 -102
- package/test/array.js +0 -118
- package/test/extension.js +0 -239
- package/test/object.js +0 -160
- package/test/string.js +0 -228
package/LICENSE
CHANGED
|
@@ -1,20 +1,21 @@
|
|
|
1
|
-
|
|
1
|
+
MIT License
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
a copy of this software and associated documentation files (the
|
|
5
|
-
"Software"), to deal in the Software without restriction, including
|
|
6
|
-
without limitation the rights to use, copy, modify, merge, publish,
|
|
7
|
-
distribute, sublicense, and/or sell copies of the Software, and to
|
|
8
|
-
permit persons to whom the Software is furnished to do so, subject to
|
|
9
|
-
the following conditions:
|
|
3
|
+
Copyright (c) 2024 Cezar Augusto <boss@cezaraugusto.net> (https://cezaraugusto.com)
|
|
10
4
|
|
|
11
|
-
|
|
12
|
-
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
13
11
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,166 +1,111 @@
|
|
|
1
|
-
|
|
1
|
+
[action-image]: https://github.com/cezaraugusto/extension-create/actions/workflows/ci.yml/badge.svg?branch=main
|
|
2
|
+
[action-url]: https://github.com/cezaraugusto/extension-create/actions
|
|
3
|
+
[npm-image]: https://img.shields.io/npm/v/extension-create.svg
|
|
4
|
+
[npm-url]: https://npmjs.org/package/extension-create
|
|
5
|
+
[downloads-image]: https://img.shields.io/npm/dm/extension-create.svg
|
|
6
|
+
[downloads-url]: https://npmjs.org/package/extension-create
|
|
7
|
+
[node]: https://img.shields.io/node/v/extension-create.svg
|
|
8
|
+
[node-url]: https://nodejs.org
|
|
9
|
+
[prs]: https://img.shields.io/badge/PRs-welcome-brightgreen.svg
|
|
10
|
+
[prs-url]: https://github.com/cezaraugusto/extension-create/blob/main/CONTRIBUTING.md
|
|
11
|
+
[vunlerabilities]: https://snyk.io/test/github/cezaraugusto/extension-create/badge.svg
|
|
12
|
+
[fossa-image]: https://app.fossa.com/api/projects/git%2Bgithub.com%2Fcezaraugusto%2Fextension-create.svg?type=shield
|
|
13
|
+
[fossa-url]: https://app.fossa.com/projects/git%2Bgithub.com%2Fcezaraugusto%2Fextension-create?ref=badge_large
|
|
14
|
+
|
|
15
|
+
# extension-create [![npm][npm-image]][npm-url] [![fossa][fossa-image]][fossa-url] [![workflow][action-image]][action-url] [![downloads][downloads-image]][downloads-url] [![PR's welcome][prs]][prs-url]
|
|
16
|
+
|
|
17
|
+
<img alt="Logo" align="right" src="https://user-images.githubusercontent.com/4672033/102850460-4d22aa80-43f8-11eb-82db-9efce586f73e.png" width="25%" />
|
|
18
|
+
|
|
19
|
+
Create cross-browser extensions with no build configuration.
|
|
20
|
+
|
|
21
|
+
- [Creating an extension](#creating-an-extension) — How to create a new extension.
|
|
22
|
+
- [Getting started immediately](#getting-started-immediately) — Get work done in no time.
|
|
23
|
+
- [I have an extension](#i-have-an-extension) - Use only specific parts of `extension-create`.
|
|
24
|
+
|
|
25
|
+
`extension-create` helps you develop cross-browser extensions with built-in support for module imports/exports, auto-reload, and more.
|
|
26
|
+
|
|
27
|
+
## Creating an Extension
|
|
28
|
+
|
|
29
|
+
```sh
|
|
30
|
+
npx extension-create@latest create my-extension-hello
|
|
31
|
+
cd my-extension-hello
|
|
32
|
+
npm run dev
|
|
33
|
+
```
|
|
2
34
|
|
|
3
|
-
|
|
35
|
+
A new browser instance will open up with your extension ready for development.
|
|
4
36
|
|
|
5
|
-
|
|
37
|
+
You are done. Time to hack on your extension!
|
|
6
38
|
|
|
7
|
-
|
|
39
|
+
<p align="center">
|
|
40
|
+
<img src="https://user-images.githubusercontent.com/4672033/106184765-ba0c2b80-6180-11eb-9d0f-d9d00d168290.gif" width="720" alt="npm start">
|
|
41
|
+
</p>
|
|
8
42
|
|
|
9
|
-
##
|
|
43
|
+
## Getting Started Immediately
|
|
10
44
|
|
|
11
|
-
|
|
45
|
+
### Kickstart any sample from Chrome Extension Samples
|
|
12
46
|
|
|
13
|
-
|
|
14
|
-
var ext = require('extension');
|
|
47
|
+
The [chrome-extensions-sample](https://github.com/GoogleChrome/chrome-extensions-samples/) project is a great way to kickstart developing your extension.
|
|
15
48
|
|
|
16
|
-
|
|
17
|
-
ext.register(String.prototype, ext.string);
|
|
49
|
+
If we go to the samples repository and look for an extension sample to work, let's say the [page-redder](https://github.com/GoogleChrome/chrome-extensions-samples/tree/main/functional-samples/sample.page-redder) sample, all we need is to copy and paste it's URL as an argument for the start command:
|
|
18
50
|
|
|
19
|
-
|
|
20
|
-
ext.register(String.prototype, {
|
|
21
|
-
echo: function() {
|
|
22
|
-
console.log(this);
|
|
23
|
-
},
|
|
51
|
+
#### Command
|
|
24
52
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
53
|
+
```sh
|
|
54
|
+
# This command will:
|
|
55
|
+
# 1. Download the Chrome extension sample URL to the current working directory
|
|
56
|
+
# 2. Bundle the downloaded extension using extension-create
|
|
57
|
+
# 3. Enable the extension in Chrome using a fresh user profile
|
|
58
|
+
npx extension-create dev https://github.com/GoogleChrome/chrome-extensions-samples/tree/main/functional-samples/sample.page-redder
|
|
29
59
|
```
|
|
30
60
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
// enable extensions registered against
|
|
35
|
-
// String.prototype for duration of program
|
|
36
|
-
ext.use(String.prototype)
|
|
37
|
-
var str = 'hello world';
|
|
38
|
-
str.echo(); // prints hello world to the console
|
|
39
|
-
```
|
|
61
|
+
<p align="center">
|
|
62
|
+
<img src="https://user-images.githubusercontent.com/4672033/106188671-04dc7200-6186-11eb-940a-52aebab46f31.gif" width="720" alt="npm start">
|
|
63
|
+
</p>
|
|
40
64
|
|
|
41
|
-
|
|
65
|
+
Will not only download the extension but also kickstart a Chrome instance in a fresh profile with your sample extension loaded and default auto-reload support. Try it yourself!
|
|
42
66
|
|
|
43
|
-
|
|
44
|
-
// enable extensions registered against
|
|
45
|
-
// String.prototype within function scope
|
|
46
|
-
var str = 'hello world';
|
|
67
|
+
### Use `Microsoft Edge` to kickstart any sample from [chrome-extesions-sample](https://github.com/GoogleChrome/chrome-extensions-samples/)
|
|
47
68
|
|
|
48
|
-
|
|
49
|
-
str.echo(); // prints 'hello world' to the console
|
|
50
|
-
});
|
|
69
|
+
**You read it!** Just run the command above with the `--browser=edge` flag:
|
|
51
70
|
|
|
52
|
-
|
|
71
|
+
```sh
|
|
72
|
+
npx extension-create dev --browser=edge https://github.com/GoogleChrome/chrome-extensions-samples/tree/main/functional-samples/sample.page-redder
|
|
53
73
|
```
|
|
54
74
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
```javascript
|
|
58
|
-
var str = 'hello world';
|
|
59
|
-
|
|
60
|
-
ext.use(String.prototype, ['echo']); // use only the echo extension method
|
|
61
|
-
str.echo(); // prints 'hello world' to the console
|
|
62
|
-
str.cap(); // TypeError: Object has no method 'cap'
|
|
63
|
-
|
|
64
|
-
ext.use(String.prototype, ['cap'], function() { // use cap extension within function scope
|
|
65
|
-
str.echo(); // prints 'hello world' to the console
|
|
66
|
-
str.cap(); // prints 'HELLO WORLD' to the console
|
|
67
|
-
});
|
|
68
|
-
|
|
69
|
-
str.cap(); // TypeError: Object has no method 'cap'
|
|
70
|
-
```
|
|
75
|
+
And see a Chrome Extension sample running automatically. On Edge!
|
|
71
76
|
|
|
72
|
-
|
|
77
|
+
## I have an extension
|
|
73
78
|
|
|
74
|
-
|
|
75
|
-
var myObj = {};
|
|
79
|
+
Just add `extension-create` to your npm scripts. Here's how it should look in your `package.json`:
|
|
76
80
|
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
81
|
+
```js
|
|
82
|
+
{
|
|
83
|
+
// ...npm stuff,
|
|
84
|
+
"scripts": {
|
|
85
|
+
"start": "npx extension-create start",
|
|
86
|
+
"dev": "npx extension-create dev",
|
|
87
|
+
"build": "npx extension-create build"
|
|
88
|
+
},
|
|
89
|
+
"devDependencies": {
|
|
90
|
+
"extension-create": "latest"
|
|
80
91
|
}
|
|
81
|
-
}
|
|
82
|
-
ext.use(myObj);
|
|
83
|
-
|
|
84
|
-
myObj.say('hello'); // prints 'hello' to the console
|
|
85
|
-
var newObj = {};
|
|
86
|
-
newObj.say('hello'); // TypeError: Object has no method 'say'
|
|
92
|
+
}
|
|
87
93
|
```
|
|
88
94
|
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
```javascript
|
|
92
|
-
var strext = require('extension').string;
|
|
93
|
-
var objext = require('extension').object;
|
|
94
|
-
|
|
95
|
-
strext.contains('hello world', 'hello'); // true
|
|
96
|
-
objext.isString('hello world'); // true
|
|
97
|
-
```
|
|
98
|
-
|
|
99
|
-
## Extension API
|
|
100
|
-
|
|
101
|
-
### register(object, extensionObject)
|
|
102
|
-
|
|
103
|
-
Register properties of extensionObject as extensions to the object argument
|
|
95
|
+
#### Using a specific browser for development
|
|
104
96
|
|
|
105
|
-
|
|
97
|
+
| <img width=120 src="https://raw.githubusercontent.com/alrra/browser-logos/main/src/chrome/chrome.svg" alt="Chrome browser logo"> | <img width=120 src="https://raw.githubusercontent.com/alrra/browser-logos/main/src/edge/edge.svg" alt="Microsoft Edge browser logo"> | <img width=120 src="https://raw.githubusercontent.com/alrra/browser-logos/main/src/firefox/firefox.svg" alt="Mozilla Firefox browser logo"> | <img width=120 src="https://raw.githubusercontent.com/alrra/browser-logos/main/src/safari/safari.svg" alt="Apple Safari browser logo"> | <img width=120 src="https://raw.githubusercontent.com/alrra/browser-logos/main/src/opera/opera.svg" alt="Opera browser logo"> | <img width=120 src="https://raw.githubusercontent.com/alrra/browser-logos/main/src/chromium/chromium.svg" alt="Chromium browser logo"> |
|
|
98
|
+
| -------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------- |
|
|
99
|
+
| Google Chrome ✅ | Microsoft Edge ✅ | Mozilla Firefox ⛔️ | Apple Safari ⛔️ | Opera browser ⛔️ | Chromium (forks) 🤔 |
|
|
106
100
|
|
|
107
|
-
|
|
108
|
-
* extensionObject - Object containing extension properties/method
|
|
101
|
+
If you want to target a specific browser, just pass the `--browser` flag to the dev/start command (Chrome or Edge, soon others), like `npx extension-create dev --browser=edge`.
|
|
109
102
|
|
|
110
|
-
|
|
103
|
+
That's it!
|
|
111
104
|
|
|
112
|
-
|
|
105
|
+
## Program Options Table
|
|
113
106
|
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
* object - the object whose registered extensions you wish to use
|
|
117
|
-
* properties - an optional array of property/method names representing a subset of the registered extensions you'd like to use
|
|
118
|
-
* scopeFunction - an optional function within which the specified registered extensions will be applied. They are removed after the method returns or throws an exception.
|
|
119
|
-
|
|
120
|
-
### registerAndUse(object, extensionObject)
|
|
121
|
-
|
|
122
|
-
Register properties of extensionObject as extensions to the object argument and set them up for use. It's the equivalent of calling `#register` followed immediately by `#use` without the scoping function argument.
|
|
123
|
-
|
|
124
|
-
__Arguments__
|
|
125
|
-
|
|
126
|
-
* object - the object against which to register extensions
|
|
127
|
-
* extensionObject - Object containing extension properties/method
|
|
128
|
-
|
|
129
|
-
### find(object)
|
|
130
|
-
|
|
131
|
-
Find all the extension properties/methods registered against the given object. The return value is an object containing all the extension properties/methods.
|
|
132
|
-
|
|
133
|
-
__Arguments__
|
|
134
|
-
|
|
135
|
-
* object - the object against which you wish to find registered extensions
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
## Built-in Extensions
|
|
139
|
-
|
|
140
|
-
Coming soon! Please see files in the lib/ directory in the meantime.
|
|
107
|
+
For a list of all commands available, see [OPTIONS_TABLE.md](OPTIONS_TABLE.md).
|
|
141
108
|
|
|
142
109
|
## License
|
|
143
110
|
|
|
144
|
-
(
|
|
145
|
-
|
|
146
|
-
Copyright (c) 2012 Near Infinity Corporation
|
|
147
|
-
|
|
148
|
-
Permission is hereby granted, free of charge, to any person obtaining
|
|
149
|
-
a copy of this software and associated documentation files (the
|
|
150
|
-
"Software"), to deal in the Software without restriction, including
|
|
151
|
-
without limitation the rights to use, copy, modify, merge, publish,
|
|
152
|
-
distribute, sublicense, and/or sell copies of the Software, and to
|
|
153
|
-
permit persons to whom the Software is furnished to do so, subject to
|
|
154
|
-
the following conditions:
|
|
155
|
-
|
|
156
|
-
The above copyright notice and this permission notice shall be
|
|
157
|
-
included in all copies or substantial portions of the Software.
|
|
158
|
-
|
|
159
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
160
|
-
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
161
|
-
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
162
|
-
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
163
|
-
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
164
|
-
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
165
|
-
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
166
|
-
|
|
111
|
+
MIT (c) Cezar Augusto.
|
package/dist/cli.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
package/dist/cli.js
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
"use strict";
|
|
3
|
+
|
|
4
|
+
// cli.ts
|
|
5
|
+
var import_child_process = require("child_process");
|
|
6
|
+
function runCli() {
|
|
7
|
+
(0, import_child_process.exec)("@extension-create/cli", (error, stdout, stderr) => {
|
|
8
|
+
if (error) {
|
|
9
|
+
console.error(`exec error: ${error}`);
|
|
10
|
+
return;
|
|
11
|
+
}
|
|
12
|
+
console.log(`stdout: ${stdout}`);
|
|
13
|
+
console.error(`stderr: ${stderr}`);
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
runCli();
|
package/dist/module.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
package/dist/module.js
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
"use strict";
|
|
3
|
+
var __create = Object.create;
|
|
4
|
+
var __defProp = Object.defineProperty;
|
|
5
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
6
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
8
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
18
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
19
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
20
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
21
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
22
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
23
|
+
mod
|
|
24
|
+
));
|
|
25
|
+
|
|
26
|
+
// module.ts
|
|
27
|
+
var import_cli = __toESM(require("@extension-create/cli"));
|
|
28
|
+
(0, import_cli.default)();
|
package/package.json
CHANGED
|
@@ -1,22 +1,47 @@
|
|
|
1
1
|
{
|
|
2
|
-
"name": "extension",
|
|
3
|
-
"description": "Framework for selectively extending JavaScript objects.",
|
|
4
|
-
"version": "0.2.0",
|
|
5
|
-
"author": "Jeff Kunkle <jeff.kunkle@nearinfinity.com>",
|
|
6
|
-
"keywords": ["prototype", "extension"],
|
|
7
|
-
"repository": { "type": "git", "url": "https://github.com/nearinfinity/node-extension.git" },
|
|
8
|
-
"engines": { "node" : ">=0.6.0" },
|
|
9
|
-
"bugs": { "url": "https://github.com/nearinfinity/node-extension/issues" },
|
|
10
2
|
"license": "MIT",
|
|
11
|
-
"
|
|
12
|
-
|
|
3
|
+
"repository": {
|
|
4
|
+
"type": "git",
|
|
5
|
+
"url": "https://github.com/cezaraugusto/extension-create.git"
|
|
6
|
+
},
|
|
7
|
+
"engines": {
|
|
8
|
+
"node": ">=18"
|
|
9
|
+
},
|
|
10
|
+
"name": "extension",
|
|
11
|
+
"version": "1.1.1",
|
|
12
|
+
"description": "Create cross-browser extensions with no build configuration.",
|
|
13
|
+
"main": "./dist/cli.js",
|
|
14
|
+
"types": "./dist/cli.d.ts",
|
|
15
|
+
"files": [
|
|
16
|
+
"dist"
|
|
13
17
|
],
|
|
14
|
-
"
|
|
15
|
-
"
|
|
16
|
-
|
|
18
|
+
"bin": {
|
|
19
|
+
"extension": "./dist/cli.js"
|
|
20
|
+
},
|
|
21
|
+
"author": {
|
|
22
|
+
"name": "Cezar Augusto",
|
|
23
|
+
"email": "boss@cezaraugusto.net",
|
|
24
|
+
"url": "https://cezaraugusto.com"
|
|
17
25
|
},
|
|
18
26
|
"scripts": {
|
|
19
|
-
"
|
|
27
|
+
"compile:readme-files": "node ./scripts/copyMarkdownFilesToCli.js",
|
|
28
|
+
"compile:cli": "tsup-node ./cli.ts --format cjs --dts --target=node18",
|
|
29
|
+
"compile": "yarn compile:readme-files && yarn compile:cli"
|
|
20
30
|
},
|
|
21
|
-
"
|
|
31
|
+
"keywords": [
|
|
32
|
+
"zero-config",
|
|
33
|
+
"build",
|
|
34
|
+
"develop",
|
|
35
|
+
"browser",
|
|
36
|
+
"extension",
|
|
37
|
+
"chrome extension",
|
|
38
|
+
"edge extension",
|
|
39
|
+
"firefox extension",
|
|
40
|
+
"web",
|
|
41
|
+
"react",
|
|
42
|
+
"typescript"
|
|
43
|
+
],
|
|
44
|
+
"dependencies": {
|
|
45
|
+
"@extension-create/cli": "*"
|
|
46
|
+
}
|
|
22
47
|
}
|
package/.npmignore
DELETED
package/lib/array.js
DELETED
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
module.exports = {
|
|
4
|
-
contains: function (source, obj) {
|
|
5
|
-
if (arguments.length < 2) {
|
|
6
|
-
obj = source;
|
|
7
|
-
source = this;
|
|
8
|
-
}
|
|
9
|
-
if (!Array.isArray(source)) {
|
|
10
|
-
return false;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
for (var i = 0, l = source.length; i < l; i++) {
|
|
14
|
-
if (source[i] === obj) {
|
|
15
|
-
return true;
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
return false;
|
|
19
|
-
},
|
|
20
|
-
|
|
21
|
-
isEmpty: function (obj) {
|
|
22
|
-
obj = arguments.length > 0 ? obj : this;
|
|
23
|
-
return obj.length < 1;
|
|
24
|
-
},
|
|
25
|
-
|
|
26
|
-
sortCaseInsensitive: function (obj) {
|
|
27
|
-
obj = arguments.length > 0 ? obj : this;
|
|
28
|
-
return obj.sort(function (a, b) {
|
|
29
|
-
a = String(a).toUpperCase();
|
|
30
|
-
b = String(b).toUpperCase();
|
|
31
|
-
if (a > b) {
|
|
32
|
-
return 1;
|
|
33
|
-
}
|
|
34
|
-
if (a < b) {
|
|
35
|
-
return -1;
|
|
36
|
-
}
|
|
37
|
-
return 0;
|
|
38
|
-
});
|
|
39
|
-
},
|
|
40
|
-
|
|
41
|
-
first: function (source, fn) {
|
|
42
|
-
if (arguments.length < 2) {
|
|
43
|
-
fn = source;
|
|
44
|
-
source = this;
|
|
45
|
-
}
|
|
46
|
-
for (var i = 0, l = source.length; i < l; i++) {
|
|
47
|
-
if (fn(source[i])) {
|
|
48
|
-
return source[i];
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
},
|
|
52
|
-
|
|
53
|
-
// fn
|
|
54
|
-
// source, fn
|
|
55
|
-
groupBy: function () {
|
|
56
|
-
var source, fn;
|
|
57
|
-
if (arguments.length === 1) {
|
|
58
|
-
source = this;
|
|
59
|
-
fn = arguments[0];
|
|
60
|
-
} else {
|
|
61
|
-
source = arguments[0];
|
|
62
|
-
fn = arguments[1];
|
|
63
|
-
}
|
|
64
|
-
var results = {};
|
|
65
|
-
|
|
66
|
-
var length = source.length;
|
|
67
|
-
for (var i = 0; i < length; i++) {
|
|
68
|
-
var key = fn(source[i]);
|
|
69
|
-
if (key in results) {
|
|
70
|
-
results[key].push(source[i]);
|
|
71
|
-
} else {
|
|
72
|
-
results[key] = [source[i]];
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
return results;
|
|
76
|
-
}
|
|
77
|
-
};
|
package/lib/extension.js
DELETED
|
@@ -1,122 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
var objext = require('./object');
|
|
4
|
-
var extensionKeys = [];
|
|
5
|
-
var extensionObjs = [];
|
|
6
|
-
|
|
7
|
-
var register = exports.register = function (obj, extObj) {
|
|
8
|
-
verifyPresent('Object to be extended cannot be null or undefined', obj);
|
|
9
|
-
verifyPresent('Extensions cannot be null or undefined', extObj);
|
|
10
|
-
|
|
11
|
-
if (objext.isEmpty(extObj)) {
|
|
12
|
-
return;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
var index = extensionKeys.indexOf(obj);
|
|
16
|
-
if (index > -1) {
|
|
17
|
-
Object.keys(extObj).forEach(function(ext) {
|
|
18
|
-
extensionObjs[index][ext] = extObj[ext];
|
|
19
|
-
});
|
|
20
|
-
} else {
|
|
21
|
-
extensionKeys.push(obj);
|
|
22
|
-
extensionObjs.push(extObj);
|
|
23
|
-
}
|
|
24
|
-
};
|
|
25
|
-
|
|
26
|
-
var registerAndUse = exports.registerAndUse = function (obj, extObj) {
|
|
27
|
-
register(obj, extObj);
|
|
28
|
-
use(obj);
|
|
29
|
-
};
|
|
30
|
-
|
|
31
|
-
var find = exports.find = function (obj) {
|
|
32
|
-
verifyPresent('object argument is required', obj);
|
|
33
|
-
|
|
34
|
-
var index = extensionKeys.indexOf(obj);
|
|
35
|
-
if (index > -1) {
|
|
36
|
-
return extensionObjs[index];
|
|
37
|
-
} else {
|
|
38
|
-
return undefined;
|
|
39
|
-
}
|
|
40
|
-
};
|
|
41
|
-
|
|
42
|
-
var use = exports.use = function (obj, props, fn) {
|
|
43
|
-
verifyPresent('Object on which to use extensions cannot be null or undefined', obj);
|
|
44
|
-
|
|
45
|
-
if (typeof props === 'function') {
|
|
46
|
-
fn = props;
|
|
47
|
-
props = undefined;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
var props = getProps(obj, props);
|
|
51
|
-
|
|
52
|
-
if (fn === undefined) {
|
|
53
|
-
addProps(obj, props);
|
|
54
|
-
} else {
|
|
55
|
-
try {
|
|
56
|
-
addProps(obj, props);
|
|
57
|
-
fn();
|
|
58
|
-
} finally {
|
|
59
|
-
removeProps(obj, props);
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
};
|
|
63
|
-
|
|
64
|
-
function addProps(obj, props) {
|
|
65
|
-
var index = extensionKeys.indexOf(obj);
|
|
66
|
-
if (index < 0) {
|
|
67
|
-
return;
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
props.forEach(function(prop) {
|
|
71
|
-
var ext = extensionObjs[index][prop];
|
|
72
|
-
if (ext) {
|
|
73
|
-
Object.defineProperty(obj, prop, {
|
|
74
|
-
value: ext,
|
|
75
|
-
configurable: true
|
|
76
|
-
});
|
|
77
|
-
}
|
|
78
|
-
});
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
function removeProps(obj, props) {
|
|
82
|
-
props.forEach(function(prop) {
|
|
83
|
-
if (obj[prop]) {
|
|
84
|
-
delete obj[prop];
|
|
85
|
-
}
|
|
86
|
-
});
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
function getProps(obj, props) {
|
|
90
|
-
if (props === null || props === undefined) {
|
|
91
|
-
var index = extensionKeys.indexOf(obj);
|
|
92
|
-
return index > -1 ? Object.keys(extensionObjs[index]) : [];
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
if (!Array.isArray(props)) {
|
|
96
|
-
props = [props];
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
props.forEach(verifyProp.bind(this, obj));
|
|
100
|
-
props = props.filter(function(prop) {
|
|
101
|
-
return obj[prop] === undefined;
|
|
102
|
-
});
|
|
103
|
-
|
|
104
|
-
return props;
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
function verifyProp(obj, prop) {
|
|
108
|
-
var index = extensionKeys.indexOf(obj);
|
|
109
|
-
if (index < 0 || extensionObjs[index][prop] === undefined) {
|
|
110
|
-
throw new Error(obj + '#' + prop + ' extension not found.');
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
function verifyPresent(message, obj) {
|
|
115
|
-
if (obj === null || obj === undefined) {
|
|
116
|
-
throw new Error(message);
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
exports.string = require('./string');
|
|
121
|
-
exports.object = require('./object');
|
|
122
|
-
exports.array = require('./array');
|
package/lib/object.js
DELETED
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
module.exports = {
|
|
4
|
-
isString: function (obj) {
|
|
5
|
-
obj = arguments.length > 0 ? obj : this;
|
|
6
|
-
return typeof obj === 'string';
|
|
7
|
-
},
|
|
8
|
-
|
|
9
|
-
isFunction: function (obj) {
|
|
10
|
-
obj = arguments.length > 0 ? obj : this;
|
|
11
|
-
return typeof obj === 'function';
|
|
12
|
-
},
|
|
13
|
-
|
|
14
|
-
isArray: function (obj) {
|
|
15
|
-
obj = arguments.length > 0 ? obj : this;
|
|
16
|
-
return Array.isArray(obj);
|
|
17
|
-
},
|
|
18
|
-
|
|
19
|
-
isNumber: function (obj) {
|
|
20
|
-
obj = arguments.length > 0 ? obj : this;
|
|
21
|
-
return typeof obj === 'number';
|
|
22
|
-
},
|
|
23
|
-
|
|
24
|
-
isObject: function (obj) {
|
|
25
|
-
obj = arguments.length > 0 ? obj : this;
|
|
26
|
-
return obj !== null &&
|
|
27
|
-
!Array.isArray(obj) &&
|
|
28
|
-
typeof obj === 'object';
|
|
29
|
-
},
|
|
30
|
-
|
|
31
|
-
isEmpty: function (obj) {
|
|
32
|
-
obj = arguments.length > 0 ? obj : this;
|
|
33
|
-
if (obj === null || obj === undefined) {
|
|
34
|
-
return true;
|
|
35
|
-
}
|
|
36
|
-
if (module.exports.isObject(obj)) {
|
|
37
|
-
return Object.keys(obj).length < 1;
|
|
38
|
-
} else if (Array.isArray(obj)) {
|
|
39
|
-
return obj.length < 1;
|
|
40
|
-
} else {
|
|
41
|
-
return false;
|
|
42
|
-
}
|
|
43
|
-
},
|
|
44
|
-
|
|
45
|
-
toArray: function (obj) {
|
|
46
|
-
obj = arguments.length > 0 ? obj : this;
|
|
47
|
-
var results = [];
|
|
48
|
-
for (var k in obj) {
|
|
49
|
-
if (!obj.hasOwnProperty(k)) {
|
|
50
|
-
continue;
|
|
51
|
-
}
|
|
52
|
-
results.push({
|
|
53
|
-
key: k,
|
|
54
|
-
value: obj[k]
|
|
55
|
-
})
|
|
56
|
-
}
|
|
57
|
-
return results;
|
|
58
|
-
}
|
|
59
|
-
};
|
|
60
|
-
|