pax_global_header 0000666 0000000 0000000 00000000064 14570351320 0014512 g ustar 00root root 0000000 0000000 52 comment=b11fe68c318dbb51b817a22a562175b29adf2e1f
medikoo-d-b11fe68/ 0000775 0000000 0000000 00000000000 14570351320 0014000 5 ustar 00root root 0000000 0000000 medikoo-d-b11fe68/.editorconfig 0000775 0000000 0000000 00000000456 14570351320 0016465 0 ustar 00root root 0000000 0000000 # EditorConfig is awesome: http://EditorConfig.org
# top-most EditorConfig file
root = true
[*]
charset = utf-8
end_of_line = lf
insert_final_newline = true
indent_style = tab
trim_trailing_whitespace = true
[*.{md,yml}]
indent_size = 2
indent_style = space
[*.md]
trim_trailing_whitespace = false
medikoo-d-b11fe68/.github/ 0000775 0000000 0000000 00000000000 14570351320 0015340 5 ustar 00root root 0000000 0000000 medikoo-d-b11fe68/.github/FUNDING.yml 0000664 0000000 0000000 00000000042 14570351320 0017151 0 ustar 00root root 0000000 0000000 github: medikoo
tidelift: "npm/d"
medikoo-d-b11fe68/.github/workflows/ 0000775 0000000 0000000 00000000000 14570351320 0017375 5 ustar 00root root 0000000 0000000 medikoo-d-b11fe68/.github/workflows/integrate.yml 0000664 0000000 0000000 00000000376 14570351320 0022110 0 ustar 00root root 0000000 0000000 # main only
name: Integrate
on:
push:
branches: [main]
env:
FORCE_COLOR: 1
jobs:
_:
uses: medikoo/github-actions-workflows/.github/workflows/0.12-integrate.yml@main
secrets:
USER_GITHUB_TOKEN: ${{ secrets.USER_GITHUB_TOKEN }}
medikoo-d-b11fe68/.github/workflows/publish.yml 0000664 0000000 0000000 00000000472 14570351320 0021571 0 ustar 00root root 0000000 0000000 # Version tags only
name: Publish
on:
push:
tags:
- v[0-9]+.[0-9]+.[0-9]+
env:
FORCE_COLOR: 1
jobs:
_:
uses: medikoo/github-actions-workflows/.github/workflows/publish.yml@main
secrets:
USER_GITHUB_TOKEN: ${{ secrets.USER_GITHUB_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
medikoo-d-b11fe68/.github/workflows/validate.yml 0000664 0000000 0000000 00000000275 14570351320 0021715 0 ustar 00root root 0000000 0000000 # PR's only
name: Validate
on:
pull_request:
branches: [main]
env:
FORCE_COLOR: 1
jobs:
_:
uses: medikoo/github-actions-workflows/.github/workflows/0.12-validate.yml@main
medikoo-d-b11fe68/.gitignore 0000664 0000000 0000000 00000000106 14570351320 0015765 0 ustar 00root root 0000000 0000000 /.nyc_output
/coverage
/node_modules
npm-debug.log
/package-lock.json
medikoo-d-b11fe68/.npmignore 0000664 0000000 0000000 00000000064 14570351320 0015777 0 ustar 00root root 0000000 0000000 /.editorconfig
/.github
/commitlint.config.js
/test
medikoo-d-b11fe68/CHANGELOG.md 0000664 0000000 0000000 00000001044 14570351320 0015610 0 ustar 00root root 0000000 0000000 # Changelog
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
### [1.0.2](https://github.com/medikoo/d/compare/v1.0.1...v1.0.2) (2024-03-01)
### Maintenance Improvements
- Upgrade `type` to v2 ([43b0eb8](https://github.com/medikoo/d/commit/43b0eb845d9efad3450e0e641ea1a827a5ba1966))
### [1.0.1](https://github.com/medikoo/d/compare/v0.1.1...v1.0.1) (2019-06-14)
## Changelog for previous versions
See `CHANGES` file
medikoo-d-b11fe68/CHANGES 0000664 0000000 0000000 00000000746 14570351320 0015002 0 ustar 00root root 0000000 0000000 For recent changelog see CHANGELOG.md
-----
v1.0.0 -- 2015.12.04
- autoBind changes:
- replace `bindTo` argument with options and `resolveContext` option
- Add support `overwriteDefinition`
- Introduce IE11 bug workaround in `lazy` handler
v0.1.1 -- 2014.04.24
- Add `autoBind` and `lazy` utilities
- Allow to pass other options to be merged onto created descriptor.
Useful when used with other custom utilties
v0.1.0 -- 2013.06.20
Initial (derived from es5-ext project)
medikoo-d-b11fe68/LICENSE 0000664 0000000 0000000 00000001405 14570351320 0015005 0 ustar 00root root 0000000 0000000 ISC License
Copyright (c) 2013-2024, Mariusz Nowak, @medikoo, medikoo.com
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
medikoo-d-b11fe68/README.md 0000664 0000000 0000000 00000007155 14570351320 0015267 0 ustar 00root root 0000000 0000000 [![Build status][build-image]][build-url]
[![Tests coverage][cov-image]][cov-url]
[![npm version][npm-image]][npm-url]
# d
## Property descriptor factory
_Originally derived from [d](https://github.com/medikoo/d) package._
Defining properties with descriptors is very verbose:
```javascript
var Account = function () {};
Object.defineProperties(Account.prototype, {
deposit: {
value: function () { /* ... */ },
configurable: true,
enumerable: false,
writable: true
},
withdraw: {
value: function () { /* ... */ },
configurable: true,
enumerable: false,
writable: true
},
balance: { get: function () { /* ... */ }, configurable: true, enumerable: false }
});
```
D cuts that to:
```javascript
var d = require("d");
var Account = function () {};
Object.defineProperties(Account.prototype, {
deposit: d(function () { /* ... */ }),
withdraw: d(function () { /* ... */ }),
balance: d.gs(function () { /* ... */ })
});
```
By default, created descriptor follow characteristics of native ES5 properties, and defines values as:
```javascript
{ configurable: true, enumerable: false, writable: true }
```
You can overwrite it by preceding _value_ argument with instruction:
```javascript
d("c", value); // { configurable: true, enumerable: false, writable: false }
d("ce", value); // { configurable: true, enumerable: true, writable: false }
d("e", value); // { configurable: false, enumerable: true, writable: false }
// Same way for get/set:
d.gs("e", value); // { configurable: false, enumerable: true }
```
### Installation
$ npm install d
To port it to Browser or any other (non CJS) environment, use your favorite CJS bundler. No favorite yet? Try: [Browserify](http://browserify.org/), [Webmake](https://github.com/medikoo/modules-webmake) or [Webpack](http://webpack.github.io/)
### Other utilities
#### autoBind(obj, props) _(d/auto-bind)_
Define methods which will be automatically bound to its instances
```javascript
var d = require('d');
var autoBind = require('d/auto-bind');
var Foo = function () { this._count = 0; };
Object.defineProperties(Foo.prototype, autoBind({
increment: d(function () { ++this._count; });
}));
var foo = new Foo();
// Increment foo counter on each domEl click
domEl.addEventListener('click', foo.increment, false);
```
#### lazy(obj, props) _(d/lazy)_
Define lazy properties, which will be resolved on first access
```javascript
var d = require("d");
var lazy = require("d/lazy");
var Foo = function () {};
Object.defineProperties(Foo.prototype, lazy({ items: d(function () { return []; }) }));
var foo = new Foo();
foo.items.push(1, 2); // foo.items array created and defined directly on foo
```
## Tests
$ npm test
## Security contact information
To report a security vulnerability, please use the [Tidelift security contact](https://tidelift.com/security). Tidelift will coordinate the fix and disclosure.
---
[build-image]: https://github.com/medikoo/d/workflows/Integrate/badge.svg
[build-url]: https://github.com/medikoo/d/actions?query=workflow%3AIntegrate
[cov-image]: https://img.shields.io/codecov/c/github/medikoo/d.svg
[cov-url]: https://codecov.io/gh/medikoo/d
[npm-image]: https://img.shields.io/npm/v/d.svg
[npm-url]: https://www.npmjs.com/package/d
medikoo-d-b11fe68/auto-bind.js 0000664 0000000 0000000 00000002324 14570351320 0016221 0 ustar 00root root 0000000 0000000 "use strict";
var isValue = require("type/value/is")
, ensureValue = require("type/value/ensure")
, ensurePlainFunction = require("type/plain-function/ensure")
, copy = require("es5-ext/object/copy")
, normalizeOptions = require("es5-ext/object/normalize-options")
, map = require("es5-ext/object/map");
var bind = Function.prototype.bind
, defineProperty = Object.defineProperty
, hasOwnProperty = Object.prototype.hasOwnProperty
, define;
define = function (name, desc, options) {
var value = ensureValue(desc) && ensurePlainFunction(desc.value), dgs;
dgs = copy(desc);
delete dgs.writable;
delete dgs.value;
dgs.get = function () {
if (!options.overwriteDefinition && hasOwnProperty.call(this, name)) return value;
desc.value = bind.call(value, options.resolveContext ? options.resolveContext(this) : this);
defineProperty(this, name, desc);
return this[name];
};
return dgs;
};
module.exports = function (props/*, options*/) {
var options = normalizeOptions(arguments[1]);
if (isValue(options.resolveContext)) ensurePlainFunction(options.resolveContext);
return map(props, function (desc, name) { return define(name, desc, options); });
};
medikoo-d-b11fe68/commitlint.config.js 0000664 0000000 0000000 00000001236 14570351320 0017763 0 ustar 00root root 0000000 0000000 "use strict";
module.exports = {
rules: {
"body-leading-blank": [2, "always"],
"body-max-line-length": [2, "always", 72],
"footer-leading-blank": [2, "always"],
"footer-max-line-length": [2, "always", 72],
"header-max-length": [2, "always", 72],
"scope-case": [2, "always", "start-case"],
"scope-enum": [2, "always", [""]],
"subject-case": [2, "always", "sentence-case"],
"subject-empty": [2, "never"],
"subject-full-stop": [2, "never", "."],
"type-case": [2, "always", "lower-case"],
"type-empty": [2, "never"],
"type-enum": [
2, "always",
["build", "chore", "ci", "docs", "feat", "fix", "perf", "refactor", "style", "test"]
]
}
};
medikoo-d-b11fe68/index.js 0000664 0000000 0000000 00000003011 14570351320 0015440 0 ustar 00root root 0000000 0000000 "use strict";
var isValue = require("type/value/is")
, isPlainFunction = require("type/plain-function/is")
, assign = require("es5-ext/object/assign")
, normalizeOpts = require("es5-ext/object/normalize-options")
, contains = require("es5-ext/string/#/contains");
var d = (module.exports = function (dscr, value/*, options*/) {
var c, e, w, options, desc;
if (arguments.length < 2 || typeof dscr !== "string") {
options = value;
value = dscr;
dscr = null;
} else {
options = arguments[2];
}
if (isValue(dscr)) {
c = contains.call(dscr, "c");
e = contains.call(dscr, "e");
w = contains.call(dscr, "w");
} else {
c = w = true;
e = false;
}
desc = { value: value, configurable: c, enumerable: e, writable: w };
return !options ? desc : assign(normalizeOpts(options), desc);
});
d.gs = function (dscr, get, set/*, options*/) {
var c, e, options, desc;
if (typeof dscr !== "string") {
options = set;
set = get;
get = dscr;
dscr = null;
} else {
options = arguments[3];
}
if (!isValue(get)) {
get = undefined;
} else if (!isPlainFunction(get)) {
options = get;
get = set = undefined;
} else if (!isValue(set)) {
set = undefined;
} else if (!isPlainFunction(set)) {
options = set;
set = undefined;
}
if (isValue(dscr)) {
c = contains.call(dscr, "c");
e = contains.call(dscr, "e");
} else {
c = true;
e = false;
}
desc = { get: get, set: set, configurable: c, enumerable: e };
return !options ? desc : assign(normalizeOpts(options), desc);
};
medikoo-d-b11fe68/lazy.js 0000664 0000000 0000000 00000007524 14570351320 0015325 0 ustar 00root root 0000000 0000000 "use strict";
var isPlainFunction = require("type/plain-function/is")
, ensureValue = require("type/value/ensure")
, isValue = require("type/value/is")
, map = require("es5-ext/object/map")
, contains = require("es5-ext/string/#/contains");
var call = Function.prototype.call
, defineProperty = Object.defineProperty
, getOwnPropertyDescriptor = Object.getOwnPropertyDescriptor
, getPrototypeOf = Object.getPrototypeOf
, hasOwnProperty = Object.prototype.hasOwnProperty
, cacheDesc = { configurable: false, enumerable: false, writable: false, value: null }
, define;
define = function (name, options) {
var value, dgs, cacheName, desc, writable = false, resolvable, flat;
options = Object(ensureValue(options));
cacheName = options.cacheName;
flat = options.flat;
if (!isValue(cacheName)) cacheName = name;
delete options.cacheName;
value = options.value;
resolvable = isPlainFunction(value);
delete options.value;
dgs = { configurable: Boolean(options.configurable), enumerable: Boolean(options.enumerable) };
if (name !== cacheName) {
dgs.get = function () {
if (hasOwnProperty.call(this, cacheName)) return this[cacheName];
cacheDesc.value = resolvable ? call.call(value, this, options) : value;
cacheDesc.writable = writable;
defineProperty(this, cacheName, cacheDesc);
cacheDesc.value = null;
if (desc) defineProperty(this, name, desc);
return this[cacheName];
};
} else if (!flat) {
dgs.get = function self() {
var ownDesc;
if (hasOwnProperty.call(this, name)) {
ownDesc = getOwnPropertyDescriptor(this, name);
// It happens in Safari, that getter is still called after property
// was defined with a value, following workarounds that
// While in IE11 it may happen that here ownDesc is undefined (go figure)
if (ownDesc) {
if (ownDesc.hasOwnProperty("value")) return ownDesc.value;
if (typeof ownDesc.get === "function" && ownDesc.get !== self) {
return ownDesc.get.call(this);
}
return value;
}
}
desc.value = resolvable ? call.call(value, this, options) : value;
defineProperty(this, name, desc);
desc.value = null;
return this[name];
};
} else {
dgs.get = function self() {
var base = this, ownDesc;
if (hasOwnProperty.call(this, name)) {
// It happens in Safari, that getter is still called after property
// was defined with a value, following workarounds that
ownDesc = getOwnPropertyDescriptor(this, name);
if (ownDesc.hasOwnProperty("value")) return ownDesc.value;
if (typeof ownDesc.get === "function" && ownDesc.get !== self) {
return ownDesc.get.call(this);
}
}
while (!hasOwnProperty.call(base, name)) base = getPrototypeOf(base);
desc.value = resolvable ? call.call(value, base, options) : value;
defineProperty(base, name, desc);
desc.value = null;
return base[name];
};
}
dgs.set = function (value) {
if (hasOwnProperty.call(this, name)) {
throw new TypeError("Cannot assign to lazy defined '" + name + "' property of " + this);
}
dgs.get.call(this);
this[cacheName] = value;
};
if (options.desc) {
desc = {
configurable: contains.call(options.desc, "c"),
enumerable: contains.call(options.desc, "e")
};
if (cacheName === name) {
desc.writable = contains.call(options.desc, "w");
desc.value = null;
} else {
writable = contains.call(options.desc, "w");
desc.get = dgs.get;
desc.set = dgs.set;
}
delete options.desc;
} else if (cacheName === name) {
desc = {
configurable: Boolean(options.configurable),
enumerable: Boolean(options.enumerable),
writable: Boolean(options.writable),
value: null
};
}
delete options.configurable;
delete options.enumerable;
delete options.writable;
return dgs;
};
module.exports = function (props) {
return map(props, function (desc, name) { return define(name, desc); });
};
medikoo-d-b11fe68/package.json 0000664 0000000 0000000 00000003724 14570351320 0016274 0 ustar 00root root 0000000 0000000 {
"name": "d",
"version": "1.0.2",
"description": "Property descriptor factory",
"author": "Mariusz Nowak (http://www.medikoo.com/)",
"keywords": [
"descriptor",
"es",
"ecmascript",
"ecma",
"property",
"descriptors",
"meta",
"properties"
],
"repository": "medikoo/d",
"dependencies": {
"es5-ext": "^0.10.64",
"type": "^2.7.2"
},
"devDependencies": {
"eslint": "^8.57.0",
"eslint-config-medikoo": "^4.2.0",
"git-list-updated": "^1.2.1",
"github-release-from-cc-changelog": "^2.3.0",
"husky": "^4.3.8",
"lint-staged": "~13.2.3",
"nyc": "^15.1.0",
"prettier-elastic": "^2.8.8",
"tad": "^3.1.1"
},
"husky": {
"hooks": {
"pre-commit": "lint-staged"
}
},
"lint-staged": {
"*.js": [
"eslint"
],
"*.{css,html,js,json,md,yaml,yml}": [
"prettier -c"
]
},
"eslintConfig": {
"extends": "medikoo/es5",
"root": true
},
"prettier": {
"printWidth": 100,
"tabWidth": 4,
"overrides": [
{
"files": [
"*.md",
"*.yml"
],
"options": {
"tabWidth": 2
}
}
]
},
"nyc": {
"all": true,
"exclude": [
".github",
"coverage/**",
"test/**",
"*.config.js"
],
"reporter": [
"lcov",
"html",
"text-summary"
]
},
"scripts": {
"coverage": "nyc npm test",
"lint": "eslint --ignore-path=.gitignore .",
"lint:updated": "pipe-git-updated --base=main --ext=js -- eslint --ignore-pattern '!*'",
"prettier-check": "prettier -c --ignore-path .gitignore \"**/*.{css,html,js,json,md,yaml,yml}\"",
"prettier-check:updated": "pipe-git-updated --base=main --ext=css --ext=html --ext=js --ext=json --ext=md --ext=yaml --ext=yml -- prettier -c",
"prettify": "prettier --write --ignore-path .gitignore \"**/*.{css,html,js,json,md,yaml,yml}\"",
"prettify:updated": "pipe-git-updated ---base=main -ext=css --ext=html --ext=js --ext=json --ext=md --ext=yaml --ext=yml -- prettier --write",
"test": "tad"
},
"license": "ISC",
"engines": {
"node": ">=0.12"
}
}
medikoo-d-b11fe68/test/ 0000775 0000000 0000000 00000000000 14570351320 0014757 5 ustar 00root root 0000000 0000000 medikoo-d-b11fe68/test/auto-bind.js 0000664 0000000 0000000 00000000375 14570351320 0017204 0 ustar 00root root 0000000 0000000 "use strict";
var d = require("../");
module.exports = function (t, a) {
var o = Object.defineProperties(
{}, t({ bar: d(function () { return this === o; }), bar2: d(function () { return this; }) })
);
a.deep([o.bar(), o.bar2()], [true, o]);
};
medikoo-d-b11fe68/test/index.js 0000664 0000000 0000000 00000014173 14570351320 0016432 0 ustar 00root root 0000000 0000000 "use strict";
var getOwnPropertyDescriptor = Object.getOwnPropertyDescriptor;
module.exports = function (t, a) {
var o, c, cg, cs, ce, ceg, ces, cew, cw, e, eg, es, ew, v, vg, vs, w, df, dfg, dfs;
o = Object.create(Object.prototype, {
c: t("c", (c = {})),
cgs: t.gs("c", (cg = function () {}), (cs = function () {})),
ce: t("ce", (ce = {})),
cegs: t.gs("ce", (ceg = function () {}), (ces = function () {})),
cew: t("cew", (cew = {})),
cw: t("cw", (cw = {})),
e: t("e", (e = {})),
egs: t.gs("e", (eg = function () {}), (es = function () {})),
ew: t("ew", (ew = {})),
v: t("", (v = {})),
vgs: t.gs("", (vg = function () {}), (vs = function () {})),
w: t("w", (w = {})),
df: t((df = {})),
dfgs: t.gs((dfg = function () {}), (dfs = function () {}))
});
return {
c: function (a) {
var d = getOwnPropertyDescriptor(o, "c");
a(d.value, c, "Value");
a(d.get, undefined, "Get");
a(d.set, undefined, "Set");
a(d.configurable, true, "Configurable");
a(d.enumerable, false, "Enumerable");
a(d.writable, false, "Writable");
d = getOwnPropertyDescriptor(o, "cgs");
a(d.value, undefined, "GS Value");
a(d.get, cg, "GS Get");
a(d.set, cs, "GS Set");
a(d.configurable, true, "GS Configurable");
a(d.enumerable, false, "GS Enumerable");
a(d.writable, undefined, "GS Writable");
},
ce: function (a) {
var d = getOwnPropertyDescriptor(o, "ce");
a(d.value, ce, "Value");
a(d.get, undefined, "Get");
a(d.set, undefined, "Set");
a(d.configurable, true, "Configurable");
a(d.enumerable, true, "Enumerable");
a(d.writable, false, "Writable");
d = getOwnPropertyDescriptor(o, "cegs");
a(d.value, undefined, "GS Value");
a(d.get, ceg, "GS Get");
a(d.set, ces, "GS Set");
a(d.configurable, true, "GS Configurable");
a(d.enumerable, true, "GS Enumerable");
a(d.writable, undefined, "GS Writable");
},
cew: function (a) {
var d = getOwnPropertyDescriptor(o, "cew");
a(d.value, cew, "Value");
a(d.get, undefined, "Get");
a(d.set, undefined, "Set");
a(d.configurable, true, "Configurable");
a(d.enumerable, true, "Enumerable");
a(d.writable, true, "Writable");
},
cw: function (a) {
var d = getOwnPropertyDescriptor(o, "cw");
a(d.value, cw, "Value");
a(d.get, undefined, "Get");
a(d.set, undefined, "Set");
a(d.configurable, true, "Configurable");
a(d.enumerable, false, "Enumerable");
a(d.writable, true, "Writable");
},
e: function (a) {
var d = getOwnPropertyDescriptor(o, "e");
a(d.value, e, "Value");
a(d.get, undefined, "Get");
a(d.set, undefined, "Set");
a(d.configurable, false, "Configurable");
a(d.enumerable, true, "Enumerable");
a(d.writable, false, "Writable");
d = getOwnPropertyDescriptor(o, "egs");
a(d.value, undefined, "GS Value");
a(d.get, eg, "GS Get");
a(d.set, es, "GS Set");
a(d.configurable, false, "GS Configurable");
a(d.enumerable, true, "GS Enumerable");
a(d.writable, undefined, "GS Writable");
},
ew: function (a) {
var d = getOwnPropertyDescriptor(o, "ew");
a(d.value, ew, "Value");
a(d.get, undefined, "Get");
a(d.set, undefined, "Set");
a(d.configurable, false, "Configurable");
a(d.enumerable, true, "Enumerable");
a(d.writable, true, "Writable");
},
v: function (a) {
var d = getOwnPropertyDescriptor(o, "v");
a(d.value, v, "Value");
a(d.get, undefined, "Get");
a(d.set, undefined, "Set");
a(d.configurable, false, "Configurable");
a(d.enumerable, false, "Enumerable");
a(d.writable, false, "Writable");
d = getOwnPropertyDescriptor(o, "vgs");
a(d.value, undefined, "GS Value");
a(d.get, vg, "GS Get");
a(d.set, vs, "GS Set");
a(d.configurable, false, "GS Configurable");
a(d.enumerable, false, "GS Enumerable");
a(d.writable, undefined, "GS Writable");
},
w: function (a) {
var d = getOwnPropertyDescriptor(o, "w");
a(d.value, w, "Value");
a(d.get, undefined, "Get");
a(d.set, undefined, "Set");
a(d.configurable, false, "Configurable");
a(d.enumerable, false, "Enumerable");
a(d.writable, true, "Writable");
},
d: function (a) {
var d = getOwnPropertyDescriptor(o, "df");
a(d.value, df, "Value");
a(d.get, undefined, "Get");
a(d.set, undefined, "Set");
a(d.configurable, true, "Configurable");
a(d.enumerable, false, "Enumerable");
a(d.writable, true, "Writable");
d = getOwnPropertyDescriptor(o, "dfgs");
a(d.value, undefined, "GS Value");
a(d.get, dfg, "GS Get");
a(d.set, dfs, "GS Set");
a(d.configurable, true, "GS Configurable");
a(d.enumerable, false, "GS Enumerable");
a(d.writable, undefined, "GS Writable");
},
Options: {
v: function (a) {
var x = {}, d = t(x, { foo: true });
a.deep(
d,
{ configurable: true, enumerable: false, writable: true, value: x, foo: true },
"No descriptor"
);
d = t("c", "foo", { marko: "elo" });
a.deep(
d,
{
configurable: true,
enumerable: false,
writable: false,
value: "foo",
marko: "elo"
},
"Descriptor"
);
},
gs: function (a) {
var gFn = function () {}, sFn = function () {}, d;
d = t.gs(gFn, sFn, { foo: true });
a.deep(
d, { configurable: true, enumerable: false, get: gFn, set: sFn, foo: true },
"No descriptor"
);
d = t.gs(null, sFn, { foo: true });
a.deep(
d,
{ configurable: true, enumerable: false, get: undefined, set: sFn, foo: true },
"No descriptor: Just set"
);
d = t.gs(gFn, { foo: true });
a.deep(
d,
{ configurable: true, enumerable: false, get: gFn, set: undefined, foo: true },
"No descriptor: Just get"
);
d = t.gs("e", gFn, sFn, { bar: true });
a.deep(
d, { configurable: false, enumerable: true, get: gFn, set: sFn, bar: true },
"Descriptor"
);
d = t.gs("e", null, sFn, { bar: true });
a.deep(
d,
{ configurable: false, enumerable: true, get: undefined, set: sFn, bar: true },
"Descriptor: Just set"
);
d = t.gs("e", gFn, { bar: true });
a.deep(
d,
{ configurable: false, enumerable: true, get: gFn, set: undefined, bar: true },
"Descriptor: Just get"
);
}
}
};
};
medikoo-d-b11fe68/test/lazy.js 0000664 0000000 0000000 00000005420 14570351320 0016275 0 ustar 00root root 0000000 0000000 "use strict";
var d = require("../")
, getOwnPropertyDescriptor = Object.getOwnPropertyDescriptor;
module.exports = function (t, a) {
var Foo = function () {}, i = 1, o, o2, desc;
Object.defineProperties(
Foo.prototype,
t({
bar: d(function () { return ++i; }),
bar2: d(function () { return this.bar + 23; }),
bar3: d(function () { return this.bar2 + 34; }, { desc: "ew" }),
bar4: d(function () { return this.bar3 + 12; }, { cacheName: "_bar4_" }),
bar5: d(function () { return this.bar4 + 3; }, { cacheName: "_bar5_", desc: "e" })
})
);
desc = getOwnPropertyDescriptor(Foo.prototype, "bar");
a(desc.configurable, true, "Configurable: default");
a(desc.enumerable, false, "Enumerable: default");
o = new Foo();
a.deep([o.bar, o.bar2, o.bar3, o.bar4, o.bar5], [2, 25, 59, 71, 74], "Values");
a.deep(
getOwnPropertyDescriptor(o, "bar3"),
{ configurable: false, enumerable: true, writable: true, value: 59 }, "Desc"
);
a(o.hasOwnProperty("bar4"), false, "Cache not exposed");
desc = getOwnPropertyDescriptor(o, "bar5");
a.deep(
desc, { configurable: false, enumerable: true, get: desc.get, set: desc.set },
"Cache & Desc: desc"
);
o2 = Object.create(o);
o2.bar = 30;
o2.bar3 = 100;
a.deep(
[o2.bar, o2.bar2, o2.bar3, o2.bar4, o2.bar5], [30, 25, 100, 112, 115], "Extension Values"
);
Foo = function () {};
Object.defineProperties(
Foo.prototype,
t({
test: d("w", function () { return "raz"; }),
test2: d("", function () { return "raz"; }, { desc: "w" }),
test3: d("", function () { return "raz"; }, { cacheName: "__test3__", desc: "w" }),
test4: d("w", "bar")
})
);
o = new Foo();
o.test = "marko";
a.deep(
getOwnPropertyDescriptor(o, "test"),
{ configurable: false, enumerable: false, writable: true, value: "marko" }, "Set before get"
);
o.test2 = "marko2";
a.deep(
getOwnPropertyDescriptor(o, "test2"),
{ configurable: false, enumerable: false, writable: true, value: "marko2" },
"Set before get: Custom desc"
);
o.test3 = "marko3";
a.deep(
getOwnPropertyDescriptor(o, "__test3__"),
{ configurable: false, enumerable: false, writable: true, value: "marko3" },
"Set before get: Custom cache name"
);
a(o.test4, "bar", "Resolve by value");
a.h1("Flat");
Object.defineProperties(
Foo.prototype,
t({
flat: d(function () { return "foo"; }, { flat: true }),
flat2: d(function () { return "bar"; }, { flat: true })
})
);
a.h2("Instance");
a(o.flat, "foo", "Value");
a(o.hasOwnProperty("flat"), false, "Instance");
a(Foo.prototype.flat, "foo", "Prototype");
a.h2("Direct");
a(Foo.prototype.flat2, "bar");
a.h2("Reset direct");
Object.defineProperties(Foo.prototype, t({ testResetDirect: d(false) }));
a.throws(function () { Foo.prototype.testResetDirect = false; }, TypeError);
};