Current Folder
This commit is contained in:
1 parent
8b3382289b
commit
cfcada880d
4379 files changed
No files matched your search
+10
@@ -0,0 +1,10 @@
|
||||
"use strict";
|
||||
|
||||
if (!require("./is-implemented")()) {
|
||||
Object.defineProperty(require("ext/global-this"), "Symbol", {
|
||||
value: require("./polyfill"),
|
||||
configurable: true,
|
||||
enumerable: false,
|
||||
writable: true
|
||||
});
|
||||
}
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
"use strict";
|
||||
|
||||
module.exports = require("./is-implemented")()
|
||||
? require("ext/global-this").Symbol
|
||||
: require("./polyfill");
|
||||
+20
@@ -0,0 +1,20 @@
|
||||
"use strict";
|
||||
|
||||
var global = require("ext/global-this")
|
||||
, validTypes = { object: true, symbol: true };
|
||||
|
||||
module.exports = function () {
|
||||
var Symbol = global.Symbol;
|
||||
var symbol;
|
||||
if (typeof Symbol !== "function") return false;
|
||||
symbol = Symbol("test symbol");
|
||||
try { String(symbol); }
|
||||
catch (e) { return false; }
|
||||
|
||||
// Return 'true' also for polyfills
|
||||
if (!validTypes[typeof Symbol.iterator]) return false;
|
||||
if (!validTypes[typeof Symbol.toPrimitive]) return false;
|
||||
if (!validTypes[typeof Symbol.toStringTag]) return false;
|
||||
|
||||
return true;
|
||||
};
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
// Exports true if environment provides native `Symbol` implementation
|
||||
|
||||
"use strict";
|
||||
|
||||
var Symbol = require("ext/global-this").Symbol;
|
||||
|
||||
module.exports = typeof Symbol === "function" && typeof Symbol() === "symbol";
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
"use strict";
|
||||
|
||||
module.exports = function (value) {
|
||||
if (!value) return false;
|
||||
if (typeof value === "symbol") return true;
|
||||
if (!value.constructor) return false;
|
||||
if (value.constructor.name !== "Symbol") return false;
|
||||
return value[value.constructor.toStringTag] === "Symbol";
|
||||
};
|
||||
+29
@@ -0,0 +1,29 @@
|
||||
"use strict";
|
||||
|
||||
var d = require("d");
|
||||
|
||||
var create = Object.create, defineProperty = Object.defineProperty, objPrototype = Object.prototype;
|
||||
|
||||
var created = create(null);
|
||||
module.exports = function (desc) {
|
||||
var postfix = 0, name, ie11BugWorkaround;
|
||||
while (created[desc + (postfix || "")]) ++postfix;
|
||||
desc += postfix || "";
|
||||
created[desc] = true;
|
||||
name = "@@" + desc;
|
||||
defineProperty(
|
||||
objPrototype,
|
||||
name,
|
||||
d.gs(null, function (value) {
|
||||
// For IE11 issue see:
|
||||
// https://connect.microsoft.com/IE/feedbackdetail/view/1928508/
|
||||
// ie11-broken-getters-on-dom-objects
|
||||
// https://github.com/medikoo/es6-symbol/issues/12
|
||||
if (ie11BugWorkaround) return;
|
||||
ie11BugWorkaround = true;
|
||||
defineProperty(this, name, d(value));
|
||||
ie11BugWorkaround = false;
|
||||
})
|
||||
);
|
||||
return name;
|
||||
};
|
||||
+34
@@ -0,0 +1,34 @@
|
||||
"use strict";
|
||||
|
||||
var d = require("d")
|
||||
, NativeSymbol = require("ext/global-this").Symbol;
|
||||
|
||||
module.exports = function (SymbolPolyfill) {
|
||||
return Object.defineProperties(SymbolPolyfill, {
|
||||
// To ensure proper interoperability with other native functions (e.g. Array.from)
|
||||
// fallback to eventual native implementation of given symbol
|
||||
hasInstance: d(
|
||||
"", (NativeSymbol && NativeSymbol.hasInstance) || SymbolPolyfill("hasInstance")
|
||||
),
|
||||
isConcatSpreadable: d(
|
||||
"",
|
||||
(NativeSymbol && NativeSymbol.isConcatSpreadable) ||
|
||||
SymbolPolyfill("isConcatSpreadable")
|
||||
),
|
||||
iterator: d("", (NativeSymbol && NativeSymbol.iterator) || SymbolPolyfill("iterator")),
|
||||
match: d("", (NativeSymbol && NativeSymbol.match) || SymbolPolyfill("match")),
|
||||
replace: d("", (NativeSymbol && NativeSymbol.replace) || SymbolPolyfill("replace")),
|
||||
search: d("", (NativeSymbol && NativeSymbol.search) || SymbolPolyfill("search")),
|
||||
species: d("", (NativeSymbol && NativeSymbol.species) || SymbolPolyfill("species")),
|
||||
split: d("", (NativeSymbol && NativeSymbol.split) || SymbolPolyfill("split")),
|
||||
toPrimitive: d(
|
||||
"", (NativeSymbol && NativeSymbol.toPrimitive) || SymbolPolyfill("toPrimitive")
|
||||
),
|
||||
toStringTag: d(
|
||||
"", (NativeSymbol && NativeSymbol.toStringTag) || SymbolPolyfill("toStringTag")
|
||||
),
|
||||
unscopables: d(
|
||||
"", (NativeSymbol && NativeSymbol.unscopables) || SymbolPolyfill("unscopables")
|
||||
)
|
||||
});
|
||||
};
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
"use strict";
|
||||
|
||||
var d = require("d")
|
||||
, validateSymbol = require("../../../validate-symbol");
|
||||
|
||||
var registry = Object.create(null);
|
||||
|
||||
module.exports = function (SymbolPolyfill) {
|
||||
return Object.defineProperties(SymbolPolyfill, {
|
||||
for: d(function (key) {
|
||||
if (registry[key]) return registry[key];
|
||||
return (registry[key] = SymbolPolyfill(String(key)));
|
||||
}),
|
||||
keyFor: d(function (symbol) {
|
||||
var key;
|
||||
validateSymbol(symbol);
|
||||
for (key in registry) {
|
||||
if (registry[key] === symbol) return key;
|
||||
}
|
||||
return undefined;
|
||||
})
|
||||
});
|
||||
};
|
||||
+137
@@ -0,0 +1,137 @@
|
||||
{
|
||||
"_from": "es6-symbol@~3.1.3",
|
||||
"_id": "es6-symbol@3.1.3",
|
||||
"_inBundle": false,
|
||||
"_integrity": "sha512-NJ6Yn3FuDinBaBRWl/q5X/s4koRHBrgKAu+yGI6JCBeiu3qrcbJhwT2GeR/EXVfylRk8dpQVJoLEFhK+Mu31NA==",
|
||||
"_location": "/es6-symbol",
|
||||
"_phantomChildren": {},
|
||||
"_requested": {
|
||||
"type": "range",
|
||||
"registry": true,
|
||||
"raw": "es6-symbol@~3.1.3",
|
||||
"name": "es6-symbol",
|
||||
"escapedName": "es6-symbol",
|
||||
"rawSpec": "~3.1.3",
|
||||
"saveSpec": null,
|
||||
"fetchSpec": "~3.1.3"
|
||||
},
|
||||
"_requiredBy": [
|
||||
"/es5-ext",
|
||||
"/es6-iterator"
|
||||
],
|
||||
"_resolved": "https://registry.npmjs.org/es6-symbol/-/es6-symbol-3.1.3.tgz",
|
||||
"_shasum": "bad5d3c1bcdac28269f4cb331e431c78ac705d18",
|
||||
"_spec": "es6-symbol@~3.1.3",
|
||||
"_where": "C:\\Users\\Luis\\source\\repos\\AAMasters\\BackendServers\\node_modules\\es5-ext",
|
||||
"author": {
|
||||
"name": "Mariusz Nowak",
|
||||
"email": "medyk@medikoo.com",
|
||||
"url": "http://www.medikoo.com/"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/medikoo/es6-symbol/issues"
|
||||
},
|
||||
"bundleDependencies": false,
|
||||
"dependencies": {
|
||||
"d": "^1.0.1",
|
||||
"ext": "^1.1.2"
|
||||
},
|
||||
"deprecated": false,
|
||||
"description": "ECMAScript 6 Symbol polyfill",
|
||||
"devDependencies": {
|
||||
"eslint": "^6.6.0",
|
||||
"eslint-config-medikoo": "^2.6.0",
|
||||
"git-list-updated": "^1.2.1",
|
||||
"husky": "^3.0.9",
|
||||
"lint-staged": "^9.4.2",
|
||||
"prettier-elastic": "^1.18.2",
|
||||
"tad": "^3.0.1"
|
||||
},
|
||||
"eslintConfig": {
|
||||
"extends": "medikoo/es5",
|
||||
"root": true,
|
||||
"rules": {
|
||||
"new-cap": [
|
||||
"error",
|
||||
{
|
||||
"capIsNewExceptions": [
|
||||
"NativeSymbol",
|
||||
"SymbolPolyfill"
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
"overrides": [
|
||||
{
|
||||
"files": [
|
||||
"polyfill.js"
|
||||
],
|
||||
"rules": {
|
||||
"func-names": "off"
|
||||
}
|
||||
},
|
||||
{
|
||||
"files": [
|
||||
"test/*.js"
|
||||
],
|
||||
"globals": {
|
||||
"Symbol": true
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"homepage": "https://github.com/medikoo/es6-symbol#readme",
|
||||
"husky": {
|
||||
"hooks": {
|
||||
"pre-commit": "lint-staged"
|
||||
}
|
||||
},
|
||||
"keywords": [
|
||||
"symbol",
|
||||
"private",
|
||||
"property",
|
||||
"es6",
|
||||
"ecmascript",
|
||||
"harmony",
|
||||
"ponyfill",
|
||||
"polyfill"
|
||||
],
|
||||
"license": "ISC",
|
||||
"lint-staged": {
|
||||
"*.js": [
|
||||
"eslint"
|
||||
],
|
||||
"*.{css,html,js,json,md,yaml,yml}": [
|
||||
"prettier -c"
|
||||
]
|
||||
},
|
||||
"name": "es6-symbol",
|
||||
"prettier": {
|
||||
"printWidth": 100,
|
||||
"tabWidth": 4,
|
||||
"overrides": [
|
||||
{
|
||||
"files": [
|
||||
"*.md"
|
||||
],
|
||||
"options": {
|
||||
"tabWidth": 2
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git://github.com/medikoo/es6-symbol.git"
|
||||
},
|
||||
"scripts": {
|
||||
"lint": "eslint --ignore-path=.gitignore .",
|
||||
"lint:updated": "pipe-git-updated --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 --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 --ext=css --ext=html --ext=js --ext=json --ext=md --ext=yaml --ext=yml -- prettier --write",
|
||||
"test": "tad"
|
||||
},
|
||||
"version": "3.1.3"
|
||||
}
|
||||
+87
@@ -0,0 +1,87 @@
|
||||
// ES2015 Symbol polyfill for environments that do not (or partially) support it
|
||||
|
||||
"use strict";
|
||||
|
||||
var d = require("d")
|
||||
, validateSymbol = require("./validate-symbol")
|
||||
, NativeSymbol = require("ext/global-this").Symbol
|
||||
, generateName = require("./lib/private/generate-name")
|
||||
, setupStandardSymbols = require("./lib/private/setup/standard-symbols")
|
||||
, setupSymbolRegistry = require("./lib/private/setup/symbol-registry");
|
||||
|
||||
var create = Object.create
|
||||
, defineProperties = Object.defineProperties
|
||||
, defineProperty = Object.defineProperty;
|
||||
|
||||
var SymbolPolyfill, HiddenSymbol, isNativeSafe;
|
||||
|
||||
if (typeof NativeSymbol === "function") {
|
||||
try {
|
||||
String(NativeSymbol());
|
||||
isNativeSafe = true;
|
||||
} catch (ignore) {}
|
||||
} else {
|
||||
NativeSymbol = null;
|
||||
}
|
||||
|
||||
// Internal constructor (not one exposed) for creating Symbol instances.
|
||||
// This one is used to ensure that `someSymbol instanceof Symbol` always return false
|
||||
HiddenSymbol = function Symbol(description) {
|
||||
if (this instanceof HiddenSymbol) throw new TypeError("Symbol is not a constructor");
|
||||
return SymbolPolyfill(description);
|
||||
};
|
||||
|
||||
// Exposed `Symbol` constructor
|
||||
// (returns instances of HiddenSymbol)
|
||||
module.exports = SymbolPolyfill = function Symbol(description) {
|
||||
var symbol;
|
||||
if (this instanceof Symbol) throw new TypeError("Symbol is not a constructor");
|
||||
if (isNativeSafe) return NativeSymbol(description);
|
||||
symbol = create(HiddenSymbol.prototype);
|
||||
description = description === undefined ? "" : String(description);
|
||||
return defineProperties(symbol, {
|
||||
__description__: d("", description),
|
||||
__name__: d("", generateName(description))
|
||||
});
|
||||
};
|
||||
|
||||
setupStandardSymbols(SymbolPolyfill);
|
||||
setupSymbolRegistry(SymbolPolyfill);
|
||||
|
||||
// Internal tweaks for real symbol producer
|
||||
defineProperties(HiddenSymbol.prototype, {
|
||||
constructor: d(SymbolPolyfill),
|
||||
toString: d("", function () { return this.__name__; })
|
||||
});
|
||||
|
||||
// Proper implementation of methods exposed on Symbol.prototype
|
||||
// They won't be accessible on produced symbol instances as they derive from HiddenSymbol.prototype
|
||||
defineProperties(SymbolPolyfill.prototype, {
|
||||
toString: d(function () { return "Symbol (" + validateSymbol(this).__description__ + ")"; }),
|
||||
valueOf: d(function () { return validateSymbol(this); })
|
||||
});
|
||||
defineProperty(
|
||||
SymbolPolyfill.prototype,
|
||||
SymbolPolyfill.toPrimitive,
|
||||
d("", function () {
|
||||
var symbol = validateSymbol(this);
|
||||
if (typeof symbol === "symbol") return symbol;
|
||||
return symbol.toString();
|
||||
})
|
||||
);
|
||||
defineProperty(SymbolPolyfill.prototype, SymbolPolyfill.toStringTag, d("c", "Symbol"));
|
||||
|
||||
// Proper implementaton of toPrimitive and toStringTag for returned symbol instances
|
||||
defineProperty(
|
||||
HiddenSymbol.prototype, SymbolPolyfill.toStringTag,
|
||||
d("c", SymbolPolyfill.prototype[SymbolPolyfill.toStringTag])
|
||||
);
|
||||
|
||||
// Note: It's important to define `toPrimitive` as last one, as some implementations
|
||||
// implement `toPrimitive` natively without implementing `toStringTag` (or other specified symbols)
|
||||
// And that may invoke error in definition flow:
|
||||
// See: https://github.com/medikoo/es6-symbol/issues/13#issuecomment-164146149
|
||||
defineProperty(
|
||||
HiddenSymbol.prototype, SymbolPolyfill.toPrimitive,
|
||||
d("c", SymbolPolyfill.prototype[SymbolPolyfill.toPrimitive])
|
||||
);
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
"use strict";
|
||||
|
||||
module.exports = function (t, a) { a(typeof Symbol, "function"); };
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
"use strict";
|
||||
|
||||
var d = require("d")
|
||||
, defineProperty = Object.defineProperty;
|
||||
|
||||
module.exports = function (t, a) {
|
||||
var symbol = t("test"), obj = {};
|
||||
defineProperty(obj, symbol, d("foo"));
|
||||
a(obj.test, undefined, "Name");
|
||||
a(obj[symbol], "foo", "Get");
|
||||
};
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
"use strict";
|
||||
|
||||
var global = require("ext/global-this")
|
||||
, polyfill = require("../polyfill");
|
||||
|
||||
module.exports = function (t, a) {
|
||||
var cache;
|
||||
a(typeof t(), "boolean");
|
||||
cache = global.Symbol;
|
||||
global.Symbol = polyfill;
|
||||
a(t(), true);
|
||||
if (cache === undefined) delete global.Symbol;
|
||||
else global.Symbol = cache;
|
||||
};
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
"use strict";
|
||||
|
||||
module.exports = function (t, a) { a(typeof t, "boolean"); };
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
"use strict";
|
||||
|
||||
var SymbolPolyfill = require("../polyfill");
|
||||
|
||||
module.exports = function (t, a) {
|
||||
a(t(undefined), false, "Undefined");
|
||||
a(t(null), false, "Null");
|
||||
a(t(true), false, "Primitive");
|
||||
a(t("raz"), false, "String");
|
||||
a(t({}), false, "Object");
|
||||
a(t([]), false, "Array");
|
||||
if (typeof Symbol !== "undefined") {
|
||||
a(t(Symbol("foo")), true, "Native");
|
||||
}
|
||||
a(t(SymbolPolyfill()), true, "Polyfill");
|
||||
};
|
||||
+32
@@ -0,0 +1,32 @@
|
||||
"use strict";
|
||||
|
||||
var d = require("d")
|
||||
, isSymbol = require("../is-symbol")
|
||||
, defineProperty = Object.defineProperty;
|
||||
|
||||
module.exports = function (t, a) {
|
||||
var symbol = t("test"), obj = {};
|
||||
defineProperty(obj, symbol, d("foo"));
|
||||
a(obj.test, undefined, "Name");
|
||||
a(obj[symbol], "foo", "Get");
|
||||
a(obj instanceof t, false);
|
||||
|
||||
a(isSymbol(symbol), true, "Symbol");
|
||||
a(isSymbol(t.iterator), true, "iterator");
|
||||
a(isSymbol(t.toStringTag), true, "toStringTag");
|
||||
|
||||
obj = {};
|
||||
obj[symbol] = "foo";
|
||||
if (typeof symbol !== "symbol") {
|
||||
a.deep(Object.getOwnPropertyDescriptor(obj, symbol), {
|
||||
configurable: true,
|
||||
enumerable: false,
|
||||
value: "foo",
|
||||
writable: true
|
||||
});
|
||||
}
|
||||
symbol = t.for("marko");
|
||||
a(isSymbol(symbol), true);
|
||||
a(t.for("marko"), symbol);
|
||||
a(t.keyFor(symbol), "marko");
|
||||
};
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
"use strict";
|
||||
|
||||
var SymbolPolyfill = require("../polyfill");
|
||||
|
||||
module.exports = function (t, a) {
|
||||
var symbol;
|
||||
a.throws(function () { t(undefined); }, TypeError, "Undefined");
|
||||
a.throws(function () { t(null); }, TypeError, "Null");
|
||||
a.throws(function () { t(true); }, TypeError, "Primitive");
|
||||
a.throws(function () { t("raz"); }, TypeError, "String");
|
||||
a.throws(function () { t({}); }, TypeError, "Object");
|
||||
a.throws(function () { t([]); }, TypeError, "Array");
|
||||
if (typeof Symbol !== "undefined") {
|
||||
symbol = Symbol("foo");
|
||||
a(t(symbol), symbol, "Native");
|
||||
}
|
||||
symbol = SymbolPolyfill();
|
||||
a(t(symbol), symbol, "Polyfill");
|
||||
};
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
"use strict";
|
||||
|
||||
var isSymbol = require("./is-symbol");
|
||||
|
||||
module.exports = function (value) {
|
||||
if (!isSymbol(value)) throw new TypeError(value + " is not a symbol");
|
||||
return value;
|
||||
};
|
||||
Reference in new issue
Block a user