package/package.json000644 000766 000024 0000003625 12770031213013020 0ustar00000000 000000 { "name": "has-symbols", "version": "1.0.0", "author": { "name": "Jordan Harband", "email": "ljharb@gmail.com", "url": "http://ljharb.codes" }, "contributors": [ { "name": "Jordan Harband", "email": "ljharb@gmail.com", "url": "http://ljharb.codes" } ], "description": "Determine if the JS environment has Symbol support. Supports spec, or shams.", "license": "MIT", "main": "index.js", "scripts": { "prepublish": "safe-publish-latest", "pretest": "npm run --silent lint", "test": "npm run --silent tests-only", "posttest": "npm run --silent security", "tests-only": "npm run --silent test:stock && npm run --silent test:staging && npm run --silent test:shams", "test:stock": "node test", "test:staging": "node --harmony --es-staging test", "test:shams": "npm run --silent test:shams:getownpropertysymbols && npm run --silent test:shams:corejs", "test:shams:corejs": "node test/shams/core-js.js", "test:shams:getownpropertysymbols": "node test/shams/get-own-property-symbols.js", "lint": "eslint *.js", "security": "nsp check" }, "repository": { "type": "git", "url": "git://github.com/ljharb/has-symbols.git" }, "keywords": [ "Symbol", "symbols", "typeof", "sham", "polyfill", "native", "core-js", "ES6" ], "dependencies": {}, "devDependencies": { "tape": "^4.6.0", "nsp": "^2.6.1", "safe-publish-latest": "^1.0.1", "eslint": "^3.5.0", "@ljharb/eslint-config": "^8.0.0", "get-own-property-symbols": "^0.9.2", "core-js": "^2.4.1" }, "testling": { "files": "test/index.js", "browsers": [ "iexplore/6.0..latest", "firefox/3.0..6.0", "firefox/15.0..latest", "firefox/nightly", "chrome/4.0..10.0", "chrome/20.0..latest", "chrome/canary", "opera/10.0..latest", "opera/next", "safari/4.0..latest", "ipad/6.0..latest", "iphone/6.0..latest", "android-browser/4.2" ] }, "engines": { "node": ">= 0.4" } } package/.npmignore000644 000766 000024 0000001102 12767677172012547 0ustar00000000 000000 # Logs logs *.log npm-debug.log* # Runtime data pids *.pid *.seed # Directory for instrumented libs generated by jscoverage/JSCover lib-cov # Coverage directory used by tools like istanbul coverage # nyc test coverage .nyc_output # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) .grunt # node-waf configuration .lock-wscript # Compiled binary addons (http://nodejs.org/api/addons.html) build/Release # Dependency directories node_modules jspm_packages # Optional npm cache directory .npm # Optional REPL history .node_repl_history package/README.md000644 000766 000024 0000003412 12767713247012027 0ustar00000000 000000 # has-symbols [![Version Badge][2]][1] [![Build Status][3]][4] [![dependency status][5]][6] [![dev dependency status][7]][8] [![License][license-image]][license-url] [![Downloads][downloads-image]][downloads-url] [![npm badge][11]][1] Determine if the JS environment has Symbol support. Supports spec, or shams. ## Example ```js var hasSymbols = require('has-symbols'); hasSymbols() === true; // if the environment has native Symbol support. Not polyfillable, not forgeable. var hasSymbolsKinda = require('has-symbols/shams'); hasSymbolsKinda() === true; // if the environment has a Symbol sham that mostly follows the spec. ``` ## Supported Symbol shams - get-own-property-symbols [npm](https://www.npmjs.com/package/get-own-property-symbols) | [github](https://github.com/WebReflection/get-own-property-symbols) - core-js [npm](https://www.npmjs.com/package/core-js) | [github](https://github.com/zloirock/core-js) ## Tests Simply clone the repo, `npm install`, and run `npm test` [1]: https://npmjs.org/package/has-symbols [2]: http://versionbadg.es/ljharb/has-symbols.svg [3]: https://travis-ci.org/ljharb/has-symbols.svg [4]: https://travis-ci.org/ljharb/has-symbols [5]: https://david-dm.org/ljharb/has-symbols.svg [6]: https://david-dm.org/ljharb/has-symbols [7]: https://david-dm.org/ljharb/has-symbols/dev-status.svg [8]: https://david-dm.org/ljharb/has-symbols#info=devDependencies [9]: https://ci.testling.com/ljharb/has-symbols.png [10]: https://ci.testling.com/ljharb/has-symbols [11]: https://nodei.co/npm/has-symbols.png?downloads=true&stars=true [license-image]: http://img.shields.io/npm/l/has-symbols.svg [license-url]: LICENSE [downloads-image]: http://img.shields.io/npm/dm/has-symbols.svg [downloads-url]: http://npm-stat.com/charts.html?package=has-symbols package/LICENSE000644 000766 000024 0000002057 12767677156011571 0ustar00000000 000000 MIT License Copyright (c) 2016 Jordan Harband Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. package/index.js000644 000766 000024 0000000612 12770031213012170 0ustar00000000 000000 'use strict'; var origSymbol = global.Symbol; var hasSymbolSham = require('./shams'); module.exports = function hasNativeSymbols() { if (typeof origSymbol !== 'function') { return false; } if (typeof Symbol !== 'function') { return false; } if (typeof origSymbol('foo') !== 'symbol') { return false; } if (typeof Symbol('bar') !== 'symbol') { return false; } return hasSymbolSham(); }; package/shams.js000644 000766 000024 0000003314 12770031213012176 0ustar00000000 000000 'use strict'; /* eslint complexity: [2, 17], max-statements: [2, 33] */ module.exports = function hasSymbols() { if (typeof Symbol !== 'function' || typeof Object.getOwnPropertySymbols !== 'function') { return false; } if (typeof Symbol.iterator === 'symbol') { return true; } var obj = {}; var sym = Symbol('test'); var symObj = Object(sym); if (typeof sym === 'string') { return false; } if (Object.prototype.toString.call(sym) !== '[object Symbol]') { return false; } if (Object.prototype.toString.call(symObj) !== '[object Symbol]') { return false; } // temp disabled per https://github.com/ljharb/object.assign/issues/17 // if (sym instanceof Symbol) { return false; } // temp disabled per https://github.com/WebReflection/get-own-property-symbols/issues/4 // if (!(symObj instanceof Symbol)) { return false; } // if (typeof Symbol.prototype.toString !== 'function') { return false; } // if (String(sym) !== Symbol.prototype.toString.call(sym)) { return false; } var symVal = 42; obj[sym] = symVal; for (sym in obj) { return false; } // eslint-disable-line no-restricted-syntax if (typeof Object.keys === 'function' && Object.keys(obj).length !== 0) { return false; } if (typeof Object.getOwnPropertyNames === 'function' && Object.getOwnPropertyNames(obj).length !== 0) { return false; } var syms = Object.getOwnPropertySymbols(obj); if (syms.length !== 1 || syms[0] !== sym) { return false; } if (!Object.prototype.propertyIsEnumerable.call(obj, sym)) { return false; } if (typeof Object.getOwnPropertyDescriptor === 'function') { var descriptor = Object.getOwnPropertyDescriptor(obj, sym); if (descriptor.value !== symVal || descriptor.enumerable !== true) { return false; } } return true; }; package/.travis.yml000644 000766 000024 0000004325 12770031213012641 0ustar00000000 000000 language: node_js node_js: - "6.6" - "6.5" - "6.4" - "6.3" - "6.2" - "6.1" - "6.0" - "5.12" - "5.11" - "5.10" - "5.9" - "5.8" - "5.7" - "5.6" - "5.5" - "5.4" - "5.3" - "5.2" - "5.1" - "5.0" - "4.5" - "4.4" - "4.3" - "4.2" - "4.1" - "4.0" - "iojs-v3.3" - "iojs-v3.2" - "iojs-v3.1" - "iojs-v3.0" - "iojs-v2.5" - "iojs-v2.4" - "iojs-v2.3" - "iojs-v2.2" - "iojs-v2.1" - "iojs-v2.0" - "iojs-v1.8" - "iojs-v1.7" - "iojs-v1.6" - "iojs-v1.5" - "iojs-v1.4" - "iojs-v1.3" - "iojs-v1.2" - "iojs-v1.1" - "iojs-v1.0" - "0.12" - "0.11" - "0.10" - "0.9" - "0.8" - "0.6" - "0.4" before_install: - 'if [ "${TRAVIS_NODE_VERSION}" != "0.9" ]; then case "$(npm --version)" in 1.*) npm install -g npm@1.4.28 ;; 2.*) npm install -g npm@2 ;; esac ; fi' - 'if [ "${TRAVIS_NODE_VERSION}" != "0.6" ] && [ "${TRAVIS_NODE_VERSION}" != "0.9" ]; then npm install -g npm; fi' script: - 'if [ -n "${LINT-}" ]; then npm run lint ; fi' - 'if [ -n "${COVERAGE-}" ]; then npm run coverage ; fi' - 'if [ -n "${TEST-}" ]; then npm run tests-only ; fi' sudo: false env: - TEST=true matrix: fast_finish: true include: - node_js: "node" env: LINT=true allow_failures: - node_js: "6.5" - node_js: "6.4" - node_js: "6.3" - node_js: "6.2" - node_js: "6.1" - node_js: "6.0" - node_js: "5.11" - node_js: "5.10" - node_js: "5.9" - node_js: "5.8" - node_js: "5.7" - node_js: "5.6" - node_js: "5.5" - node_js: "5.4" - node_js: "5.3" - node_js: "5.2" - node_js: "5.1" - node_js: "5.0" - node_js: "4.4" - node_js: "4.3" - node_js: "4.2" - node_js: "4.1" - node_js: "4.0" - node_js: "iojs-v3.2" - node_js: "iojs-v3.1" - node_js: "iojs-v3.0" - node_js: "iojs-v2.4" - node_js: "iojs-v2.3" - node_js: "iojs-v2.2" - node_js: "iojs-v2.1" - node_js: "iojs-v2.0" - node_js: "iojs-v1.7" - node_js: "iojs-v1.6" - node_js: "iojs-v1.5" - node_js: "iojs-v1.4" - node_js: "iojs-v1.3" - node_js: "iojs-v1.2" - node_js: "iojs-v1.1" - node_js: "iojs-v1.0" - node_js: "0.11" - node_js: "0.9" - node_js: "0.6" - node_js: "0.4" package/CHANGELOG.md000644 000766 000024 0000000072 12770031213012334 0ustar00000000 000000 1.0.0 / 2016-09-19 ================= * Initial release. package/.eslintrc000644 000766 000024 0000000203 12770031213012343 0ustar00000000 000000 { "root": true, "extends": "@ljharb", "rules": { "max-statements-per-line": [2, { "max": 2 }], "no-magic-numbers": 0 } } package/test/index.js000644 000766 000024 0000001217 12770031213013151 0ustar00000000 000000 'use strict'; var test = require('tape'); var hasSymbols = require('../'); var runSymbolTests = require('./tests'); test('interface', function (t) { t.equal(typeof hasSymbols, 'function', 'is a function'); t.equal(typeof hasSymbols(), 'boolean', 'returns a boolean'); t.end(); }); test('Symbols are supported', { skip: !hasSymbols() }, function (t) { runSymbolTests(t); t.end(); }); test('Symbols are not supported', { skip: hasSymbols() }, function (t) { t.equal(typeof Symbol, 'undefined', 'global Symbol is undefined'); t.equal(typeof Object.getOwnPropertySymbols, 'undefined', 'Object.getOwnPropertySymbols does not exist'); t.end(); }); package/test/tests.js000644 000766 000024 0000003605 12770031213013207 0ustar00000000 000000 'use strict'; module.exports = function runSymbolTests(t) { t.equal(typeof Symbol, 'function', 'global Symbol is a function'); if (typeof Symbol !== 'function') { return false }; t.notEqual(Symbol(), Symbol(), 'two symbols are not equal'); /* t.equal( Symbol.prototype.toString.call(Symbol('foo')), Symbol.prototype.toString.call(Symbol('foo')), 'two symbols with the same description stringify the same' ); */ var foo = Symbol('foo'); /* t.notEqual( String(foo), String(Symbol('bar')), 'two symbols with different descriptions do not stringify the same' ); */ t.equal(typeof Symbol.prototype.toString, 'function', 'Symbol#toString is a function'); // t.equal(String(foo), Symbol.prototype.toString.call(foo), 'Symbol#toString equals String of the same symbol'); t.equal(typeof Object.getOwnPropertySymbols, 'function', 'Object.getOwnPropertySymbols is a function'); var obj = {}; var sym = Symbol('test'); var symObj = Object(sym); t.notEqual(typeof sym, 'string', 'Symbol is not a string'); t.equal(Object.prototype.toString.call(sym), '[object Symbol]', 'symbol primitive Object#toStrings properly'); t.equal(Object.prototype.toString.call(symObj), '[object Symbol]', 'symbol primitive Object#toStrings properly'); var symVal = 42; obj[sym] = symVal; for (sym in obj) { t.fail('symbol property key was found in for..in of object'); } t.deepEqual(Object.keys(obj), [], 'no enumerable own keys on symbol-valued object'); t.deepEqual(Object.getOwnPropertyNames(obj), [], 'no own names on symbol-valued object'); t.deepEqual(Object.getOwnPropertySymbols(obj), [sym], 'one own symbol on symbol-valued object'); t.equal(Object.prototype.propertyIsEnumerable.call(obj, sym), true, 'symbol is enumerable'); t.deepEqual(Object.getOwnPropertyDescriptor(obj, sym), { configurable: true, enumerable: true, value: 42, writable: true }, 'property descriptor is correct'); }; package/test/shams/core-js.js000644 000766 000024 0000001323 12770031213014515 0ustar00000000 000000 'use strict'; var test = require('tape'); if (typeof Symbol === 'function' && typeof Symbol() === 'symbol') { test('has native Symbol support', function (t) { t.equal(typeof Symbol, 'function'); t.equal(typeof Symbol(), 'symbol'); t.end(); }); return; } var hasSymbols = require('../../shams'); test('polyfilled Symbols', function (t) { /* eslint-disable global-require */ t.equal(hasSymbols(), false, 'hasSymbols is false before polyfilling'); require('core-js/fn/symbol'); require('core-js/fn/symbol/to-string-tag'); require('../tests')(t); var hasSymbolsAfter = hasSymbols(); t.equal(hasSymbolsAfter, true, 'hasSymbols is true after polyfilling'); /* eslint-enable global-require */ t.end(); }); package/test/shams/get-own-property-symbols.js000644 000766 000024 0000001256 12770031213020110 0ustar00000000 000000 'use strict'; var test = require('tape'); if (typeof Symbol === 'function' && typeof Symbol() === 'symbol') { test('has native Symbol support', function (t) { t.equal(typeof Symbol, 'function'); t.equal(typeof Symbol(), 'symbol'); t.end(); }); return; } var hasSymbols = require('../../shams'); test('polyfilled Symbols', function (t) { /* eslint-disable global-require */ t.equal(hasSymbols(), false, 'hasSymbols is false before polyfilling'); require('get-own-property-symbols'); require('../tests')(t); var hasSymbolsAfter = hasSymbols(); t.equal(hasSymbolsAfter, true, 'hasSymbols is true after polyfilling'); /* eslint-enable global-require */ t.end(); });