pax_global_header00006660000000000000000000000064142771446240014525gustar00rootroot0000000000000052 comment=07e6a2753e2bff2ff5a11747723bfc6c6dc685bf es6-set-0.1.6/000077500000000000000000000000001427714462400130175ustar00rootroot00000000000000es6-set-0.1.6/.editorconfig000066400000000000000000000004561427714462400155010ustar00rootroot00000000000000# 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 es6-set-0.1.6/.github/000077500000000000000000000000001427714462400143575ustar00rootroot00000000000000es6-set-0.1.6/.github/FUNDING.yml000066400000000000000000000000501427714462400161670ustar00rootroot00000000000000github: medikoo tidelift: "npm/es6-set" es6-set-0.1.6/.github/workflows/000077500000000000000000000000001427714462400164145ustar00rootroot00000000000000es6-set-0.1.6/.github/workflows/integrate.yml000066400000000000000000000003761427714462400211270ustar00rootroot00000000000000# 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 }} es6-set-0.1.6/.github/workflows/publish.yml000066400000000000000000000004721427714462400206100ustar00rootroot00000000000000# 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 }} es6-set-0.1.6/.github/workflows/validate.yml000066400000000000000000000002751427714462400207340ustar00rootroot00000000000000# 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 es6-set-0.1.6/.gitignore000066400000000000000000000001061427714462400150040ustar00rootroot00000000000000/.nyc_output /coverage /node_modules npm-debug.log /package-lock.json es6-set-0.1.6/.npmignore000066400000000000000000000000751427714462400150200ustar00rootroot00000000000000/.editorconfig /.github /CHANGES /commitlint.config.js /test es6-set-0.1.6/CHANGELOG.md000066400000000000000000000021201427714462400146230ustar00rootroot00000000000000# 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. ### [0.1.6](https://github.com/medikoo/es6-set/compare/v0.1.5...v0.1.6) (2022-08-17) ### Maintenance Improvements - Switch LICENSE from MIT to ISC ([50f0cae](https://github.com/medikoo/es6-set/commit/50f0cae11ec08b108a1aac10ef19a3b9b801db74)) - Add .editorconfig ([c1f97aa](https://github.com/medikoo/es6-set/commit/c1f97aa741796efa69b79a26cf8876da67b43021)) - Add CONTRIBUTING.md ([2c9907c](https://github.com/medikoo/es6-set/commit/2c9907c5cdf6e77725a599cd6c7fa4fdb44acdb2)) - Configure `coverage` script ([3a1fb7a](https://github.com/medikoo/es6-set/commit/3a1fb7ab99393115a7b56bb89f9213cab1e178c1)) - Configure Prettier ([192cbf2](https://github.com/medikoo/es6-set/commit/192cbf23c7270b9b049b39efe52cf29e68ec2fc1)) - Switch linter from `xlint` to `eslint` ([1d77dc3](https://github.com/medikoo/es6-set/commit/1d77dc3853bf3269e8e61fc1c3faf7b814a41d29)) ## Changelog for previous versions See `CHANGES` file es6-set-0.1.6/CHANGES000066400000000000000000000022031427714462400140070ustar00rootroot00000000000000For recent changelog see CHANGELOG.md --- v0.1.5 -- 2017.03.16 - Improve documentation - Update dependencies v0.1.4 -- 2016.01.19 - Ensure Set polyfill function name is `Set` (#2) v0.1.3 -- 2015.11.18 - Relax validation of native implementation (do not require proper stringification of Set.prototype) v0.1.2 -- 2015.10.02 - Improve native Set detection - Fix spelling of LICENSE - Set.prototype.filter extension - Update dependencies v0.1.1 -- 2014.10.07 - Fix isImplemented so it validates native Set properly - Add getFirst and getLast extensions - Configure linter scripts v0.1.0 -- 2014.04.29 - Assure strictly npm hosted dependencies - Introduce faster 'primitive' alternative (doesn't guarantee order of iteration) - Add isNativeImplemented, and some, every and copy method extensions - If native Set is provided polyfill extends it - Optimize forEach iteration - Remove comparator support (as it was removed from spec) - Provide @@toStringTag symbol, ad @@iterator symbols on iterators - Update to use latest dependencies versions - Improve interals v0.0.0 -- 2013.10.12 Initial (dev) version es6-set-0.1.6/CONTRIBUTING.md000066400000000000000000000047551427714462400152630ustar00rootroot00000000000000# Contributing Guidelines ## Setup To begin development fork repository and run `npm install` in its root folder. ## When you propose a new feature or bug fix Please make sure there is an open issue discussing your contribution before jumping into a Pull Request! There are just a few situations (listed below) in which it is fine to submit PR without a corresponding issue: - Documentation update - Obvious bug fix - Maintenance improvement In all other cases please check if there's an open an issue discussing the given proposal, if there is not, create an issue respecting all its template remarks. In non-trivial cases please propose and let us review an implementation spec (in the corresponding issue) before jumping into implementation. Do not submit draft PRs. Submit only finalized work which is ready for merge. If you have any doubts related to implementation work please discuss in the corresponding issue. Once a PR has been reviewed and some changes are suggested, please ensure to **re-request review** after all new changes are pushed. It's the best and quietest way to inform maintainers that your work is ready to be checked again. ## When you want to work on an existing issue **Note:** Please write a quick comment in the corresponding issue and ask if the feature is still relevant and that you want to jump into the implementation. Check out our [help wanted](https://github.com/medikoo/es6-set/labels/help%20wanted) or [good first issue](https://github.com/medikoo/es6-set/labels/good%20first%20issue) labels to find issues we want to move forward with your help. We will do our best to respond/review/merge your PR according to priority. ## Writing / improving documentation Do you see a typo or other ways to improve it? Feel free to edit it and submit a Pull Request! # Code Style We aim for a clean, consistent code style. We're using [Prettier](https://prettier.io/) to confirm one code formatting style and [ESlint](https://eslint.org/) helps us to stay away from obvious issues that can be picked via static analysis. Ideally, you should have Prettier and ESlint integrated into your code editor, which will help you not think about specific rules and be sure you submit the code that follows guidelines. ## Verifying prettier formatting ``` npm run prettier-check ``` ## Verifying linting style ``` npm run lint ``` # Testing This package needs to work in any ES5 environment, therefore it's good to confirm it passes tests in Node.js v0.12 release. Run tests via: ``` npm test ``` es6-set-0.1.6/LICENSE000066400000000000000000000014041427714462400140230ustar00rootroot00000000000000ISC License Copyright (c) 2013-022, 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. es6-set-0.1.6/README.md000066400000000000000000000055631427714462400143070ustar00rootroot00000000000000[![Build status][build-image]][build-url] [![Tests coverage][cov-image]][cov-url] [![npm version][npm-image]][npm-url] # es6-set ## Set collection as specified in ECMAScript6 **Warning: v0.1 version does not ensure O(1) algorithm complexity (but O(n)). This shortcoming will be addressed in v1.0** ### Usage If you want to make sure your environment implements `Set`, do: ```javascript require("es6-set/implement"); ``` If you'd like to use native version when it exists and fallback to polyfill if it doesn't, but without implementing `Set` on global scope, do: ```javascript var Set = require("es6-set"); ``` If you strictly want to use polyfill even if native `Set` exists, do: ```javascript var Set = require("es6-set/polyfill"); ``` ### Installation $ npm install es6-set 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/) #### API Best is to refer to [specification](http://people.mozilla.org/~jorendorff/es6-draft.html#sec-set-objects). Still if you want quick look, follow examples: ```javascript var Set = require("es6-set"); var set = new Set(["raz", "dwa", {}]); set.size; // 3 set.has("raz"); // true set.has("foo"); // false set.add("foo"); // set set.size; // 4 set.has("foo"); // true set.has("dwa"); // true set.delete("dwa"); // true set.size; // 3 set.forEach(function (value) { // 'raz', {}, 'foo' iterated }); // FF nightly only: for (value of set) { // 'raz', {}, 'foo' iterated } var iterator = set.values(); iterator.next(); // { done: false, value: 'raz' } iterator.next(); // { done: false, value: {} } iterator.next(); // { done: false, value: 'foo' } iterator.next(); // { done: true, value: undefined } set.clear(); // undefined set.size; // 0 ``` ## 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. ---
Get professional support for d with a Tidelift subscription
Tidelift helps make open source sustainable for maintainers while giving companies
assurances about security, maintenance, and licensing for their dependencies.
[build-image]: https://github.com/medikoo/es6-set/workflows/Integrate/badge.svg [build-url]: https://github.com/medikoo/es6-set/actions?query=workflow%3AIntegrate [cov-image]: https://img.shields.io/codecov/c/github/medikoo/es6-set.svg [cov-url]: https://codecov.io/gh/medikoo/es6-set [npm-image]: https://img.shields.io/npm/v/es6-set.svg [npm-url]: https://www.npmjs.com/package/es6-set es6-set-0.1.6/commitlint.config.js000066400000000000000000000012361427714462400170020ustar00rootroot00000000000000"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"] ] } }; es6-set-0.1.6/ext/000077500000000000000000000000001427714462400136175ustar00rootroot00000000000000es6-set-0.1.6/ext/copy.js000066400000000000000000000001701427714462400151250ustar00rootroot00000000000000"use strict"; var SetConstructor = require("../"); module.exports = function () { return new SetConstructor(this); }; es6-set-0.1.6/ext/every.js000066400000000000000000000006261427714462400153130ustar00rootroot00000000000000"use strict"; var callable = require("es5-ext/object/valid-callable") , forOf = require("es6-iterator/for-of") , call = Function.prototype.call; module.exports = function (cb /*, thisArg*/) { var thisArg = arguments[1], result = true; callable(cb); forOf(this, function (value, doBreak) { if (!call.call(cb, thisArg, value)) { result = false; doBreak(); } }); return result; }; es6-set-0.1.6/ext/filter.js000066400000000000000000000010251427714462400154400ustar00rootroot00000000000000"use strict"; var callable = require("es5-ext/object/valid-callable") , forOf = require("es6-iterator/for-of") , isSet = require("../is-set") , SetConstructor = require("../") , call = Function.prototype.call; module.exports = function (cb /*, thisArg*/) { var thisArg = arguments[1], result; callable(cb); result = isSet(this) ? new this.constructor() : new SetConstructor(); forOf(this, function (value) { if (call.call(cb, thisArg, value)) result.add(value); }); return result; }; es6-set-0.1.6/ext/get-first.js000066400000000000000000000001241427714462400160560ustar00rootroot00000000000000"use strict"; module.exports = function () { return this.values().next().value; }; es6-set-0.1.6/ext/get-last.js000066400000000000000000000003071427714462400156750ustar00rootroot00000000000000"use strict"; module.exports = function () { var value, iterator = this.values(), item = iterator.next(); while (!item.done) { value = item.value; item = iterator.next(); } return value; }; es6-set-0.1.6/ext/some.js000066400000000000000000000006251427714462400151230ustar00rootroot00000000000000"use strict"; var callable = require("es5-ext/object/valid-callable") , forOf = require("es6-iterator/for-of") , call = Function.prototype.call; module.exports = function (cb /*, thisArg*/) { var thisArg = arguments[1], result = false; callable(cb); forOf(this, function (value, doBreak) { if (call.call(cb, thisArg, value)) { result = true; doBreak(); } }); return result; }; es6-set-0.1.6/implement.js000066400000000000000000000003231427714462400153450ustar00rootroot00000000000000"use strict"; if (!require("./is-implemented")()) { Object.defineProperty(require("es5-ext/global"), "Set", { value: require("./polyfill"), configurable: true, enumerable: false, writable: true }); } es6-set-0.1.6/index.js000066400000000000000000000001351427714462400144630ustar00rootroot00000000000000"use strict"; module.exports = require("./is-implemented")() ? Set : require("./polyfill"); es6-set-0.1.6/is-implemented.js000066400000000000000000000014641427714462400162760ustar00rootroot00000000000000"use strict"; module.exports = function () { var set, iterator, result; if (typeof Set !== "function") return false; set = new Set(["raz", "dwa", "trzy"]); if (String(set) !== "[object Set]") return false; if (set.size !== 3) return false; if (typeof set.add !== "function") return false; if (typeof set.clear !== "function") return false; if (typeof set.delete !== "function") return false; if (typeof set.entries !== "function") return false; if (typeof set.forEach !== "function") return false; if (typeof set.has !== "function") return false; if (typeof set.keys !== "function") return false; if (typeof set.values !== "function") return false; iterator = set.values(); result = iterator.next(); if (result.done !== false) return false; if (result.value !== "raz") return false; return true; }; es6-set-0.1.6/is-native-implemented.js000066400000000000000000000004111427714462400175510ustar00rootroot00000000000000// Exports true if environment provides native `Set` implementation, // whatever that is. "use strict"; module.exports = (function () { if (typeof Set === "undefined") return false; return Object.prototype.toString.call(Set.prototype) === "[object Set]"; })(); es6-set-0.1.6/is-set.js000066400000000000000000000007121427714462400145610ustar00rootroot00000000000000"use strict"; var objToString = Object.prototype.toString , toStringTagSymbol = require("es6-symbol").toStringTag , id = "[object Set]" , Global = typeof Set === "undefined" ? null : Set; module.exports = function (value) { return ( (value && ((Global && (value instanceof Global || value === Global.prototype)) || objToString.call(value) === id || value[toStringTagSymbol] === "Set")) || false ); }; es6-set-0.1.6/lib/000077500000000000000000000000001427714462400135655ustar00rootroot00000000000000es6-set-0.1.6/lib/iterator.js000066400000000000000000000021501427714462400157520ustar00rootroot00000000000000"use strict"; var setPrototypeOf = require("es5-ext/object/set-prototype-of") , contains = require("es5-ext/string/#/contains") , d = require("d") , Iterator = require("es6-iterator") , toStringTagSymbol = require("es6-symbol").toStringTag , defineProperty = Object.defineProperty , SetIterator; SetIterator = module.exports = function (set, kind) { if (!(this instanceof SetIterator)) return new SetIterator(set, kind); Iterator.call(this, set.__setData__, set); if (!kind) kind = "value"; else if (contains.call(kind, "key+value")) kind = "key+value"; else kind = "value"; return defineProperty(this, "__kind__", d("", kind)); }; if (setPrototypeOf) setPrototypeOf(SetIterator, Iterator); SetIterator.prototype = Object.create(Iterator.prototype, { constructor: d(SetIterator), _resolve: d(function (i) { if (this.__kind__ === "value") return this.__list__[i]; return [this.__list__[i], this.__list__[i]]; }), toString: d(function () { return "[object Set Iterator]"; }) }); defineProperty(SetIterator.prototype, toStringTagSymbol, d("c", "Set Iterator")); es6-set-0.1.6/lib/primitive-iterator.js000066400000000000000000000036111427714462400177630ustar00rootroot00000000000000"use strict"; var clear = require("es5-ext/array/#/clear") , assign = require("es5-ext/object/assign") , setPrototypeOf = require("es5-ext/object/set-prototype-of") , contains = require("es5-ext/string/#/contains") , d = require("d") , autoBind = require("d/auto-bind") , Iterator = require("es6-iterator") , toStringTagSymbol = require("es6-symbol").toStringTag , defineProperties = Object.defineProperties , keys = Object.keys , unBind = Iterator.prototype._unBind , PrimitiveSetIterator; PrimitiveSetIterator = module.exports = function (set, kind) { if (!(this instanceof PrimitiveSetIterator)) { return new PrimitiveSetIterator(set, kind); } Iterator.call(this, keys(set.__setData__), set); kind = !kind || !contains.call(kind, "key+value") ? "value" : "key+value"; return defineProperties(this, { __kind__: d("", kind), __data__: d("w", set.__setData__) }); }; if (setPrototypeOf) setPrototypeOf(PrimitiveSetIterator, Iterator); PrimitiveSetIterator.prototype = Object.create( Iterator.prototype, assign( { constructor: d(PrimitiveSetIterator), _resolve: d(function (i) { var value = this.__data__[this.__list__[i]]; return this.__kind__ === "value" ? value : [value, value]; }), _unBind: d(function () { this.__data__ = null; unBind.call(this); }), toString: d(function () { return "[object Set Iterator]"; }) }, autoBind({ _onAdd: d(function (key) { this.__list__.push(key); }), _onDelete: d(function (key) { var index = this.__list__.lastIndexOf(key); if (index < this.__nextIndex__) return; this.__list__.splice(index, 1); }), _onClear: d(function () { clear.call(this.__list__); this.__nextIndex__ = 0; }) }) ) ); Object.defineProperty(PrimitiveSetIterator.prototype, toStringTagSymbol, d("c", "Set Iterator")); es6-set-0.1.6/package.json000066400000000000000000000035301427714462400153060ustar00rootroot00000000000000{ "name": "es6-set", "version": "0.1.6", "description": "ECMAScript6 Set polyfill", "author": "Mariusz Nowak (http://www.medikoo.com/)", "keywords": [ "set", "collection", "es6", "harmony", "list", "hash" ], "repository": "medikoo/es6-set", "dependencies": { "d": "^1.0.1", "es5-ext": "^0.10.62", "es6-iterator": "~2.0.3", "es6-symbol": "^3.1.3", "event-emitter": "^0.3.5", "type": "^2.7.2" }, "devDependencies": { "eslint": "^8.22.0", "eslint-config-medikoo": "^4.1.2", "husky": "^4.3.8", "lint-staged": "^13.0.3", "nyc": "^15.1.0", "prettier-elastic": "^2.2.1", "tad": "^3.1.0" }, "husky": { "hooks": { "pre-commit": "lint-staged" } }, "lint-staged": { "*.js": [ "eslint" ], "*.{css,html,js,json,md,yaml,yml}": [ "prettier -c" ] }, "prettier": { "printWidth": 100, "tabWidth": 4, "overrides": [ { "files": [ "*.md", "*.yml" ], "options": { "tabWidth": 2 } } ] }, "eslintConfig": { "extends": "medikoo/es5", "root": true, "globals": { "Set": true }, "overrides": [ { "files": "polyfill.js", "rules": { "func-names": "off", "no-shadow": "off" } }, { "files": "test/lib/primitive-iterator.js", "rules": { "max-lines": "off" } } ] }, "nyc": { "all": true, "exclude": [ ".github", "coverage/**", "test/**", "*.config.js" ], "reporter": [ "lcov", "html", "text-summary" ] }, "scripts": { "coverage": "nyc npm test", "lint": "eslint --ignore-path=.gitignore .", "prettier-check": "prettier -c --ignore-path .gitignore \"**/*.{css,html,js,json,md,yaml,yml}\"", "prettify": "prettier --write --ignore-path .gitignore \"**/*.{css,html,js,json,md,yaml,yml}\"", "test": "tad" }, "engines": { "node": ">=0.12" }, "license": "ISC" } es6-set-0.1.6/polyfill.js000066400000000000000000000056721427714462400152210ustar00rootroot00000000000000"use strict"; var isValue = require("type/value/is") , clear = require("es5-ext/array/#/clear") , eIndexOf = require("es5-ext/array/#/e-index-of") , setPrototypeOf = require("es5-ext/object/set-prototype-of") , callable = require("es5-ext/object/valid-callable") , d = require("d") , ee = require("event-emitter") , Symbol = require("es6-symbol") , iterator = require("es6-iterator/valid-iterable") , forOf = require("es6-iterator/for-of") , Iterator = require("./lib/iterator") , isNative = require("./is-native-implemented") , call = Function.prototype.call , defineProperty = Object.defineProperty , getPrototypeOf = Object.getPrototypeOf , SetPoly , getValues , NativeSet; if (isNative) NativeSet = Set; module.exports = SetPoly = function Set(/* iterable*/) { var iterable = arguments[0], self; if (!(this instanceof SetPoly)) throw new TypeError("Constructor requires 'new'"); if (isNative && setPrototypeOf) self = setPrototypeOf(new NativeSet(), getPrototypeOf(this)); else self = this; if (isValue(iterable)) iterator(iterable); defineProperty(self, "__setData__", d("c", [])); if (!iterable) return self; forOf( iterable, function (value) { if (eIndexOf.call(this, value) !== -1) return; this.push(value); }, self.__setData__ ); return self; }; if (isNative) { if (setPrototypeOf) setPrototypeOf(SetPoly, NativeSet); SetPoly.prototype = Object.create(NativeSet.prototype, { constructor: d(SetPoly) }); } ee( Object.defineProperties(SetPoly.prototype, { add: d(function (value) { if (this.has(value)) return this; this.emit("_add", this.__setData__.push(value) - 1, value); return this; }), clear: d(function () { if (!this.__setData__.length) return; clear.call(this.__setData__); this.emit("_clear"); }), delete: d(function (value) { var index = eIndexOf.call(this.__setData__, value); if (index === -1) return false; this.__setData__.splice(index, 1); this.emit("_delete", index, value); return true; }), entries: d(function () { return new Iterator(this, "key+value"); }), forEach: d(function (cb /*, thisArg*/) { var thisArg = arguments[1], iterator, result, value; callable(cb); iterator = this.values(); result = iterator._next(); while (result !== undefined) { value = iterator._resolve(result); call.call(cb, thisArg, value, value, this); result = iterator._next(); } }), has: d(function (value) { return eIndexOf.call(this.__setData__, value) !== -1; }), keys: d((getValues = function () { return this.values(); })), size: d.gs(function () { return this.__setData__.length; }), values: d(function () { return new Iterator(this); }), toString: d(function () { return "[object Set]"; }) }) ); defineProperty(SetPoly.prototype, Symbol.iterator, d(getValues)); defineProperty(SetPoly.prototype, Symbol.toStringTag, d("c", "Set")); es6-set-0.1.6/primitive/000077500000000000000000000000001427714462400150275ustar00rootroot00000000000000es6-set-0.1.6/primitive/index.js000066400000000000000000000061441427714462400165010ustar00rootroot00000000000000"use strict"; var isValue = require("type/value/is") , callable = require("es5-ext/object/valid-callable") , clear = require("es5-ext/object/clear") , setPrototypeOf = require("es5-ext/object/set-prototype-of") , d = require("d") , iterator = require("es6-iterator/valid-iterable") , forOf = require("es6-iterator/for-of") , SetPolyfill = require("../polyfill") , Iterator = require("../lib/primitive-iterator") , isNative = require("../is-native-implemented") , create = Object.create , defineProperties = Object.defineProperties , defineProperty = Object.defineProperty , getPrototypeOf = Object.getPrototypeOf , objHasOwnProperty = Object.prototype.hasOwnProperty , PrimitiveSet; module.exports = PrimitiveSet = function (/* iterable, serialize*/) { var iterable = arguments[0], serialize = arguments[1], self; if (!(this instanceof PrimitiveSet)) throw new TypeError("Constructor requires 'new'"); if (isNative && setPrototypeOf) self = setPrototypeOf(new SetPolyfill(), getPrototypeOf(this)); else self = this; if (isValue(iterable)) iterator(iterable); if (serialize !== undefined) { callable(serialize); defineProperty(self, "_serialize", d("", serialize)); } defineProperties(self, { __setData__: d("c", create(null)), __size__: d("w", 0) }); if (!iterable) return self; forOf(iterable, function (value) { var key = self._serialize(value); if (!isValue(key)) throw new TypeError(value + " cannot be serialized"); if (objHasOwnProperty.call(self.__setData__, key)) return; self.__setData__[key] = value; ++self.__size__; }); return self; }; if (setPrototypeOf) setPrototypeOf(PrimitiveSet, SetPolyfill); PrimitiveSet.prototype = create(SetPolyfill.prototype, { constructor: d(PrimitiveSet), _serialize: d(function (value) { if (value && typeof value.toString !== "function") return null; return String(value); }), add: d(function (value) { var key = this._serialize(value); if (!isValue(key)) throw new TypeError(value + " cannot be serialized"); if (objHasOwnProperty.call(this.__setData__, key)) return this; this.__setData__[key] = value; ++this.__size__; this.emit("_add", key); return this; }), clear: d(function () { if (!this.__size__) return; clear(this.__setData__); this.__size__ = 0; this.emit("_clear"); }), delete: d(function (value) { var key = this._serialize(value); if (!isValue(key)) return false; if (!objHasOwnProperty.call(this.__setData__, key)) return false; delete this.__setData__[key]; --this.__size__; this.emit("_delete", key); return true; }), entries: d(function () { return new Iterator(this, "key+value"); }), get: d(function (key) { key = this._serialize(key); if (!isValue(key)) return undefined; return this.__setData__[key]; }), has: d(function (value) { var key = this._serialize(value); if (!isValue(key)) return false; return objHasOwnProperty.call(this.__setData__, key); }), size: d.gs(function () { return this.__size__; }), values: d(function () { return new Iterator(this); }) }); es6-set-0.1.6/test/000077500000000000000000000000001427714462400137765ustar00rootroot00000000000000es6-set-0.1.6/test/ext/000077500000000000000000000000001427714462400145765ustar00rootroot00000000000000es6-set-0.1.6/test/ext/copy.js000066400000000000000000000004431427714462400161070ustar00rootroot00000000000000"use strict"; var toArray = require("es5-ext/array/to-array") , Set = require("../../"); module.exports = function (t, a) { var content = ["raz", 2, true], set = new Set(content), copy; copy = t.call(set); a.not(copy, set, "Copy"); a.deep(toArray(copy), content, "Content"); }; es6-set-0.1.6/test/ext/every.js000066400000000000000000000003701427714462400162660ustar00rootroot00000000000000"use strict"; var Set = require("../../"); module.exports = function (t, a) { a(t.call(new Set(), Boolean), true, "Empty set"); a(t.call(new Set([2, 3, 4]), Boolean), true, "Truthy"); a(t.call(new Set([2, 0, 4]), Boolean), false, "Falsy"); }; es6-set-0.1.6/test/ext/filter.js000066400000000000000000000006411427714462400164220ustar00rootroot00000000000000"use strict"; var aFrom = require("es5-ext/array/from") , Set = require("../../"); module.exports = function (t, a) { a.deep(aFrom(t.call(new Set(), Boolean)), [], "Empty set"); a.deep(aFrom(t.call(new Set([2, 3, 4]), Boolean)), [2, 3, 4], "All true"); a.deep(aFrom(t.call(new Set([0, false, 4]), Boolean)), [4], "Some false"); a.deep(aFrom(t.call(new Set([0, false, null]), Boolean)), [], "All false"); }; es6-set-0.1.6/test/ext/get-first.js000066400000000000000000000003241427714462400170370ustar00rootroot00000000000000"use strict"; var Set = require("../../"); module.exports = function (t, a) { var content = ["raz", 2, true], set = new Set(content); a(t.call(set), "raz"); set = new Set(); a(t.call(set), undefined); }; es6-set-0.1.6/test/ext/get-last.js000066400000000000000000000003231427714462400166520ustar00rootroot00000000000000"use strict"; var Set = require("../../"); module.exports = function (t, a) { var content = ["raz", 2, true], set = new Set(content); a(t.call(set), true); set = new Set(); a(t.call(set), undefined); }; es6-set-0.1.6/test/ext/some.js000066400000000000000000000005071427714462400161010ustar00rootroot00000000000000"use strict"; var Set = require("../../"); module.exports = function (t, a) { a(t.call(new Set(), Boolean), false, "Empty set"); a(t.call(new Set([2, 3, 4]), Boolean), true, "All true"); a(t.call(new Set([0, false, 4]), Boolean), true, "Some false"); a(t.call(new Set([0, false, null]), Boolean), false, "All false"); }; es6-set-0.1.6/test/implement.js000066400000000000000000000001201427714462400163170ustar00rootroot00000000000000"use strict"; module.exports = function (t, a) { a(typeof Set, "function"); }; es6-set-0.1.6/test/index.js000066400000000000000000000001271427714462400154430ustar00rootroot00000000000000"use strict"; module.exports = function (T, a) { a(new T(["raz", "dwa"]).size, 2); }; es6-set-0.1.6/test/is-implemented.js000066400000000000000000000004601427714462400172500ustar00rootroot00000000000000"use strict"; var global = require("es5-ext/global") , polyfill = require("../polyfill"); module.exports = function (t, a) { var cache; a(typeof t(), "boolean"); cache = global.Set; global.Set = polyfill; a(t(), true); if (cache === undefined) delete global.Set; else global.Set = cache; }; es6-set-0.1.6/test/is-native-implemented.js000066400000000000000000000001151427714462400205310ustar00rootroot00000000000000"use strict"; module.exports = function (t, a) { a(typeof t, "boolean"); }; es6-set-0.1.6/test/is-set.js000066400000000000000000000006061427714462400155420ustar00rootroot00000000000000"use strict"; var SetPoly = 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 Set !== "undefined") { a(t(new Set()), true, "Native"); } a(t(new SetPoly()), true, "Polyfill"); }; es6-set-0.1.6/test/lib/000077500000000000000000000000001427714462400145445ustar00rootroot00000000000000es6-set-0.1.6/test/lib/iterator.js000066400000000000000000000006311427714462400167330ustar00rootroot00000000000000"use strict"; var Set = require("../../polyfill") , toArray = require("es5-ext/array/to-array"); module.exports = function (T, a) { var set = new Set(["raz", "dwa"]); a.deep(toArray(new T(set)), ["raz", "dwa"], "Default"); a.deep( toArray(new T(set, "key+value")), [ ["raz", "raz"], ["dwa", "dwa"] ], "Key & Value" ); a.deep(toArray(new T(set, "value")), ["raz", "dwa"], "Other"); }; es6-set-0.1.6/test/lib/primitive-iterator.js000066400000000000000000000064431427714462400207500ustar00rootroot00000000000000"use strict"; var Set = require("../../primitive") , toArray = require("es5-ext/array/to-array") , iteratorSymbol = require("es6-symbol").iterator , compare , map; compare = function (value1, value2) { if (!value1.value) return -1; if (!value2.value) return 1; return value1.value.localeCompare(value2.value); }; map = function (arr) { return arr.sort().map(function (value) { return { done: false, value: value }; }); }; module.exports = function (T) { return { "": function (a) { var arr = ["raz", "dwa", "trzy", "cztery", "pięć"] , it , value1 , value2 , set = new Set(arr) , result = []; it = new T(set); a(it[iteratorSymbol](), it, "@@iterator"); value1 = it.next(); result.push(value1); value2 = it.next(); a.not(value1, value2, "Recreate result"); result.push(value2); result.push(it.next()); result.push(it.next()); result.push(it.next()); a.deep(result.sort(compare), map(arr)); a.deep((value1 = it.next()), { done: true, value: undefined }, "End"); a.not(value1, it.next(), "Recreate result on dead"); }, "Emited": function (a) { var arr = ["raz", "dwa", "trzy", "cztery", "pięć"], it, set = new Set(arr), result = []; it = new T(set); result.push(it.next()); result.push(it.next()); set.add("sześć"); arr.push("sześć"); result.push(it.next()); set.delete("pięć"); arr.splice(4, 1); result.push(it.next()); result.push(it.next()); a.deep(result.sort(compare), map(arr)); a.deep(it.next(), { done: true, value: undefined }, "End"); }, "Emited #2": function (a) { var arr = ["raz", "dwa", "trzy", "cztery", "pięć", "sześć"] , it , set = new Set(arr) , result = []; it = new T(set); result.push(it.next()); result.push(it.next()); set.add("siedem"); set.delete("siedem"); result.push(it.next()); result.push(it.next()); set.delete("pięć"); arr.splice(4, 1); result.push(it.next()); a.deep(result.sort(compare), map(arr)); a.deep(it.next(), { done: true, value: undefined }, "End"); }, "Emited: Clear #1": function (a) { var arr = ["raz", "dwa", "trzy", "cztery", "pięć", "sześć"] , it , set = new Set(arr) , result = []; it = new T(set); result.push(it.next()); result.push(it.next()); arr = ["raz", "dwa"]; set.clear(); a.deep(result.sort(compare), map(arr)); a.deep(it.next(), { done: true, value: undefined }, "End"); }, "Emited: Clear #2": function (a) { var arr = ["raz", "dwa", "trzy", "cztery", "pięć", "sześć"] , it , set = new Set(arr) , result = []; it = new T(set); result.push(it.next()); result.push(it.next()); set.clear(); set.add("foo"); set.add("bar"); arr = ["raz", "dwa", "foo", "bar"]; result.push(it.next()); result.push(it.next()); a.deep(result.sort(compare), map(arr)); a.deep(it.next(), { done: true, value: undefined }, "End"); }, "Kinds": function (a) { var set = new Set(["raz", "dwa"]); a.deep(toArray(new T(set)).sort(), ["raz", "dwa"].sort(), "Default"); a.deep( toArray(new T(set, "key+value")).sort(), [ ["raz", "raz"], ["dwa", "dwa"] ].sort(), "Key & Value" ); a.deep(toArray(new T(set, "value")).sort(), ["raz", "dwa"].sort(), "Other"); } }; }; es6-set-0.1.6/test/polyfill.js000066400000000000000000000027621427714462400161750ustar00rootroot00000000000000"use strict"; var aFrom = require("es5-ext/array/from") , toArray = require("es5-ext/array/to-array"); module.exports = function (T, a) { var arr = ["raz", "dwa", "trzy"], set = new T(arr), value1 = {}, value2 = {}, i = 0; a(set instanceof T, true, "Set"); a(set.size, 3, "Size"); a(set.has("raz"), true, "Has: true"); a(set.has(value1), false, "Has: false"); a(set.add(value1), set, "Add: return"); a(set.has(value1), true, "Add"); a(set.size, 4, "Add: Size"); a(set.delete({}), false, "Delete: false"); arr.push(value1); set.forEach(function () { a.deep(aFrom(arguments), [arr[i], arr[i], set], "ForEach: Arguments: #" + i); a(this, value2, "ForEach: Context: #" + i); if (i === 0) { a(set.delete("raz"), true, "Delete: true"); a(set.has("raz"), false, "Delete"); a(set.size, 3, "Delete: size"); set.add("cztery"); arr.push("cztery"); } i++; }, value2); arr.splice(0, 1); a.deep( toArray(set.entries()), [ ["dwa", "dwa"], ["trzy", "trzy"], [value1, value1], ["cztery", "cztery"] ], "Entries" ); a.deep(toArray(set.keys()), ["dwa", "trzy", value1, "cztery"], "Keys"); a.deep(toArray(set.values()), ["dwa", "trzy", value1, "cztery"], "Values"); a.deep(toArray(set), ["dwa", "trzy", value1, "cztery"], "Iterator"); set.clear(); a(set.size, 0, "Clear: size"); a(set.has("trzy"), false, "Clear: has"); a.deep(toArray(set), [], "Clear: Values"); a.h1("Empty initialization"); set = new T(); set.add("foo"); a(set.size, 1); a(set.has("foo"), true); }; es6-set-0.1.6/test/primitive/000077500000000000000000000000001427714462400160065ustar00rootroot00000000000000es6-set-0.1.6/test/primitive/index.js000066400000000000000000000031301427714462400174500ustar00rootroot00000000000000"use strict"; var aFrom = require("es5-ext/array/from") , getIterator = require("es6-iterator/get") , toArray = require("es5-ext/array/to-array"); module.exports = function (T, a) { var arr = ["raz", "dwa", "trzy"] , set = new T(arr) , value1 = "other" , value2 = "other2" , i = 0 , result = []; a(set instanceof T, true, "Set"); a(set.size, 3, "Size"); a(set.has("raz"), true, "Has: true"); a(set.has(value1), false, "Has: false"); a(set.add(value1), set, "Add: return"); a(set.has(value1), true, "Add"); a(set.size, 4, "Add: Size"); a(set.delete("else"), false, "Delete: false"); a(set.get("raz"), "raz", "Get"); arr.push(value1); set.forEach(function () { result.push(aFrom(arguments)); a(this, value2, "ForEach: Context: #" + i); }, value2); a.deep( result.sort(function (valueA, valueB) { return valueA[0].localeCompare(valueB[0]); }), arr.sort().map(function (val) { return [val, val, set]; }) ); a.deep( toArray(set.entries()).sort(), [ ["dwa", "dwa"], ["trzy", "trzy"], [value1, value1], ["raz", "raz"] ].sort(), "Entries" ); a.deep(toArray(set.keys()).sort(), ["dwa", "trzy", value1, "raz"].sort(), "Keys"); a.deep(toArray(set.values()).sort(), ["dwa", "trzy", value1, "raz"].sort(), "Values"); a.deep(toArray(getIterator(set)).sort(), ["dwa", "trzy", value1, "raz"].sort(), "Iterator"); set.clear(); a(set.size, 0, "Clear: size"); a(set.has("trzy"), false, "Clear: has"); a.deep(toArray(set.values()), [], "Clear: Values"); a.h1("Empty initialization"); set = new T(); set.add("foo"); a(set.size, 1); a(set.has("foo"), true); }; es6-set-0.1.6/test/valid-set.js000066400000000000000000000011171427714462400162240ustar00rootroot00000000000000"use strict"; var SetPoly = require("../polyfill"); module.exports = function (t, a) { var set; 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 Set !== "undefined") { set = new Set(); a(t(set), set, "Native"); } set = new SetPoly(); a(t(set), set, "Polyfill"); }; es6-set-0.1.6/valid-set.js000066400000000000000000000002511427714462400152430ustar00rootroot00000000000000"use strict"; var isSet = require("./is-set"); module.exports = function (value) { if (!isSet(value)) throw new TypeError(value + " is not a Set"); return value; };