├── .eslintrc ├── .gitignore ├── CHANGELOG.md ├── CONTRIBUTING.md ├── IdleQueue.mjs ├── IdleValue.mjs ├── LICENSE ├── README.md ├── defineIdleProperties.mjs ├── defineIdleProperty.mjs ├── docs ├── IdleQueue.md ├── IdleValue.md ├── defineIdleProperties.md ├── defineIdleProperty.md └── idle-callback-polyfills.md ├── idle-callback-polyfills.mjs ├── lib ├── now.mjs └── queueMicrotask.mjs ├── package-lock.json ├── package.json └── test ├── IdleQueue-test.mjs ├── IdleValue-test.mjs ├── defineIdleProperties-test.mjs ├── defineIdleProperty-test.mjs ├── helpers.mjs ├── idle-callback-polyfills-test.mjs └── index.html /.eslintrc: -------------------------------------------------------------------------------- 1 | { 2 | 'root': true, 3 | 'env': { 4 | 'browser': true, 5 | 'es6': true, 6 | 'node': true, 7 | 'mocha': true 8 | }, 9 | 'globals': { 10 | 'assert': false, 11 | 'sinon': false, 12 | 'safari': false 13 | }, 14 | 'parserOptions': { 15 | 'ecmaVersion': 2018, 16 | 'sourceType': 'module' 17 | }, 18 | 'extends': [ 19 | 'eslint:recommended', 20 | 'google' 21 | ], 22 | 'rules': { 23 | 'max-len': [2, { 24 | 'code': 80, 25 | 'tabWidth': 2, 26 | 'ignoreUrls': true, 27 | // Ignore `it()` blocks in tests. 28 | 'ignorePattern': 'it\(`' 29 | }] 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | node_modules 3 | npm-debug.log 4 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Changelog 2 | 3 | ### 0.1.1 (2018-10-23) 4 | 5 | - Fix `IdleDealine` typo ([#13](https://github.com/GoogleChromeLabs/idlize/pull/13)) 6 | 7 | ### 0.1.0 (2018-09-20) 8 | 9 | - Initial public release 10 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # How to Contribute 2 | 3 | We'd love to accept your patches and contributions to this project. There are 4 | just a few small guidelines you need to follow. 5 | 6 | ## Contributor License Agreement 7 | 8 | Contributions to this project must be accompanied by a Contributor License 9 | Agreement. You (or your employer) retain the copyright to your contribution; 10 | this simply gives us permission to use and redistribute your contributions as 11 | part of the project. Head over to to see 12 | your current agreements on file or to sign a new one. 13 | 14 | You generally only need to submit a CLA once, so if you've already submitted one 15 | (even if it was for a different project), you probably don't need to do it 16 | again. 17 | 18 | ## Code reviews 19 | 20 | All submissions, including submissions by project members, require review. We 21 | use GitHub pull requests for this purpose. Consult 22 | [GitHub Help](https://help.github.com/articles/about-pull-requests/) for more 23 | information on using pull requests. 24 | 25 | ## Community Guidelines 26 | 27 | This project follows [Google's Open Source Community 28 | Guidelines](https://opensource.google.com/conduct/). 29 | -------------------------------------------------------------------------------- /IdleQueue.mjs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 Google Inc. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | import {cIC, rIC} from './idle-callback-polyfills.mjs'; 18 | import {now} from './lib/now.mjs'; 19 | import {queueMicrotask} from './lib/queueMicrotask.mjs'; 20 | 21 | 22 | const DEFAULT_MIN_TASK_TIME = 0; 23 | 24 | const isSafari_ = !!(typeof safari === 'object' && safari.pushNotification); 25 | 26 | /** 27 | * A class wraps a queue of requestIdleCallback functions for two reasons: 28 | * 1. So other callers can know whether or not the queue is empty. 29 | * 2. So we can provide some guarantees that the queued functions will 30 | * run in unload-type situations. 31 | */ 32 | export class IdleQueue { 33 | /** 34 | * Creates the IdleQueue instance and adds lifecycle event listeners to 35 | * run the queue if the page is hidden (with fallback behavior for Safari). 36 | * @param {{ 37 | * ensureTasksRun: boolean, 38 | * defaultMinTaskTime: number, 39 | * }=} param1 40 | */ 41 | constructor({ 42 | ensureTasksRun = false, 43 | defaultMinTaskTime = DEFAULT_MIN_TASK_TIME, 44 | } = {}) { 45 | this.idleCallbackHandle_ = null; 46 | this.taskQueue_ = []; 47 | this.isProcessing_ = false; 48 | this.state_ = null; 49 | this.defaultMinTaskTime_ = defaultMinTaskTime; 50 | this.ensureTasksRun_ = ensureTasksRun; 51 | 52 | // Bind methods 53 | this.runTasksImmediately = this.runTasksImmediately.bind(this); 54 | this.runTasks_ = this.runTasks_.bind(this); 55 | this.onVisibilityChange_ = this.onVisibilityChange_.bind(this); 56 | 57 | if (this.ensureTasksRun_) { 58 | addEventListener('visibilitychange', this.onVisibilityChange_, true); 59 | 60 | // Safari does not reliably fire the `pagehide` or `visibilitychange` 61 | // events when closing a tab, so we have to use `beforeunload` with a 62 | // timeout to check whether the default action was prevented. 63 | // - https://bugs.webkit.org/show_bug.cgi?id=151610 64 | // - https://bugs.webkit.org/show_bug.cgi?id=151234 65 | // NOTE: we only add this to Safari because adding it to Firefox would 66 | // prevent the page from being eligible for bfcache. 67 | if (isSafari_) { 68 | addEventListener('beforeunload', this.runTasksImmediately, true); 69 | } 70 | } 71 | } 72 | 73 | /** 74 | * @param {...*} args 75 | */ 76 | pushTask(...args) { 77 | this.addTask_(Array.prototype.push, ...args); 78 | } 79 | 80 | /** 81 | * @param {...*} args 82 | */ 83 | unshiftTask(...args) { 84 | this.addTask_(Array.prototype.unshift, ...args); 85 | } 86 | 87 | /** 88 | * Runs all scheduled tasks synchronously. 89 | */ 90 | runTasksImmediately() { 91 | // By not passing a deadline, all tasks will be run sync. 92 | this.runTasks_(); 93 | } 94 | 95 | /** 96 | * @return {boolean} 97 | */ 98 | hasPendingTasks() { 99 | return this.taskQueue_.length > 0; 100 | } 101 | 102 | 103 | /** 104 | * Clears all pending tasks for the queue and stops any scheduled tasks 105 | * from running. 106 | */ 107 | clearPendingTasks() { 108 | this.taskQueue_ = []; 109 | this.cancelScheduledRun_(); 110 | } 111 | 112 | /** 113 | * Returns the state object for the currently running task. If no task is 114 | * running, null is returned. 115 | * @return {?Object} 116 | */ 117 | getState() { 118 | return this.state_; 119 | } 120 | 121 | /** 122 | * Destroys the instance by unregistering all added event listeners and 123 | * removing any overridden methods. 124 | */ 125 | destroy() { 126 | this.taskQueue_ = []; 127 | this.cancelScheduledRun_(); 128 | 129 | if (this.ensureTasksRun_) { 130 | removeEventListener('visibilitychange', this.onVisibilityChange_, true); 131 | 132 | // Safari does not reliably fire the `pagehide` or `visibilitychange` 133 | // events when closing a tab, so we have to use `beforeunload` with a 134 | // timeout to check whether the default action was prevented. 135 | // - https://bugs.webkit.org/show_bug.cgi?id=151610 136 | // - https://bugs.webkit.org/show_bug.cgi?id=151234 137 | // NOTE: we only add this to Safari because adding it to Firefox would 138 | // prevent the page from being eligible for bfcache. 139 | if (isSafari_) { 140 | removeEventListener( 141 | 'beforeunload', this.runTasksImmediately, true); 142 | } 143 | } 144 | } 145 | 146 | /** 147 | * @param {!Function} arrayMethod Either the Array.prototype{push|shift}. 148 | * @param {!Function} task 149 | * @param {{minTaskTime: number}=} param1 150 | * @private 151 | */ 152 | addTask_(arrayMethod, task, {minTaskTime = this.defaultMinTaskTime_} = {}) { 153 | const state = { 154 | time: now(), 155 | visibilityState: document.visibilityState, 156 | }; 157 | 158 | arrayMethod.call(this.taskQueue_, {state, task, minTaskTime}); 159 | 160 | this.scheduleTasksToRun_(); 161 | } 162 | 163 | /** 164 | * Schedules the task queue to be processed. If the document is in the 165 | * hidden state, they queue is scheduled as a microtask so it can be run 166 | * in cases where a macrotask couldn't (like if the page is unloading). If 167 | * the document is in the visible state, `requestIdleCallback` is used. 168 | * @private 169 | */ 170 | scheduleTasksToRun_() { 171 | if (this.ensureTasksRun_ && document.visibilityState === 'hidden') { 172 | queueMicrotask(this.runTasks_); 173 | } else { 174 | if (!this.idleCallbackHandle_) { 175 | this.idleCallbackHandle_ = rIC(this.runTasks_); 176 | } 177 | } 178 | } 179 | 180 | /** 181 | * Runs as many tasks in the queue as it can before reaching the 182 | * deadline. If no deadline is passed, it will run all tasks. 183 | * If an `IdleDeadline` object is passed (as is with `requestIdleCallback`) 184 | * then the tasks are run until there's no time remaining, at which point 185 | * we yield to input or other script and wait until the next idle time. 186 | * @param {IdleDeadline=} deadline 187 | * @private 188 | */ 189 | runTasks_(deadline = undefined) { 190 | this.cancelScheduledRun_(); 191 | 192 | if (!this.isProcessing_) { 193 | this.isProcessing_ = true; 194 | 195 | // Process tasks until there's no time left or we need to yield to input. 196 | while (this.hasPendingTasks() && 197 | !shouldYield(deadline, this.taskQueue_[0].minTaskTime)) { 198 | const {task, state} = this.taskQueue_.shift(); 199 | 200 | this.state_ = state; 201 | task(state); 202 | this.state_ = null; 203 | } 204 | 205 | this.isProcessing_ = false; 206 | 207 | if (this.hasPendingTasks()) { 208 | // Schedule the rest of the tasks for the next idle time. 209 | this.scheduleTasksToRun_(); 210 | } 211 | } 212 | } 213 | 214 | /** 215 | * Cancels any scheduled idle callback and removes the handler (if set). 216 | * @private 217 | */ 218 | cancelScheduledRun_() { 219 | cIC(this.idleCallbackHandle_); 220 | this.idleCallbackHandle_ = null; 221 | } 222 | 223 | /** 224 | * A callback for the `visibilitychange` event that runs all pending 225 | * callbacks immediately if the document's visibility state is hidden. 226 | * @private 227 | */ 228 | onVisibilityChange_() { 229 | if (document.visibilityState === 'hidden') { 230 | this.runTasksImmediately(); 231 | } 232 | } 233 | } 234 | 235 | /** 236 | * Returns true if the IdleDealine object exists and the remaining time is 237 | * less or equal to than the minTaskTime. Otherwise returns false. 238 | * @param {IdleDeadline|undefined} deadline 239 | * @param {number} minTaskTime 240 | * @return {boolean} 241 | * @private 242 | */ 243 | const shouldYield = (deadline, minTaskTime) => { 244 | if (deadline && deadline.timeRemaining() <= minTaskTime) { 245 | return true; 246 | } 247 | return false; 248 | }; 249 | -------------------------------------------------------------------------------- /IdleValue.mjs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 Google Inc. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | import {cIC, rIC} from './idle-callback-polyfills.mjs'; 18 | 19 | 20 | /** 21 | * A class that wraps a value that is initialized when idle. 22 | */ 23 | export class IdleValue { 24 | /** 25 | * Accepts a function to initialize the value of a variable when idle. 26 | * @param {!Function} init 27 | */ 28 | constructor(init) { 29 | this.init_ = init; 30 | 31 | /** @type (?|undefined) */ 32 | this.value_; 33 | 34 | this.idleHandle_ = rIC(() => { 35 | this.value_ = this.init_(); 36 | }); 37 | } 38 | 39 | /** 40 | * Returns the value if it's already been initialized. If it hasn't then the 41 | * initializer function is run immediately and the pending idle callback 42 | * is cancelled. 43 | * @return {?} 44 | */ 45 | getValue() { 46 | if (this.value_ === undefined) { 47 | this.cancleIdleInit_(); 48 | this.value_ = this.init_(); 49 | } 50 | return this.value_; 51 | } 52 | 53 | /** 54 | * @param {?} newValue 55 | */ 56 | setValue(newValue) { 57 | this.cancleIdleInit_(); 58 | this.value_ = newValue; 59 | } 60 | 61 | /** 62 | * Cancels any scheduled requestIdleCallback and resets the handle. 63 | * @private 64 | */ 65 | cancleIdleInit_() { 66 | if (this.idleHandle_) { 67 | cIC(this.idleHandle_); 68 | this.idleHandle_ = null; 69 | } 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | 2 | Apache License 3 | Version 2.0, January 2004 4 | http://www.apache.org/licenses/ 5 | 6 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 7 | 8 | 1. Definitions. 9 | 10 | "License" shall mean the terms and conditions for use, reproduction, 11 | and distribution as defined by Sections 1 through 9 of this document. 12 | 13 | "Licensor" shall mean the copyright owner or entity authorized by 14 | the copyright owner that is granting the License. 15 | 16 | "Legal Entity" shall mean the union of the acting entity and all 17 | other entities that control, are controlled by, or are under common 18 | control with that entity. For the purposes of this definition, 19 | "control" means (i) the power, direct or indirect, to cause the 20 | direction or management of such entity, whether by contract or 21 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 22 | outstanding shares, or (iii) beneficial ownership of such entity. 23 | 24 | "You" (or "Your") shall mean an individual or Legal Entity 25 | exercising permissions granted by this License. 26 | 27 | "Source" form shall mean the preferred form for making modifications, 28 | including but not limited to software source code, documentation 29 | source, and configuration files. 30 | 31 | "Object" form shall mean any form resulting from mechanical 32 | transformation or translation of a Source form, including but 33 | not limited to compiled object code, generated documentation, 34 | and conversions to other media types. 35 | 36 | "Work" shall mean the work of authorship, whether in Source or 37 | Object form, made available under the License, as indicated by a 38 | copyright notice that is included in or attached to the work 39 | (an example is provided in the Appendix below). 40 | 41 | "Derivative Works" shall mean any work, whether in Source or Object 42 | form, that is based on (or derived from) the Work and for which the 43 | editorial revisions, annotations, elaborations, or other modifications 44 | represent, as a whole, an original work of authorship. For the purposes 45 | of this License, Derivative Works shall not include works that remain 46 | separable from, or merely link (or bind by name) to the interfaces of, 47 | the Work and Derivative Works thereof. 48 | 49 | "Contribution" shall mean any work of authorship, including 50 | the original version of the Work and any modifications or additions 51 | to that Work or Derivative Works thereof, that is intentionally 52 | submitted to Licensor for inclusion in the Work by the copyright owner 53 | or by an individual or Legal Entity authorized to submit on behalf of 54 | the copyright owner. For the purposes of this definition, "submitted" 55 | means any form of electronic, verbal, or written communication sent 56 | to the Licensor or its representatives, including but not limited to 57 | communication on electronic mailing lists, source code control systems, 58 | and issue tracking systems that are managed by, or on behalf of, the 59 | Licensor for the purpose of discussing and improving the Work, but 60 | excluding communication that is conspicuously marked or otherwise 61 | designated in writing by the copyright owner as "Not a Contribution." 62 | 63 | "Contributor" shall mean Licensor and any individual or Legal Entity 64 | on behalf of whom a Contribution has been received by Licensor and 65 | subsequently incorporated within the Work. 66 | 67 | 2. Grant of Copyright License. Subject to the terms and conditions of 68 | this License, each Contributor hereby grants to You a perpetual, 69 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 70 | copyright license to reproduce, prepare Derivative Works of, 71 | publicly display, publicly perform, sublicense, and distribute the 72 | Work and such Derivative Works in Source or Object form. 73 | 74 | 3. Grant of Patent License. Subject to the terms and conditions of 75 | this License, each Contributor hereby grants to You a perpetual, 76 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 77 | (except as stated in this section) patent license to make, have made, 78 | use, offer to sell, sell, import, and otherwise transfer the Work, 79 | where such license applies only to those patent claims licensable 80 | by such Contributor that are necessarily infringed by their 81 | Contribution(s) alone or by combination of their Contribution(s) 82 | with the Work to which such Contribution(s) was submitted. If You 83 | institute patent litigation against any entity (including a 84 | cross-claim or counterclaim in a lawsuit) alleging that the Work 85 | or a Contribution incorporated within the Work constitutes direct 86 | or contributory patent infringement, then any patent licenses 87 | granted to You under this License for that Work shall terminate 88 | as of the date such litigation is filed. 89 | 90 | 4. Redistribution. You may reproduce and distribute copies of the 91 | Work or Derivative Works thereof in any medium, with or without 92 | modifications, and in Source or Object form, provided that You 93 | meet the following conditions: 94 | 95 | (a) You must give any other recipients of the Work or 96 | Derivative Works a copy of this License; and 97 | 98 | (b) You must cause any modified files to carry prominent notices 99 | stating that You changed the files; and 100 | 101 | (c) You must retain, in the Source form of any Derivative Works 102 | that You distribute, all copyright, patent, trademark, and 103 | attribution notices from the Source form of the Work, 104 | excluding those notices that do not pertain to any part of 105 | the Derivative Works; and 106 | 107 | (d) If the Work includes a "NOTICE" text file as part of its 108 | distribution, then any Derivative Works that You distribute must 109 | include a readable copy of the attribution notices contained 110 | within such NOTICE file, excluding those notices that do not 111 | pertain to any part of the Derivative Works, in at least one 112 | of the following places: within a NOTICE text file distributed 113 | as part of the Derivative Works; within the Source form or 114 | documentation, if provided along with the Derivative Works; or, 115 | within a display generated by the Derivative Works, if and 116 | wherever such third-party notices normally appear. The contents 117 | of the NOTICE file are for informational purposes only and 118 | do not modify the License. You may add Your own attribution 119 | notices within Derivative Works that You distribute, alongside 120 | or as an addendum to the NOTICE text from the Work, provided 121 | that such additional attribution notices cannot be construed 122 | as modifying the License. 123 | 124 | You may add Your own copyright statement to Your modifications and 125 | may provide additional or different license terms and conditions 126 | for use, reproduction, or distribution of Your modifications, or 127 | for any such Derivative Works as a whole, provided Your use, 128 | reproduction, and distribution of the Work otherwise complies with 129 | the conditions stated in this License. 130 | 131 | 5. Submission of Contributions. Unless You explicitly state otherwise, 132 | any Contribution intentionally submitted for inclusion in the Work 133 | by You to the Licensor shall be under the terms and conditions of 134 | this License, without any additional terms or conditions. 135 | Notwithstanding the above, nothing herein shall supersede or modify 136 | the terms of any separate license agreement you may have executed 137 | with Licensor regarding such Contributions. 138 | 139 | 6. Trademarks. This License does not grant permission to use the trade 140 | names, trademarks, service marks, or product names of the Licensor, 141 | except as required for reasonable and customary use in describing the 142 | origin of the Work and reproducing the content of the NOTICE file. 143 | 144 | 7. Disclaimer of Warranty. Unless required by applicable law or 145 | agreed to in writing, Licensor provides the Work (and each 146 | Contributor provides its Contributions) on an "AS IS" BASIS, 147 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 148 | implied, including, without limitation, any warranties or conditions 149 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 150 | PARTICULAR PURPOSE. You are solely responsible for determining the 151 | appropriateness of using or redistributing the Work and assume any 152 | risks associated with Your exercise of permissions under this License. 153 | 154 | 8. Limitation of Liability. In no event and under no legal theory, 155 | whether in tort (including negligence), contract, or otherwise, 156 | unless required by applicable law (such as deliberate and grossly 157 | negligent acts) or agreed to in writing, shall any Contributor be 158 | liable to You for damages, including any direct, indirect, special, 159 | incidental, or consequential damages of any character arising as a 160 | result of this License or out of the use or inability to use the 161 | Work (including but not limited to damages for loss of goodwill, 162 | work stoppage, computer failure or malfunction, or any and all 163 | other commercial damages or losses), even if such Contributor 164 | has been advised of the possibility of such damages. 165 | 166 | 9. Accepting Warranty or Additional Liability. While redistributing 167 | the Work or Derivative Works thereof, You may choose to offer, 168 | and charge a fee for, acceptance of support, warranty, indemnity, 169 | or other liability obligations and/or rights consistent with this 170 | License. However, in accepting such obligations, You may act only 171 | on Your own behalf and on Your sole responsibility, not on behalf 172 | of any other Contributor, and only if You agree to indemnify, 173 | defend, and hold each Contributor harmless for any liability 174 | incurred by, or claims asserted against, such Contributor by reason 175 | of your accepting any such warranty or additional liability. 176 | 177 | END OF TERMS AND CONDITIONS 178 | 179 | APPENDIX: How to apply the Apache License to your work. 180 | 181 | To apply the Apache License to your work, attach the following 182 | boilerplate notice, with the fields enclosed by brackets "[]" 183 | replaced with your own identifying information. (Don't include 184 | the brackets!) The text should be enclosed in the appropriate 185 | comment syntax for the file format. We also recommend that a 186 | file or class name and description of purpose be included on the 187 | same "printed page" as the copyright notice for easier 188 | identification within third-party archives. 189 | 190 | Copyright 2018 Google, Inc. 191 | 192 | Licensed under the Apache License, Version 2.0 (the "License"); 193 | you may not use this file except in compliance with the License. 194 | You may obtain a copy of the License at 195 | 196 | http://www.apache.org/licenses/LICENSE-2.0 197 | 198 | Unless required by applicable law or agreed to in writing, software 199 | distributed under the License is distributed on an "AS IS" BASIS, 200 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 201 | See the License for the specific language governing permissions and 202 | limitations under the License. 203 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Idlize 2 | 3 | Helper classes and methods make it easier for developers to implement the [*idle-until-urgent*](https://philipwalton.com/articles/idle-until-urgent/) pattern and leverage the [`requestIdleCallback()`](https://developer.mozilla.org/en-US/docs/Web/API/Window/requestIdleCallback) API. 4 | 5 | ## Installation 6 | 7 | You can install this library from npm by running: 8 | 9 | ```sh 10 | npm install idlize 11 | ``` 12 | 13 | ## Usage 14 | 15 | This library is a collection of helper methods and classes (not a single bundle). As such, each helper should be imported separately. All public helpers are released at the level of the project, so they can be imported by directly referencing the helper's `.mjs` file. 16 | 17 | ```js 18 | import {defineIdleProperty} from 'idlize/defineIdleProperty.mjs' 19 | import {defineIdleProperties} from 'idlize/defineIdleProperties.mjs' 20 | import {cIC, rIC} from 'idlize/idle-callback-polyfills.mjs' 21 | import {IdleQueue} from 'idlize/IdleQueue.mjs' 22 | import {IdleValue} from 'idlize/IdleValue.mjs' 23 | ``` 24 | 25 | Refer to each helper's [documentation](/docs) for examples and API usage details: 26 | 27 | - [`defineIdleProperty.mjs`](/docs/defineIdleProperty.md) 28 | - [`defineIdleProperties.mjs`](/docs/defineIdleProperties.md) 29 | - [`idle-callback-polyfills.mjs`](/docs/idle-callback-polyfills.md) 30 | - [`IdleQueue.mjs`](/docs/IdleQueue.md) 31 | - [`IdleValue.mjs`](/docs/IdleValue.md) 32 | 33 | ## Browser Support 34 | 35 | 36 | 37 | 41 | 45 | 49 | 53 | 57 | 61 | 62 |
38 | Chrome
39 | ✔ 40 |
42 | Firefox
43 | ✔ 44 |
46 | Safari
47 | ✔ 48 |
50 | Edge
51 | ✔ 52 |
54 | Internet Explorer
55 | 9+ 56 |
58 | Opera
59 | ✔ 60 |
63 | 64 | This code has been tested and known to work in all major browsers as well as Internet Explorer back to version 9. 65 | 66 | ## License 67 | 68 | [Apache 2.0](/LICENSE) 69 | -------------------------------------------------------------------------------- /defineIdleProperties.mjs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 Google Inc. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | import {defineIdleProperty} from './defineIdleProperty.mjs'; 18 | 19 | 20 | /** 21 | * @param {!Object} obj The object to define the property on. 22 | * @param {!Object} props A mapping of property names to 23 | * initialization functions to be run idly. 24 | */ 25 | export const defineIdleProperties = (obj, props) => { 26 | Object.keys(props).forEach((prop) => { 27 | defineIdleProperty(obj, prop, props[prop]); 28 | }); 29 | }; 30 | -------------------------------------------------------------------------------- /defineIdleProperty.mjs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 Google Inc. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | import {IdleValue} from './IdleValue.mjs'; 18 | 19 | 20 | /** 21 | * @param {!Object} obj The object to define the property on. 22 | * @param {string} prop The property name. 23 | * @param {!Function} init An initialization function to by run idly. 24 | */ 25 | export const defineIdleProperty = (obj, prop, init) => { 26 | const idleValue = new IdleValue(init); 27 | 28 | Object.defineProperty(obj, prop, { 29 | configurable: true, 30 | get: idleValue.getValue.bind(idleValue), 31 | set: idleValue.setValue.bind(idleValue), 32 | }); 33 | }; 34 | -------------------------------------------------------------------------------- /docs/IdleQueue.md: -------------------------------------------------------------------------------- 1 | # `IdleQueue.mjs` 2 | 3 | [`idlize/IdleQueue.mjs`](/IdleQueue.mjs) 4 | 5 | ## Overview 6 | 7 | The `IdleQueue` class is a helper that allows developers to implement the [*idle-until-urgent*](https://philipwalton.com/articles/idle-until-urgent/) pattern in their code. It's useful for apps that want to split up their logic into a sequence of functions and schedule them to run idly. 8 | 9 | This class offers a few benefits over the regular usage of [`requestIdleCallback()`](https://developers.google.com/web/updates/2015/08/using-requestidlecallback): 10 | 11 | - The queue can be configured so all queued functions are guaranteed to run before the page is unloaded. 12 | - Queued tasks can be run immediately at any time. 13 | - Queued tasks can pass a minimum time budget, below which they won't attempt to run (this minimum time budget can also be configured per queue). 14 | - Queued tasks store the time/visibilityState when they were added to the queue, and are invoked with this data when run. 15 | 16 | ### Exports 17 | 18 | - [`IdleQueue`](#idlequeue) 19 | 20 | ### Usage 21 | 22 | ```js 23 | import {IdleQueue} from 'idlize/IdleQueue.mjs'; 24 | 25 | const queue = new IdleQueue(); 26 | 27 | queue.pushTask(() => { 28 | // Some expensive function that can run idly... 29 | }); 30 | 31 | queue.pushTask(() => { 32 | // Some other task that depends on the above 33 | // expensive function having already run... 34 | }); 35 | ``` 36 | 37 | ## `IdleQueue` 38 | 39 | ### Methods 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 61 | 62 | 63 | 64 | 85 | 86 | 87 | 88 | 109 | 110 | 111 | 112 | 115 | 116 | 117 | 118 | 122 | 123 | 124 | 125 | 128 | 129 | 130 | 131 | 142 | 143 |
NameDescription
constructor(options) 49 |

Parameters:

50 |
    51 |
  • 52 | options.ensureTasksRun (boolean) 53 | Adds Page Lifecycle callbacks to ensure the queue is run before the user leaves the page (default: false). 54 |
  • 55 |
  • 56 | options.defaultMinTaskTime: (number) 57 | The default amount of idle time remaining in order for a task to be run (default: 0). 58 |
  • 59 |
60 |
pushTask(task, options) 65 |

Parameters:

66 |
    67 |
  • task: (function(Object)) 68 | The task to add to the end of the queue. 69 |
  • 70 |
  • options.minTaskTime: (number) 71 | The minimum amount of idle time remaining in order for a task to be run. If no value is passed, the queue default is used. 72 |
  • 73 |
74 |

Adds a task to the end of the queue and schedules the queue to be run when next idle (if not already scheduled).

75 |

When the task is run, it's invoked with an object containing the following properties:

76 |
    77 |
  • time: (number) 78 | The time (epoch time in milliseconds) when the task was added to the queue. 79 |
  • 80 |
  • visibilityState: (string) 81 | The visibility state of the document when the task was added to the queue. 82 |
  • 83 |
84 |
unshiftTask(task, options) 89 |

Parameters:

90 |
    91 |
  • task: (function(Object<{{time: number, visibilityState: string}}>)) 92 | The task to add to the beginning of the queue. 93 |
  • 94 |
  • options.minTaskTime: (number) 95 | The minimum amount of idle time remaining in order for a task to be run. If no value is passed, the queue default is used. 96 |
  • 97 |
98 |

Adds a task to the beginning of the queue and schedules the queue to be run when next idle (if not already scheduled).

99 |

When the task is run, it's invoked with an object containing the following properties:

100 |
    101 |
  • time: (number) 102 | The time (epoch time in milliseconds) when the task was added to the queue. 103 |
  • 104 |
  • visibilityState: (string) 105 | The visibility state of the document when the task was added to the queue. 106 |
  • 107 |
108 |
runTasksImmediately() 113 |

Runs all queued tasks immediately (synchronously).

114 |
hasPendingTasks() 119 |

Returns: (boolean)

120 |

True if the queue has any tasks not yet run.

121 |
clearPendingTasks() 126 |

Unschedules all pending tasks in the queue.

127 |
getState() 132 |

Returns: (Object)

133 |
    134 |
  • {time}: (number) 135 | The time (milliseconds, in epoch time) the task was added to the queue. 136 |
  • 137 |
  • {visibilityState}: (string) 138 | The document's visibility state when the task was added to the queue. 139 |
  • 140 |
141 |
144 | -------------------------------------------------------------------------------- /docs/IdleValue.md: -------------------------------------------------------------------------------- 1 | # `IdleValue.mjs` 2 | 3 | [`idlize/IdleValue.mjs`](/IdleValue.mjs) 4 | 5 | ## Overview 6 | 7 | The `IdleValue` class is a helper that allows developers to implement the [*idle-until-urgent*](https://philipwalton.com/articles/idle-until-urgent/) pattern in their code. It's useful when you want to initialize a value during an idle period but ensure it can be initialized immediately as soon as it's needed. 8 | 9 | ### Exports 10 | 11 | - [`IdleValue`](#idlevalue) 12 | 13 | ### Usage 14 | 15 | ```js 16 | import {IdleValue} from 'idlize/IdleValue.mjs'; 17 | 18 | class MyClass { 19 | constructor() { 20 | // Create an IdleValue instance for `this.data`. It's value is 21 | // initialized in an idle callback (or immediately as soon as 22 | // `this.data.getValue()` is called). 23 | this.data = new IdleValue(() => { 24 | // Run expensive code and return the result... 25 | }); 26 | } 27 | } 28 | ``` 29 | 30 | ## `IdleValue` 31 | 32 | ### Methods 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 51 | 52 | 53 | 54 | 58 | 59 | 60 | 61 | 70 | 71 |
NameDescription
constructor(init) 42 |

Parameters:

43 |
    44 |
  • 45 | init (Function) 46 | An initialization function (typically something expensive to compute) that returns a value. 47 |
  • 48 |
49 |

The initialization function is scheduled to run in an idle callback as soon as the instance is created.

50 |
getValue() 55 |

Returns: (*)

56 |

Returns the value returned by the initialization function passed to the constructor. If the initialization function has already been run, the value is returned immediately. If the initialization function is still scheduled for an idle callback, that callback is cancelled, the initialization function is run synchronously, and the result is returned.

57 |
setValue(newValue) 62 |

Parameters:

63 |
    64 |
  • 65 | newValue (*) 66 |
  • 67 |
68 |

Assigns a new value. If the initialization function passed to the constructor has not yet run, it is cancelled.

69 |
72 | 73 | -------------------------------------------------------------------------------- /docs/defineIdleProperties.md: -------------------------------------------------------------------------------- 1 | # `defineIdleProperties.mjs` 2 | 3 | [`idlize/defineIdleProperties.mjs`](/defineIdleProperties.mjs) 4 | 5 | ## Overview 6 | 7 | This module provides a `defineIdleProperties` helper function that allows developers to implement the [*idle-until-urgent*](https://philipwalton.com/articles/idle-until-urgent/) pattern in their code. It's useful when you want to initialize one or more property values during an idle period but ensure they can be initialized immediately as soon as they're referenced. 8 | 9 | ### Exports 10 | 11 | - [`defineIdleProperties`](#defineidleproperties) 12 | 13 | ### Usage 14 | 15 | ```js 16 | import {defineIdleProperties} from 'idlize/defineIdleProperties.mjs'; 17 | 18 | class MyClass { 19 | constructor() { 20 | // Define a getter for `this.data` whose value is initialized 21 | // in an idle callback (or immediately if referenced). 22 | defineIdleProperties(this, { 23 | data: () => { 24 | // Run expensive code and return the result... 25 | }, 26 | }); 27 | } 28 | } 29 | ``` 30 | 31 | ## `defineIdleProperties` 32 | 33 | ### Syntax 34 | 35 | ```js 36 | defineIdleProperties(obj, props); 37 | ``` 38 | 39 | ### Parameters 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 53 | 54 | 55 | 56 | 57 | 60 | 61 |
NameTypeDescription
objObject 51 | The object on which to define the property. 52 |
propsObject 58 | A dictionary of property names and initialization functions. See the defineIdleProperty documentation for prop and init. 59 |
62 | -------------------------------------------------------------------------------- /docs/defineIdleProperty.md: -------------------------------------------------------------------------------- 1 | # `defineIdleProperty.mjs` 2 | 3 | [`idlize/defineIdleProperty.mjs`](/defineIdleProperty.mjs) 4 | 5 | ## Overview 6 | 7 | The module provides a `defineIdleProperty` helper function that allows developers to implement the [*idle-until-urgent*](https://philipwalton.com/articles/idle-until-urgent/) pattern in their code. It's useful when you want to initialize a property value during an idle period but ensure it can be initialized immediately as soon as it's referenced. 8 | 9 | ### Exports 10 | 11 | - [`defineIdleProperty`](#defineidleproperty) 12 | 13 | ### Usage 14 | 15 | ```js 16 | import {defineIdleProperty} from 'idlize/defineIdleProperty.mjs'; 17 | 18 | class MyClass { 19 | constructor() { 20 | // Define a getter for `this.data` whose value is initialized 21 | // in an idle callback (or immediately if referenced). 22 | defineIdleProperty(this, 'data', () => { 23 | // Run expensive code and return the result... 24 | }); 25 | } 26 | } 27 | ``` 28 | 29 | ## `defineIdleProperty` 30 | 31 | ### Syntax 32 | 33 | ```js 34 | defineIdleProperty(obj, prop, init); 35 | ``` 36 | 37 | ### Parameters 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 51 | 52 | 53 | 54 | 55 | 58 | 59 | 60 | 61 | 62 | 65 | 66 |
NameTypeDescription
objObject 49 | The object on which to define the property. 50 |
propstring 56 | The name of the property. 57 |
initFunction 63 | An function (typically something expensive to compute) that returns a value. The function is scheduled to run in an idle callback as soon as the property is defined. If the property is referenced before the function can be run in an idle callback, the idle callback is canceled, the function is run immediately, and the return value of the function is set as the value of the property. 64 |
67 | -------------------------------------------------------------------------------- /docs/idle-callback-polyfills.md: -------------------------------------------------------------------------------- 1 | # `idle-callback-polyfills.mjs` 2 | 3 | [`idlize/idle-callback-polyfills.mjs`](/idle-callback-polyfills.mjs) 4 | 5 | ## Overview 6 | 7 | Small polyfills that allow developers to use [`requestIdleCallback`](https://developer.mozilla.org/en-US/docs/Web/API/Window/requestIdleCallback) and [`cancelIdleCallback()`](https://developer.mozilla.org/en-US/docs/Web/API/Window/cancelIdleCallback) in all browsers. 8 | 9 | These are not full polyfills (since the native APIs cannot be fully polyfilled), but they offer the basic benefits of idle tasks via `setTimeout()` and `clearTimeout()`. 10 | 11 | ### Exports 12 | 13 | - [`rIC`](#rIC) 14 | - [`cIC`](#cIC) 15 | 16 | ### Usage 17 | 18 | ```js 19 | import {rIC, cIC} from 'idlize/idle-callback-polyfills.mjs'; 20 | 21 | // To run a task when idle. 22 | const handle = rIC(() => { 23 | // Do something here... 24 | }); 25 | 26 | // To cancel the idle callback. 27 | cIC(handle); 28 | ``` 29 | 30 | ## `rIC` 31 | 32 | Uses the native `requestIdleCallback()` function in browsers that support it, or a small polyfill (based on `setTimeout()`) in browsers that don't. 33 | 34 | See the [`requestIdleCallback()` docs on MDN](https://developer.mozilla.org/en-US/docs/Web/API/Window/requestIdleCallback) for details. 35 | 36 | ## `cIC` 37 | 38 | Uses the native `cancelIdleCallback()` function in browsers that support it, or a small polyfill (based on `clearTimeout()`) in browsers that don't. 39 | 40 | See the [`cancelIdleCallback()` docs on MDN](https://developer.mozilla.org/en-US/docs/Web/API/Window/cancelIdleCallback) for details. 41 | -------------------------------------------------------------------------------- /idle-callback-polyfills.mjs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 Google Inc. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | import {now} from './lib/now.mjs'; 18 | 19 | 20 | const supportsRequestIdleCallback_ = typeof requestIdleCallback === 'function'; 21 | 22 | /** 23 | * A minimal shim of the native IdleDeadline class. 24 | */ 25 | class IdleDeadline { 26 | /** @param {number} initTime */ 27 | constructor(initTime) { 28 | this.initTime_ = initTime; 29 | } 30 | /** @return {boolean} */ 31 | get didTimeout() { 32 | return false; 33 | } 34 | /** @return {number} */ 35 | timeRemaining() { 36 | return Math.max(0, 50 - (now() - this.initTime_)); 37 | } 38 | } 39 | 40 | /** 41 | * A minimal shim for the requestIdleCallback function. This accepts a 42 | * callback function and runs it at the next idle period, passing in an 43 | * object with a `timeRemaining()` method. 44 | * @private 45 | * @param {!Function} callback 46 | * @return {number} 47 | */ 48 | const requestIdleCallbackShim = (callback) => { 49 | const deadline = new IdleDeadline(now()); 50 | return setTimeout(() => callback(deadline), 0); 51 | }; 52 | 53 | 54 | /** 55 | * A minimal shim for the cancelIdleCallback function. This accepts a 56 | * handle identifying the idle callback to cancel. 57 | * @private 58 | * @param {number|null} handle 59 | */ 60 | const cancelIdleCallbackShim = (handle) => { 61 | clearTimeout(handle); 62 | }; 63 | 64 | 65 | /** 66 | * The native `requestIdleCallback()` function or `cancelIdleCallbackShim()` 67 | *.if the browser doesn't support it. 68 | * @param {!Function} callback 69 | * @return {number} 70 | */ 71 | export const rIC = supportsRequestIdleCallback_ ? 72 | requestIdleCallback : requestIdleCallbackShim; 73 | 74 | 75 | /** 76 | * The native `cancelIdleCallback()` function or `cancelIdleCallbackShim()` 77 | * if the browser doesn't support it. 78 | * @param {number} handle 79 | */ 80 | export const cIC = supportsRequestIdleCallback_ ? 81 | cancelIdleCallback : cancelIdleCallbackShim; 82 | -------------------------------------------------------------------------------- /lib/now.mjs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 Google Inc. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | /** 18 | * @private 19 | * @return {number} The current date timestamp 20 | */ 21 | export const now = () => { 22 | return +new Date(); 23 | }; 24 | -------------------------------------------------------------------------------- /lib/queueMicrotask.mjs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 Google Inc. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | /** 18 | * @return {!Function} 19 | */ 20 | const createQueueMicrotaskViaPromises = () => { 21 | return (microtask) => { 22 | Promise.resolve().then(microtask); 23 | }; 24 | }; 25 | 26 | /** 27 | * @return {!Function} 28 | */ 29 | const createQueueMicrotaskViaMutationObserver = () => { 30 | let i = 0; 31 | let microtaskQueue = []; 32 | const observer = new MutationObserver(() => { 33 | microtaskQueue.forEach((microtask) => microtask()); 34 | microtaskQueue = []; 35 | }); 36 | const node = document.createTextNode(''); 37 | observer.observe(node, {characterData: true}); 38 | 39 | return (microtask) => { 40 | microtaskQueue.push(microtask); 41 | 42 | // Trigger a mutation observer callback, which is a microtask. 43 | node.data = String(++i % 2); 44 | }; 45 | }; 46 | 47 | /** 48 | * Queues a function to be run in the next microtask. If the browser supports 49 | * Promises, those are used. Otherwise it falls back to MutationObserver. 50 | * Note: since Promise polyfills are popular but not all support microtasks, 51 | * we check for native implementation rather than a polyfill. 52 | * @private 53 | * @param {!Function} microtask 54 | */ 55 | export const queueMicrotask = typeof Promise === 'function' && 56 | Promise.toString().indexOf('[native code]') > -1 ? 57 | createQueueMicrotaskViaPromises() : 58 | createQueueMicrotaskViaMutationObserver(); 59 | -------------------------------------------------------------------------------- /package-lock.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "idlize", 3 | "version": "0.1.0", 4 | "lockfileVersion": 1, 5 | "requires": true, 6 | "dependencies": { 7 | "@babel/code-frame": { 8 | "version": "7.0.0", 9 | "resolved": "https://registry.npmjs.org/@babel/code-frame/-/code-frame-7.0.0.tgz", 10 | "integrity": "sha512-OfC2uemaknXr87bdLUkWog7nYuliM9Ij5HUcajsVcMCpQrcLmtxRbVFTIqmcSkSeYRBFBRxs2FiUqFJDLdiebA==", 11 | "dev": true, 12 | "requires": { 13 | "@babel/highlight": "^7.0.0" 14 | } 15 | }, 16 | "@babel/highlight": { 17 | "version": "7.0.0", 18 | "resolved": "https://registry.npmjs.org/@babel/highlight/-/highlight-7.0.0.tgz", 19 | "integrity": "sha512-UFMC4ZeFC48Tpvj7C8UgLvtkaUuovQX+5xNWrsIoMG8o2z+XFKjKaN9iVmS84dPwVN00W4wPmqvYoZF3EGAsfw==", 20 | "dev": true, 21 | "requires": { 22 | "chalk": "^2.0.0", 23 | "esutils": "^2.0.2", 24 | "js-tokens": "^4.0.0" 25 | } 26 | }, 27 | "acorn": { 28 | "version": "5.7.3", 29 | "resolved": "https://registry.npmjs.org/acorn/-/acorn-5.7.3.tgz", 30 | "integrity": "sha512-T/zvzYRfbVojPWahDsE5evJdHb3oJoQfFbsrKM7w5Zcs++Tr257tia3BmMP8XYVjp1S9RZXQMh7gao96BlqZOw==", 31 | "dev": true 32 | }, 33 | "acorn-jsx": { 34 | "version": "4.1.1", 35 | "resolved": "https://registry.npmjs.org/acorn-jsx/-/acorn-jsx-4.1.1.tgz", 36 | "integrity": "sha512-JY+iV6r+cO21KtntVvFkD+iqjtdpRUpGqKWgfkCdZq1R+kbreEl8EcdcJR4SmiIgsIQT33s6QzheQ9a275Q8xw==", 37 | "dev": true, 38 | "requires": { 39 | "acorn": "^5.0.3" 40 | } 41 | }, 42 | "ajv": { 43 | "version": "6.5.3", 44 | "resolved": "https://registry.npmjs.org/ajv/-/ajv-6.5.3.tgz", 45 | "integrity": "sha512-LqZ9wY+fx3UMiiPd741yB2pj3hhil+hQc8taf4o2QGRFpWgZ2V5C8HA165DY9sS3fJwsk7uT7ZlFEyC3Ig3lLg==", 46 | "dev": true, 47 | "requires": { 48 | "fast-deep-equal": "^2.0.1", 49 | "fast-json-stable-stringify": "^2.0.0", 50 | "json-schema-traverse": "^0.4.1", 51 | "uri-js": "^4.2.2" 52 | } 53 | }, 54 | "ajv-keywords": { 55 | "version": "3.2.0", 56 | "resolved": "https://registry.npmjs.org/ajv-keywords/-/ajv-keywords-3.2.0.tgz", 57 | "integrity": "sha1-6GuBnGAs+IIa1jdBNpjx3sAhhHo=", 58 | "dev": true 59 | }, 60 | "ansi-escapes": { 61 | "version": "3.1.0", 62 | "resolved": "https://registry.npmjs.org/ansi-escapes/-/ansi-escapes-3.1.0.tgz", 63 | "integrity": "sha512-UgAb8H9D41AQnu/PbWlCofQVcnV4Gs2bBJi9eZPxfU/hgglFh3SMDMENRIqdr7H6XFnXdoknctFByVsCOotTVw==", 64 | "dev": true 65 | }, 66 | "ansi-regex": { 67 | "version": "3.0.0", 68 | "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-3.0.0.tgz", 69 | "integrity": "sha1-7QMXwyIGT3lGbAKWa922Bas32Zg=", 70 | "dev": true 71 | }, 72 | "ansi-styles": { 73 | "version": "3.2.1", 74 | "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-3.2.1.tgz", 75 | "integrity": "sha512-VT0ZI6kZRdTh8YyJw3SMbYm/u+NqfsAxEpWO0Pf9sq8/e94WxxOpPKx9FR1FlyCtOVDNOQ+8ntlqFxiRc+r5qA==", 76 | "dev": true, 77 | "requires": { 78 | "color-convert": "^1.9.0" 79 | } 80 | }, 81 | "argparse": { 82 | "version": "1.0.10", 83 | "resolved": "https://registry.npmjs.org/argparse/-/argparse-1.0.10.tgz", 84 | "integrity": "sha512-o5Roy6tNG4SL/FOkCAN6RzjiakZS25RLYFrcMttJqbdd8BWrnA+fGz57iN5Pb06pvBGvl5gQ0B48dJlslXvoTg==", 85 | "dev": true, 86 | "requires": { 87 | "sprintf-js": "~1.0.2" 88 | } 89 | }, 90 | "array-union": { 91 | "version": "1.0.2", 92 | "resolved": "https://registry.npmjs.org/array-union/-/array-union-1.0.2.tgz", 93 | "integrity": "sha1-mjRBDk9OPaI96jdb5b5w8kd47Dk=", 94 | "dev": true, 95 | "requires": { 96 | "array-uniq": "^1.0.1" 97 | } 98 | }, 99 | "array-uniq": { 100 | "version": "1.0.3", 101 | "resolved": "https://registry.npmjs.org/array-uniq/-/array-uniq-1.0.3.tgz", 102 | "integrity": "sha1-r2rId6Jcx/dOBYiUdThY39sk/bY=", 103 | "dev": true 104 | }, 105 | "arrify": { 106 | "version": "1.0.1", 107 | "resolved": "https://registry.npmjs.org/arrify/-/arrify-1.0.1.tgz", 108 | "integrity": "sha1-iYUI2iIm84DfkEcoRWhJwVAaSw0=", 109 | "dev": true 110 | }, 111 | "balanced-match": { 112 | "version": "1.0.0", 113 | "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.0.tgz", 114 | "integrity": "sha1-ibTRmasr7kneFk6gK4nORi1xt2c=", 115 | "dev": true 116 | }, 117 | "brace-expansion": { 118 | "version": "1.1.11", 119 | "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz", 120 | "integrity": "sha512-iCuPHDFgrHX7H2vEI/5xpz07zSHB00TpugqhmYtVmMO6518mCuRMoOYFldEBl0g187ufozdaHgWKcYFb61qGiA==", 121 | "dev": true, 122 | "requires": { 123 | "balanced-match": "^1.0.0", 124 | "concat-map": "0.0.1" 125 | } 126 | }, 127 | "caller-path": { 128 | "version": "0.1.0", 129 | "resolved": "https://registry.npmjs.org/caller-path/-/caller-path-0.1.0.tgz", 130 | "integrity": "sha1-lAhe9jWB7NPaqSREqP6U6CV3dR8=", 131 | "dev": true, 132 | "requires": { 133 | "callsites": "^0.2.0" 134 | } 135 | }, 136 | "callsites": { 137 | "version": "0.2.0", 138 | "resolved": "https://registry.npmjs.org/callsites/-/callsites-0.2.0.tgz", 139 | "integrity": "sha1-r6uWJikQp/M8GaV3WCXGnzTjUMo=", 140 | "dev": true 141 | }, 142 | "chalk": { 143 | "version": "2.4.1", 144 | "resolved": "https://registry.npmjs.org/chalk/-/chalk-2.4.1.tgz", 145 | "integrity": "sha512-ObN6h1v2fTJSmUXoS3nMQ92LbDK9be4TV+6G+omQlGJFdcUX5heKi1LZ1YnRMIgwTLEj3E24bT6tYni50rlCfQ==", 146 | "dev": true, 147 | "requires": { 148 | "ansi-styles": "^3.2.1", 149 | "escape-string-regexp": "^1.0.5", 150 | "supports-color": "^5.3.0" 151 | } 152 | }, 153 | "chardet": { 154 | "version": "0.7.0", 155 | "resolved": "https://registry.npmjs.org/chardet/-/chardet-0.7.0.tgz", 156 | "integrity": "sha512-mT8iDcrh03qDGRRmoA2hmBJnxpllMR+0/0qlzjqZES6NdiWDcZkCNAk4rPFZ9Q85r27unkiNNg8ZOiwZXBHwcA==", 157 | "dev": true 158 | }, 159 | "circular-json": { 160 | "version": "0.3.3", 161 | "resolved": "https://registry.npmjs.org/circular-json/-/circular-json-0.3.3.tgz", 162 | "integrity": "sha512-UZK3NBx2Mca+b5LsG7bY183pHWt5Y1xts4P3Pz7ENTwGVnJOUWbRb3ocjvX7hx9tq/yTAdclXm9sZ38gNuem4A==", 163 | "dev": true 164 | }, 165 | "cli-cursor": { 166 | "version": "2.1.0", 167 | "resolved": "https://registry.npmjs.org/cli-cursor/-/cli-cursor-2.1.0.tgz", 168 | "integrity": "sha1-s12sN2R5+sw+lHR9QdDQ9SOP/LU=", 169 | "dev": true, 170 | "requires": { 171 | "restore-cursor": "^2.0.0" 172 | } 173 | }, 174 | "cli-width": { 175 | "version": "2.2.0", 176 | "resolved": "https://registry.npmjs.org/cli-width/-/cli-width-2.2.0.tgz", 177 | "integrity": "sha1-/xnt6Kml5XkyQUewwR8PvLq+1jk=", 178 | "dev": true 179 | }, 180 | "color-convert": { 181 | "version": "1.9.3", 182 | "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-1.9.3.tgz", 183 | "integrity": "sha512-QfAUtd+vFdAtFQcC8CCyYt1fYWxSqAiK2cSD6zDB8N3cpsEBAvRxp9zOGg6G/SHHJYAT88/az/IuDGALsNVbGg==", 184 | "dev": true, 185 | "requires": { 186 | "color-name": "1.1.3" 187 | } 188 | }, 189 | "color-name": { 190 | "version": "1.1.3", 191 | "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.3.tgz", 192 | "integrity": "sha1-p9BVi9icQveV3UIyj3QIMcpTvCU=", 193 | "dev": true 194 | }, 195 | "concat-map": { 196 | "version": "0.0.1", 197 | "resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz", 198 | "integrity": "sha1-2Klr13/Wjfd5OnMDajug1UBdR3s=", 199 | "dev": true 200 | }, 201 | "cross-spawn": { 202 | "version": "6.0.5", 203 | "resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-6.0.5.tgz", 204 | "integrity": "sha512-eTVLrBSt7fjbDygz805pMnstIs2VTBNkRm0qxZd+M7A5XDdxVRWO5MxGBXZhjY4cqLYLdtrGqRf8mBPmzwSpWQ==", 205 | "dev": true, 206 | "requires": { 207 | "nice-try": "^1.0.4", 208 | "path-key": "^2.0.1", 209 | "semver": "^5.5.0", 210 | "shebang-command": "^1.2.0", 211 | "which": "^1.2.9" 212 | } 213 | }, 214 | "debug": { 215 | "version": "3.2.5", 216 | "resolved": "https://registry.npmjs.org/debug/-/debug-3.2.5.tgz", 217 | "integrity": "sha512-D61LaDQPQkxJ5AUM2mbSJRbPkNs/TmdmOeLAi1hgDkpDfIfetSrjmWhccwtuResSwMbACjx/xXQofvM9CE/aeg==", 218 | "dev": true, 219 | "requires": { 220 | "ms": "^2.1.1" 221 | } 222 | }, 223 | "deep-is": { 224 | "version": "0.1.3", 225 | "resolved": "https://registry.npmjs.org/deep-is/-/deep-is-0.1.3.tgz", 226 | "integrity": "sha1-s2nW+128E+7PUk+RsHD+7cNXzzQ=", 227 | "dev": true 228 | }, 229 | "del": { 230 | "version": "2.2.2", 231 | "resolved": "https://registry.npmjs.org/del/-/del-2.2.2.tgz", 232 | "integrity": "sha1-wSyYHQZ4RshLyvhiz/kw2Qf/0ag=", 233 | "dev": true, 234 | "requires": { 235 | "globby": "^5.0.0", 236 | "is-path-cwd": "^1.0.0", 237 | "is-path-in-cwd": "^1.0.0", 238 | "object-assign": "^4.0.1", 239 | "pify": "^2.0.0", 240 | "pinkie-promise": "^2.0.0", 241 | "rimraf": "^2.2.8" 242 | } 243 | }, 244 | "doctrine": { 245 | "version": "2.1.0", 246 | "resolved": "https://registry.npmjs.org/doctrine/-/doctrine-2.1.0.tgz", 247 | "integrity": "sha512-35mSku4ZXK0vfCuHEDAwt55dg2jNajHZ1odvF+8SSr82EsZY4QmXfuWso8oEd8zRhVObSN18aM0CjSdoBX7zIw==", 248 | "dev": true, 249 | "requires": { 250 | "esutils": "^2.0.2" 251 | } 252 | }, 253 | "escape-string-regexp": { 254 | "version": "1.0.5", 255 | "resolved": "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-1.0.5.tgz", 256 | "integrity": "sha1-G2HAViGQqN/2rjuyzwIAyhMLhtQ=", 257 | "dev": true 258 | }, 259 | "eslint": { 260 | "version": "5.5.0", 261 | "resolved": "https://registry.npmjs.org/eslint/-/eslint-5.5.0.tgz", 262 | "integrity": "sha512-m+az4vYehIJgl1Z0gb25KnFXeqQRdNreYsei1jdvkd9bB+UNQD3fsuiC2AWSQ56P+/t++kFSINZXFbfai+krOw==", 263 | "dev": true, 264 | "requires": { 265 | "@babel/code-frame": "^7.0.0", 266 | "ajv": "^6.5.3", 267 | "chalk": "^2.1.0", 268 | "cross-spawn": "^6.0.5", 269 | "debug": "^3.1.0", 270 | "doctrine": "^2.1.0", 271 | "eslint-scope": "^4.0.0", 272 | "eslint-utils": "^1.3.1", 273 | "eslint-visitor-keys": "^1.0.0", 274 | "espree": "^4.0.0", 275 | "esquery": "^1.0.1", 276 | "esutils": "^2.0.2", 277 | "file-entry-cache": "^2.0.0", 278 | "functional-red-black-tree": "^1.0.1", 279 | "glob": "^7.1.2", 280 | "globals": "^11.7.0", 281 | "ignore": "^4.0.6", 282 | "imurmurhash": "^0.1.4", 283 | "inquirer": "^6.1.0", 284 | "is-resolvable": "^1.1.0", 285 | "js-yaml": "^3.12.0", 286 | "json-stable-stringify-without-jsonify": "^1.0.1", 287 | "levn": "^0.3.0", 288 | "lodash": "^4.17.5", 289 | "minimatch": "^3.0.4", 290 | "mkdirp": "^0.5.1", 291 | "natural-compare": "^1.4.0", 292 | "optionator": "^0.8.2", 293 | "path-is-inside": "^1.0.2", 294 | "pluralize": "^7.0.0", 295 | "progress": "^2.0.0", 296 | "regexpp": "^2.0.0", 297 | "require-uncached": "^1.0.3", 298 | "semver": "^5.5.1", 299 | "strip-ansi": "^4.0.0", 300 | "strip-json-comments": "^2.0.1", 301 | "table": "^4.0.3", 302 | "text-table": "^0.2.0" 303 | } 304 | }, 305 | "eslint-config-google": { 306 | "version": "0.10.0", 307 | "resolved": "https://registry.npmjs.org/eslint-config-google/-/eslint-config-google-0.10.0.tgz", 308 | "integrity": "sha512-PGlMufI13kljog4HlDkwtyqJ7ZZFOcl0ppEvhDoE1lq+8+nMe0lQs0WIZrXpQJhwxhii3SZuCHW2g/weS6Xpyw==", 309 | "dev": true 310 | }, 311 | "eslint-scope": { 312 | "version": "4.0.0", 313 | "resolved": "https://registry.npmjs.org/eslint-scope/-/eslint-scope-4.0.0.tgz", 314 | "integrity": "sha512-1G6UTDi7Jc1ELFwnR58HV4fK9OQK4S6N985f166xqXxpjU6plxFISJa2Ba9KCQuFa8RCnj/lSFJbHo7UFDBnUA==", 315 | "dev": true, 316 | "requires": { 317 | "esrecurse": "^4.1.0", 318 | "estraverse": "^4.1.1" 319 | } 320 | }, 321 | "eslint-utils": { 322 | "version": "1.3.1", 323 | "resolved": "https://registry.npmjs.org/eslint-utils/-/eslint-utils-1.3.1.tgz", 324 | "integrity": "sha512-Z7YjnIldX+2XMcjr7ZkgEsOj/bREONV60qYeB/bjMAqqqZ4zxKyWX+BOUkdmRmA9riiIPVvo5x86m5elviOk0Q==", 325 | "dev": true 326 | }, 327 | "eslint-visitor-keys": { 328 | "version": "1.0.0", 329 | "resolved": "https://registry.npmjs.org/eslint-visitor-keys/-/eslint-visitor-keys-1.0.0.tgz", 330 | "integrity": "sha512-qzm/XxIbxm/FHyH341ZrbnMUpe+5Bocte9xkmFMzPMjRaZMcXww+MpBptFvtU+79L362nqiLhekCxCxDPaUMBQ==", 331 | "dev": true 332 | }, 333 | "espree": { 334 | "version": "4.0.0", 335 | "resolved": "https://registry.npmjs.org/espree/-/espree-4.0.0.tgz", 336 | "integrity": "sha512-kapdTCt1bjmspxStVKX6huolXVV5ZfyZguY1lcfhVVZstce3bqxH9mcLzNn3/mlgW6wQ732+0fuG9v7h0ZQoKg==", 337 | "dev": true, 338 | "requires": { 339 | "acorn": "^5.6.0", 340 | "acorn-jsx": "^4.1.1" 341 | } 342 | }, 343 | "esprima": { 344 | "version": "4.0.1", 345 | "resolved": "https://registry.npmjs.org/esprima/-/esprima-4.0.1.tgz", 346 | "integrity": "sha512-eGuFFw7Upda+g4p+QHvnW0RyTX/SVeJBDM/gCtMARO0cLuT2HcEKnTPvhjV6aGeqrCB/sbNop0Kszm0jsaWU4A==", 347 | "dev": true 348 | }, 349 | "esquery": { 350 | "version": "1.0.1", 351 | "resolved": "https://registry.npmjs.org/esquery/-/esquery-1.0.1.tgz", 352 | "integrity": "sha512-SmiyZ5zIWH9VM+SRUReLS5Q8a7GxtRdxEBVZpm98rJM7Sb+A9DVCndXfkeFUd3byderg+EbDkfnevfCwynWaNA==", 353 | "dev": true, 354 | "requires": { 355 | "estraverse": "^4.0.0" 356 | } 357 | }, 358 | "esrecurse": { 359 | "version": "4.2.1", 360 | "resolved": "https://registry.npmjs.org/esrecurse/-/esrecurse-4.2.1.tgz", 361 | "integrity": "sha512-64RBB++fIOAXPw3P9cy89qfMlvZEXZkqqJkjqqXIvzP5ezRZjW+lPWjw35UX/3EhUPFYbg5ER4JYgDw4007/DQ==", 362 | "dev": true, 363 | "requires": { 364 | "estraverse": "^4.1.0" 365 | } 366 | }, 367 | "estraverse": { 368 | "version": "4.2.0", 369 | "resolved": "https://registry.npmjs.org/estraverse/-/estraverse-4.2.0.tgz", 370 | "integrity": "sha1-De4/7TH81GlhjOc0IJn8GvoL2xM=", 371 | "dev": true 372 | }, 373 | "esutils": { 374 | "version": "2.0.2", 375 | "resolved": "https://registry.npmjs.org/esutils/-/esutils-2.0.2.tgz", 376 | "integrity": "sha1-Cr9PHKpbyx96nYrMbepPqqBLrJs=", 377 | "dev": true 378 | }, 379 | "external-editor": { 380 | "version": "3.0.3", 381 | "resolved": "https://registry.npmjs.org/external-editor/-/external-editor-3.0.3.tgz", 382 | "integrity": "sha512-bn71H9+qWoOQKyZDo25mOMVpSmXROAsTJVVVYzrrtol3d4y+AsKjf4Iwl2Q+IuT0kFSQ1qo166UuIwqYq7mGnA==", 383 | "dev": true, 384 | "requires": { 385 | "chardet": "^0.7.0", 386 | "iconv-lite": "^0.4.24", 387 | "tmp": "^0.0.33" 388 | } 389 | }, 390 | "fast-deep-equal": { 391 | "version": "2.0.1", 392 | "resolved": "https://registry.npmjs.org/fast-deep-equal/-/fast-deep-equal-2.0.1.tgz", 393 | "integrity": "sha1-ewUhjd+WZ79/Nwv3/bLLFf3Qqkk=", 394 | "dev": true 395 | }, 396 | "fast-json-stable-stringify": { 397 | "version": "2.0.0", 398 | "resolved": "https://registry.npmjs.org/fast-json-stable-stringify/-/fast-json-stable-stringify-2.0.0.tgz", 399 | "integrity": "sha1-1RQsDK7msRifh9OnYREGT4bIu/I=", 400 | "dev": true 401 | }, 402 | "fast-levenshtein": { 403 | "version": "2.0.6", 404 | "resolved": "https://registry.npmjs.org/fast-levenshtein/-/fast-levenshtein-2.0.6.tgz", 405 | "integrity": "sha1-PYpcZog6FqMMqGQ+hR8Zuqd5eRc=", 406 | "dev": true 407 | }, 408 | "figures": { 409 | "version": "2.0.0", 410 | "resolved": "https://registry.npmjs.org/figures/-/figures-2.0.0.tgz", 411 | "integrity": "sha1-OrGi0qYsi/tDGgyUy3l6L84nyWI=", 412 | "dev": true, 413 | "requires": { 414 | "escape-string-regexp": "^1.0.5" 415 | } 416 | }, 417 | "file-entry-cache": { 418 | "version": "2.0.0", 419 | "resolved": "https://registry.npmjs.org/file-entry-cache/-/file-entry-cache-2.0.0.tgz", 420 | "integrity": "sha1-w5KZDD5oR4PYOLjISkXYoEhFg2E=", 421 | "dev": true, 422 | "requires": { 423 | "flat-cache": "^1.2.1", 424 | "object-assign": "^4.0.1" 425 | } 426 | }, 427 | "flat-cache": { 428 | "version": "1.3.0", 429 | "resolved": "https://registry.npmjs.org/flat-cache/-/flat-cache-1.3.0.tgz", 430 | "integrity": "sha1-0wMLMrOBVPTjt+nHCfSQ9++XxIE=", 431 | "dev": true, 432 | "requires": { 433 | "circular-json": "^0.3.1", 434 | "del": "^2.0.2", 435 | "graceful-fs": "^4.1.2", 436 | "write": "^0.2.1" 437 | } 438 | }, 439 | "fs.realpath": { 440 | "version": "1.0.0", 441 | "resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz", 442 | "integrity": "sha1-FQStJSMVjKpA20onh8sBQRmU6k8=", 443 | "dev": true 444 | }, 445 | "functional-red-black-tree": { 446 | "version": "1.0.1", 447 | "resolved": "https://registry.npmjs.org/functional-red-black-tree/-/functional-red-black-tree-1.0.1.tgz", 448 | "integrity": "sha1-GwqzvVU7Kg1jmdKcDj6gslIHgyc=", 449 | "dev": true 450 | }, 451 | "glob": { 452 | "version": "7.1.3", 453 | "resolved": "https://registry.npmjs.org/glob/-/glob-7.1.3.tgz", 454 | "integrity": "sha512-vcfuiIxogLV4DlGBHIUOwI0IbrJ8HWPc4MU7HzviGeNho/UJDfi6B5p3sHeWIQ0KGIU0Jpxi5ZHxemQfLkkAwQ==", 455 | "dev": true, 456 | "requires": { 457 | "fs.realpath": "^1.0.0", 458 | "inflight": "^1.0.4", 459 | "inherits": "2", 460 | "minimatch": "^3.0.4", 461 | "once": "^1.3.0", 462 | "path-is-absolute": "^1.0.0" 463 | } 464 | }, 465 | "globals": { 466 | "version": "11.7.0", 467 | "resolved": "https://registry.npmjs.org/globals/-/globals-11.7.0.tgz", 468 | "integrity": "sha512-K8BNSPySfeShBQXsahYB/AbbWruVOTyVpgoIDnl8odPpeSfP2J5QO2oLFFdl2j7GfDCtZj2bMKar2T49itTPCg==", 469 | "dev": true 470 | }, 471 | "globby": { 472 | "version": "5.0.0", 473 | "resolved": "https://registry.npmjs.org/globby/-/globby-5.0.0.tgz", 474 | "integrity": "sha1-69hGZ8oNuzMLmbz8aOrCvFQ3Dg0=", 475 | "dev": true, 476 | "requires": { 477 | "array-union": "^1.0.1", 478 | "arrify": "^1.0.0", 479 | "glob": "^7.0.3", 480 | "object-assign": "^4.0.1", 481 | "pify": "^2.0.0", 482 | "pinkie-promise": "^2.0.0" 483 | } 484 | }, 485 | "graceful-fs": { 486 | "version": "4.1.11", 487 | "resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.1.11.tgz", 488 | "integrity": "sha1-Dovf5NHduIVNZOBOp8AOKgJuVlg=", 489 | "dev": true 490 | }, 491 | "has-flag": { 492 | "version": "3.0.0", 493 | "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-3.0.0.tgz", 494 | "integrity": "sha1-tdRU3CGZriJWmfNGfloH87lVuv0=", 495 | "dev": true 496 | }, 497 | "iconv-lite": { 498 | "version": "0.4.24", 499 | "resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.4.24.tgz", 500 | "integrity": "sha512-v3MXnZAcvnywkTUEZomIActle7RXXeedOR31wwl7VlyoXO4Qi9arvSenNQWne1TcRwhCL1HwLI21bEqdpj8/rA==", 501 | "dev": true, 502 | "requires": { 503 | "safer-buffer": ">= 2.1.2 < 3" 504 | } 505 | }, 506 | "ignore": { 507 | "version": "4.0.6", 508 | "resolved": "https://registry.npmjs.org/ignore/-/ignore-4.0.6.tgz", 509 | "integrity": "sha512-cyFDKrqc/YdcWFniJhzI42+AzS+gNwmUzOSFcRCQYwySuBBBy/KjuxWLZ/FHEH6Moq1NizMOBWyTcv8O4OZIMg==", 510 | "dev": true 511 | }, 512 | "imurmurhash": { 513 | "version": "0.1.4", 514 | "resolved": "https://registry.npmjs.org/imurmurhash/-/imurmurhash-0.1.4.tgz", 515 | "integrity": "sha1-khi5srkoojixPcT7a21XbyMUU+o=", 516 | "dev": true 517 | }, 518 | "inflight": { 519 | "version": "1.0.6", 520 | "resolved": "https://registry.npmjs.org/inflight/-/inflight-1.0.6.tgz", 521 | "integrity": "sha1-Sb1jMdfQLQwJvJEKEHW6gWW1bfk=", 522 | "dev": true, 523 | "requires": { 524 | "once": "^1.3.0", 525 | "wrappy": "1" 526 | } 527 | }, 528 | "inherits": { 529 | "version": "2.0.3", 530 | "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.3.tgz", 531 | "integrity": "sha1-Yzwsg+PaQqUC9SRmAiSA9CCCYd4=", 532 | "dev": true 533 | }, 534 | "inquirer": { 535 | "version": "6.2.0", 536 | "resolved": "https://registry.npmjs.org/inquirer/-/inquirer-6.2.0.tgz", 537 | "integrity": "sha512-QIEQG4YyQ2UYZGDC4srMZ7BjHOmNk1lR2JQj5UknBapklm6WHA+VVH7N+sUdX3A7NeCfGF8o4X1S3Ao7nAcIeg==", 538 | "dev": true, 539 | "requires": { 540 | "ansi-escapes": "^3.0.0", 541 | "chalk": "^2.0.0", 542 | "cli-cursor": "^2.1.0", 543 | "cli-width": "^2.0.0", 544 | "external-editor": "^3.0.0", 545 | "figures": "^2.0.0", 546 | "lodash": "^4.17.10", 547 | "mute-stream": "0.0.7", 548 | "run-async": "^2.2.0", 549 | "rxjs": "^6.1.0", 550 | "string-width": "^2.1.0", 551 | "strip-ansi": "^4.0.0", 552 | "through": "^2.3.6" 553 | } 554 | }, 555 | "is-fullwidth-code-point": { 556 | "version": "2.0.0", 557 | "resolved": "https://registry.npmjs.org/is-fullwidth-code-point/-/is-fullwidth-code-point-2.0.0.tgz", 558 | "integrity": "sha1-o7MKXE8ZkYMWeqq5O+764937ZU8=", 559 | "dev": true 560 | }, 561 | "is-path-cwd": { 562 | "version": "1.0.0", 563 | "resolved": "https://registry.npmjs.org/is-path-cwd/-/is-path-cwd-1.0.0.tgz", 564 | "integrity": "sha1-0iXsIxMuie3Tj9p2dHLmLmXxEG0=", 565 | "dev": true 566 | }, 567 | "is-path-in-cwd": { 568 | "version": "1.0.1", 569 | "resolved": "https://registry.npmjs.org/is-path-in-cwd/-/is-path-in-cwd-1.0.1.tgz", 570 | "integrity": "sha512-FjV1RTW48E7CWM7eE/J2NJvAEEVektecDBVBE5Hh3nM1Jd0kvhHtX68Pr3xsDf857xt3Y4AkwVULK1Vku62aaQ==", 571 | "dev": true, 572 | "requires": { 573 | "is-path-inside": "^1.0.0" 574 | } 575 | }, 576 | "is-path-inside": { 577 | "version": "1.0.1", 578 | "resolved": "https://registry.npmjs.org/is-path-inside/-/is-path-inside-1.0.1.tgz", 579 | "integrity": "sha1-jvW33lBDej/cprToZe96pVy0gDY=", 580 | "dev": true, 581 | "requires": { 582 | "path-is-inside": "^1.0.1" 583 | } 584 | }, 585 | "is-promise": { 586 | "version": "2.1.0", 587 | "resolved": "https://registry.npmjs.org/is-promise/-/is-promise-2.1.0.tgz", 588 | "integrity": "sha1-eaKp7OfwlugPNtKy87wWwf9L8/o=", 589 | "dev": true 590 | }, 591 | "is-resolvable": { 592 | "version": "1.1.0", 593 | "resolved": "https://registry.npmjs.org/is-resolvable/-/is-resolvable-1.1.0.tgz", 594 | "integrity": "sha512-qgDYXFSR5WvEfuS5dMj6oTMEbrrSaM0CrFk2Yiq/gXnBvD9pMa2jGXxyhGLfvhZpuMZe18CJpFxAt3CRs42NMg==", 595 | "dev": true 596 | }, 597 | "isexe": { 598 | "version": "2.0.0", 599 | "resolved": "https://registry.npmjs.org/isexe/-/isexe-2.0.0.tgz", 600 | "integrity": "sha1-6PvzdNxVb/iUehDcsFctYz8s+hA=", 601 | "dev": true 602 | }, 603 | "js-tokens": { 604 | "version": "4.0.0", 605 | "resolved": "https://registry.npmjs.org/js-tokens/-/js-tokens-4.0.0.tgz", 606 | "integrity": "sha512-RdJUflcE3cUzKiMqQgsCu06FPu9UdIJO0beYbPhHN4k6apgJtifcoCtT9bcxOpYBtpD2kCM6Sbzg4CausW/PKQ==", 607 | "dev": true 608 | }, 609 | "js-yaml": { 610 | "version": "3.12.0", 611 | "resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-3.12.0.tgz", 612 | "integrity": "sha512-PIt2cnwmPfL4hKNwqeiuz4bKfnzHTBv6HyVgjahA6mPLwPDzjDWrplJBMjHUFxku/N3FlmrbyPclad+I+4mJ3A==", 613 | "dev": true, 614 | "requires": { 615 | "argparse": "^1.0.7", 616 | "esprima": "^4.0.0" 617 | } 618 | }, 619 | "json-schema-traverse": { 620 | "version": "0.4.1", 621 | "resolved": "https://registry.npmjs.org/json-schema-traverse/-/json-schema-traverse-0.4.1.tgz", 622 | "integrity": "sha512-xbbCH5dCYU5T8LcEhhuh7HJ88HXuW3qsI3Y0zOZFKfZEHcpWiHU/Jxzk629Brsab/mMiHQti9wMP+845RPe3Vg==", 623 | "dev": true 624 | }, 625 | "json-stable-stringify-without-jsonify": { 626 | "version": "1.0.1", 627 | "resolved": "https://registry.npmjs.org/json-stable-stringify-without-jsonify/-/json-stable-stringify-without-jsonify-1.0.1.tgz", 628 | "integrity": "sha1-nbe1lJatPzz+8wp1FC0tkwrXJlE=", 629 | "dev": true 630 | }, 631 | "levn": { 632 | "version": "0.3.0", 633 | "resolved": "https://registry.npmjs.org/levn/-/levn-0.3.0.tgz", 634 | "integrity": "sha1-OwmSTt+fCDwEkP3UwLxEIeBHZO4=", 635 | "dev": true, 636 | "requires": { 637 | "prelude-ls": "~1.1.2", 638 | "type-check": "~0.3.2" 639 | } 640 | }, 641 | "lodash": { 642 | "version": "4.17.10", 643 | "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.10.tgz", 644 | "integrity": "sha512-UejweD1pDoXu+AD825lWwp4ZGtSwgnpZxb3JDViD7StjQz+Nb/6l093lx4OQ0foGWNRoc19mWy7BzL+UAK2iVg==", 645 | "dev": true 646 | }, 647 | "mimic-fn": { 648 | "version": "1.2.0", 649 | "resolved": "https://registry.npmjs.org/mimic-fn/-/mimic-fn-1.2.0.tgz", 650 | "integrity": "sha512-jf84uxzwiuiIVKiOLpfYk7N46TSy8ubTonmneY9vrpHNAnp0QBt2BxWV9dO3/j+BoVAb+a5G6YDPW3M5HOdMWQ==", 651 | "dev": true 652 | }, 653 | "minimatch": { 654 | "version": "3.0.4", 655 | "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.0.4.tgz", 656 | "integrity": "sha512-yJHVQEhyqPLUTgt9B83PXu6W3rx4MvvHvSUvToogpwoGDOUQ+yDrR0HRot+yOCdCO7u4hX3pWft6kWBBcqh0UA==", 657 | "dev": true, 658 | "requires": { 659 | "brace-expansion": "^1.1.7" 660 | } 661 | }, 662 | "minimist": { 663 | "version": "0.0.8", 664 | "resolved": "http://registry.npmjs.org/minimist/-/minimist-0.0.8.tgz", 665 | "integrity": "sha1-hX/Kv8M5fSYluCKCYuhqp6ARsF0=", 666 | "dev": true 667 | }, 668 | "mkdirp": { 669 | "version": "0.5.1", 670 | "resolved": "http://registry.npmjs.org/mkdirp/-/mkdirp-0.5.1.tgz", 671 | "integrity": "sha1-MAV0OOrGz3+MR2fzhkjWaX11yQM=", 672 | "dev": true, 673 | "requires": { 674 | "minimist": "0.0.8" 675 | } 676 | }, 677 | "ms": { 678 | "version": "2.1.1", 679 | "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.1.tgz", 680 | "integrity": "sha512-tgp+dl5cGk28utYktBsrFqA7HKgrhgPsg6Z/EfhWI4gl1Hwq8B/GmY/0oXZ6nF8hDVesS/FpnYaD/kOWhYQvyg==", 681 | "dev": true 682 | }, 683 | "mute-stream": { 684 | "version": "0.0.7", 685 | "resolved": "https://registry.npmjs.org/mute-stream/-/mute-stream-0.0.7.tgz", 686 | "integrity": "sha1-MHXOk7whuPq0PhvE2n6BFe0ee6s=", 687 | "dev": true 688 | }, 689 | "natural-compare": { 690 | "version": "1.4.0", 691 | "resolved": "https://registry.npmjs.org/natural-compare/-/natural-compare-1.4.0.tgz", 692 | "integrity": "sha1-Sr6/7tdUHywnrPspvbvRXI1bpPc=", 693 | "dev": true 694 | }, 695 | "nice-try": { 696 | "version": "1.0.5", 697 | "resolved": "https://registry.npmjs.org/nice-try/-/nice-try-1.0.5.tgz", 698 | "integrity": "sha512-1nh45deeb5olNY7eX82BkPO7SSxR5SSYJiPTrTdFUVYwAl8CKMA5N9PjTYkHiRjisVcxcQ1HXdLhx2qxxJzLNQ==", 699 | "dev": true 700 | }, 701 | "object-assign": { 702 | "version": "4.1.1", 703 | "resolved": "https://registry.npmjs.org/object-assign/-/object-assign-4.1.1.tgz", 704 | "integrity": "sha1-IQmtx5ZYh8/AXLvUQsrIv7s2CGM=", 705 | "dev": true 706 | }, 707 | "once": { 708 | "version": "1.4.0", 709 | "resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz", 710 | "integrity": "sha1-WDsap3WWHUsROsF9nFC6753Xa9E=", 711 | "dev": true, 712 | "requires": { 713 | "wrappy": "1" 714 | } 715 | }, 716 | "onetime": { 717 | "version": "2.0.1", 718 | "resolved": "https://registry.npmjs.org/onetime/-/onetime-2.0.1.tgz", 719 | "integrity": "sha1-BnQoIw/WdEOyeUsiu6UotoZ5YtQ=", 720 | "dev": true, 721 | "requires": { 722 | "mimic-fn": "^1.0.0" 723 | } 724 | }, 725 | "optionator": { 726 | "version": "0.8.2", 727 | "resolved": "https://registry.npmjs.org/optionator/-/optionator-0.8.2.tgz", 728 | "integrity": "sha1-NkxeQJ0/TWMB1sC0wFu6UBgK62Q=", 729 | "dev": true, 730 | "requires": { 731 | "deep-is": "~0.1.3", 732 | "fast-levenshtein": "~2.0.4", 733 | "levn": "~0.3.0", 734 | "prelude-ls": "~1.1.2", 735 | "type-check": "~0.3.2", 736 | "wordwrap": "~1.0.0" 737 | } 738 | }, 739 | "os-tmpdir": { 740 | "version": "1.0.2", 741 | "resolved": "https://registry.npmjs.org/os-tmpdir/-/os-tmpdir-1.0.2.tgz", 742 | "integrity": "sha1-u+Z0BseaqFxc/sdm/lc0VV36EnQ=", 743 | "dev": true 744 | }, 745 | "path-is-absolute": { 746 | "version": "1.0.1", 747 | "resolved": "https://registry.npmjs.org/path-is-absolute/-/path-is-absolute-1.0.1.tgz", 748 | "integrity": "sha1-F0uSaHNVNP+8es5r9TpanhtcX18=", 749 | "dev": true 750 | }, 751 | "path-is-inside": { 752 | "version": "1.0.2", 753 | "resolved": "https://registry.npmjs.org/path-is-inside/-/path-is-inside-1.0.2.tgz", 754 | "integrity": "sha1-NlQX3t5EQw0cEa9hAn+s8HS9/FM=", 755 | "dev": true 756 | }, 757 | "path-key": { 758 | "version": "2.0.1", 759 | "resolved": "https://registry.npmjs.org/path-key/-/path-key-2.0.1.tgz", 760 | "integrity": "sha1-QRyttXTFoUDTpLGRDUDYDMn0C0A=", 761 | "dev": true 762 | }, 763 | "pify": { 764 | "version": "2.3.0", 765 | "resolved": "https://registry.npmjs.org/pify/-/pify-2.3.0.tgz", 766 | "integrity": "sha1-7RQaasBDqEnqWISY59yosVMw6Qw=", 767 | "dev": true 768 | }, 769 | "pinkie": { 770 | "version": "2.0.4", 771 | "resolved": "https://registry.npmjs.org/pinkie/-/pinkie-2.0.4.tgz", 772 | "integrity": "sha1-clVrgM+g1IqXToDnckjoDtT3+HA=", 773 | "dev": true 774 | }, 775 | "pinkie-promise": { 776 | "version": "2.0.1", 777 | "resolved": "https://registry.npmjs.org/pinkie-promise/-/pinkie-promise-2.0.1.tgz", 778 | "integrity": "sha1-ITXW36ejWMBprJsXh3YogihFD/o=", 779 | "dev": true, 780 | "requires": { 781 | "pinkie": "^2.0.0" 782 | } 783 | }, 784 | "pluralize": { 785 | "version": "7.0.0", 786 | "resolved": "https://registry.npmjs.org/pluralize/-/pluralize-7.0.0.tgz", 787 | "integrity": "sha512-ARhBOdzS3e41FbkW/XWrTEtukqqLoK5+Z/4UeDaLuSW+39JPeFgs4gCGqsrJHVZX0fUrx//4OF0K1CUGwlIFow==", 788 | "dev": true 789 | }, 790 | "prelude-ls": { 791 | "version": "1.1.2", 792 | "resolved": "https://registry.npmjs.org/prelude-ls/-/prelude-ls-1.1.2.tgz", 793 | "integrity": "sha1-IZMqVJ9eUv/ZqCf1cOBL5iqX2lQ=", 794 | "dev": true 795 | }, 796 | "progress": { 797 | "version": "2.0.0", 798 | "resolved": "https://registry.npmjs.org/progress/-/progress-2.0.0.tgz", 799 | "integrity": "sha1-ihvjZr+Pwj2yvSPxDG/pILQ4nR8=", 800 | "dev": true 801 | }, 802 | "punycode": { 803 | "version": "2.1.1", 804 | "resolved": "https://registry.npmjs.org/punycode/-/punycode-2.1.1.tgz", 805 | "integrity": "sha512-XRsRjdf+j5ml+y/6GKHPZbrF/8p2Yga0JPtdqTIY2Xe5ohJPD9saDJJLPvp9+NSBprVvevdXZybnj2cv8OEd0A==", 806 | "dev": true 807 | }, 808 | "regexpp": { 809 | "version": "2.0.0", 810 | "resolved": "https://registry.npmjs.org/regexpp/-/regexpp-2.0.0.tgz", 811 | "integrity": "sha512-g2FAVtR8Uh8GO1Nv5wpxW7VFVwHcCEr4wyA8/MHiRkO8uHoR5ntAA8Uq3P1vvMTX/BeQiRVSpDGLd+Wn5HNOTA==", 812 | "dev": true 813 | }, 814 | "require-uncached": { 815 | "version": "1.0.3", 816 | "resolved": "https://registry.npmjs.org/require-uncached/-/require-uncached-1.0.3.tgz", 817 | "integrity": "sha1-Tg1W1slmL9MeQwEcS5WqSZVUIdM=", 818 | "dev": true, 819 | "requires": { 820 | "caller-path": "^0.1.0", 821 | "resolve-from": "^1.0.0" 822 | } 823 | }, 824 | "resolve-from": { 825 | "version": "1.0.1", 826 | "resolved": "https://registry.npmjs.org/resolve-from/-/resolve-from-1.0.1.tgz", 827 | "integrity": "sha1-Jsv+k10a7uq7Kbw/5a6wHpPUQiY=", 828 | "dev": true 829 | }, 830 | "restore-cursor": { 831 | "version": "2.0.0", 832 | "resolved": "https://registry.npmjs.org/restore-cursor/-/restore-cursor-2.0.0.tgz", 833 | "integrity": "sha1-n37ih/gv0ybU/RYpI9YhKe7g368=", 834 | "dev": true, 835 | "requires": { 836 | "onetime": "^2.0.0", 837 | "signal-exit": "^3.0.2" 838 | } 839 | }, 840 | "rimraf": { 841 | "version": "2.6.2", 842 | "resolved": "https://registry.npmjs.org/rimraf/-/rimraf-2.6.2.tgz", 843 | "integrity": "sha512-lreewLK/BlghmxtfH36YYVg1i8IAce4TI7oao75I1g245+6BctqTVQiBP3YUJ9C6DQOXJmkYR9X9fCLtCOJc5w==", 844 | "dev": true, 845 | "requires": { 846 | "glob": "^7.0.5" 847 | } 848 | }, 849 | "run-async": { 850 | "version": "2.3.0", 851 | "resolved": "https://registry.npmjs.org/run-async/-/run-async-2.3.0.tgz", 852 | "integrity": "sha1-A3GrSuC91yDUFm19/aZP96RFpsA=", 853 | "dev": true, 854 | "requires": { 855 | "is-promise": "^2.1.0" 856 | } 857 | }, 858 | "rxjs": { 859 | "version": "6.3.2", 860 | "resolved": "https://registry.npmjs.org/rxjs/-/rxjs-6.3.2.tgz", 861 | "integrity": "sha512-hV7criqbR0pe7EeL3O66UYVg92IR0XsA97+9y+BWTePK9SKmEI5Qd3Zj6uPnGkNzXsBywBQWTvujPl+1Kn9Zjw==", 862 | "dev": true, 863 | "requires": { 864 | "tslib": "^1.9.0" 865 | } 866 | }, 867 | "safer-buffer": { 868 | "version": "2.1.2", 869 | "resolved": "https://registry.npmjs.org/safer-buffer/-/safer-buffer-2.1.2.tgz", 870 | "integrity": "sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg==", 871 | "dev": true 872 | }, 873 | "semver": { 874 | "version": "5.5.1", 875 | "resolved": "https://registry.npmjs.org/semver/-/semver-5.5.1.tgz", 876 | "integrity": "sha512-PqpAxfrEhlSUWge8dwIp4tZnQ25DIOthpiaHNIthsjEFQD6EvqUKUDM7L8O2rShkFccYo1VjJR0coWfNkCubRw==", 877 | "dev": true 878 | }, 879 | "shebang-command": { 880 | "version": "1.2.0", 881 | "resolved": "https://registry.npmjs.org/shebang-command/-/shebang-command-1.2.0.tgz", 882 | "integrity": "sha1-RKrGW2lbAzmJaMOfNj/uXer98eo=", 883 | "dev": true, 884 | "requires": { 885 | "shebang-regex": "^1.0.0" 886 | } 887 | }, 888 | "shebang-regex": { 889 | "version": "1.0.0", 890 | "resolved": "https://registry.npmjs.org/shebang-regex/-/shebang-regex-1.0.0.tgz", 891 | "integrity": "sha1-2kL0l0DAtC2yypcoVxyxkMmO/qM=", 892 | "dev": true 893 | }, 894 | "signal-exit": { 895 | "version": "3.0.2", 896 | "resolved": "https://registry.npmjs.org/signal-exit/-/signal-exit-3.0.2.tgz", 897 | "integrity": "sha1-tf3AjxKH6hF4Yo5BXiUTK3NkbG0=", 898 | "dev": true 899 | }, 900 | "slice-ansi": { 901 | "version": "1.0.0", 902 | "resolved": "https://registry.npmjs.org/slice-ansi/-/slice-ansi-1.0.0.tgz", 903 | "integrity": "sha512-POqxBK6Lb3q6s047D/XsDVNPnF9Dl8JSaqe9h9lURl0OdNqy/ujDrOiIHtsqXMGbWWTIomRzAMaTyawAU//Reg==", 904 | "dev": true, 905 | "requires": { 906 | "is-fullwidth-code-point": "^2.0.0" 907 | } 908 | }, 909 | "sprintf-js": { 910 | "version": "1.0.3", 911 | "resolved": "https://registry.npmjs.org/sprintf-js/-/sprintf-js-1.0.3.tgz", 912 | "integrity": "sha1-BOaSb2YolTVPPdAVIDYzuFcpfiw=", 913 | "dev": true 914 | }, 915 | "string-width": { 916 | "version": "2.1.1", 917 | "resolved": "https://registry.npmjs.org/string-width/-/string-width-2.1.1.tgz", 918 | "integrity": "sha512-nOqH59deCq9SRHlxq1Aw85Jnt4w6KvLKqWVik6oA9ZklXLNIOlqg4F2yrT1MVaTjAqvVwdfeZ7w7aCvJD7ugkw==", 919 | "dev": true, 920 | "requires": { 921 | "is-fullwidth-code-point": "^2.0.0", 922 | "strip-ansi": "^4.0.0" 923 | } 924 | }, 925 | "strip-ansi": { 926 | "version": "4.0.0", 927 | "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-4.0.0.tgz", 928 | "integrity": "sha1-qEeQIusaw2iocTibY1JixQXuNo8=", 929 | "dev": true, 930 | "requires": { 931 | "ansi-regex": "^3.0.0" 932 | } 933 | }, 934 | "strip-json-comments": { 935 | "version": "2.0.1", 936 | "resolved": "https://registry.npmjs.org/strip-json-comments/-/strip-json-comments-2.0.1.tgz", 937 | "integrity": "sha1-PFMZQukIwml8DsNEhYwobHygpgo=", 938 | "dev": true 939 | }, 940 | "supports-color": { 941 | "version": "5.5.0", 942 | "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-5.5.0.tgz", 943 | "integrity": "sha512-QjVjwdXIt408MIiAqCX4oUKsgU2EqAGzs2Ppkm4aQYbjm+ZEWEcW4SfFNTr4uMNZma0ey4f5lgLrkB0aX0QMow==", 944 | "dev": true, 945 | "requires": { 946 | "has-flag": "^3.0.0" 947 | } 948 | }, 949 | "table": { 950 | "version": "4.0.3", 951 | "resolved": "http://registry.npmjs.org/table/-/table-4.0.3.tgz", 952 | "integrity": "sha512-S7rnFITmBH1EnyKcvxBh1LjYeQMmnZtCXSEbHcH6S0NoKit24ZuFO/T1vDcLdYsLQkM188PVVhQmzKIuThNkKg==", 953 | "dev": true, 954 | "requires": { 955 | "ajv": "^6.0.1", 956 | "ajv-keywords": "^3.0.0", 957 | "chalk": "^2.1.0", 958 | "lodash": "^4.17.4", 959 | "slice-ansi": "1.0.0", 960 | "string-width": "^2.1.1" 961 | } 962 | }, 963 | "text-table": { 964 | "version": "0.2.0", 965 | "resolved": "https://registry.npmjs.org/text-table/-/text-table-0.2.0.tgz", 966 | "integrity": "sha1-f17oI66AUgfACvLfSoTsP8+lcLQ=", 967 | "dev": true 968 | }, 969 | "through": { 970 | "version": "2.3.8", 971 | "resolved": "http://registry.npmjs.org/through/-/through-2.3.8.tgz", 972 | "integrity": "sha1-DdTJ/6q8NXlgsbckEV1+Doai4fU=", 973 | "dev": true 974 | }, 975 | "tmp": { 976 | "version": "0.0.33", 977 | "resolved": "https://registry.npmjs.org/tmp/-/tmp-0.0.33.tgz", 978 | "integrity": "sha512-jRCJlojKnZ3addtTOjdIqoRuPEKBvNXcGYqzO6zWZX8KfKEpnGY5jfggJQ3EjKuu8D4bJRr0y+cYJFmYbImXGw==", 979 | "dev": true, 980 | "requires": { 981 | "os-tmpdir": "~1.0.2" 982 | } 983 | }, 984 | "tslib": { 985 | "version": "1.9.3", 986 | "resolved": "https://registry.npmjs.org/tslib/-/tslib-1.9.3.tgz", 987 | "integrity": "sha512-4krF8scpejhaOgqzBEcGM7yDIEfi0/8+8zDRZhNZZ2kjmHJ4hv3zCbQWxoJGz1iw5U0Jl0nma13xzHXcncMavQ==", 988 | "dev": true 989 | }, 990 | "type-check": { 991 | "version": "0.3.2", 992 | "resolved": "https://registry.npmjs.org/type-check/-/type-check-0.3.2.tgz", 993 | "integrity": "sha1-WITKtRLPHTVeP7eE8wgEsrUg23I=", 994 | "dev": true, 995 | "requires": { 996 | "prelude-ls": "~1.1.2" 997 | } 998 | }, 999 | "uri-js": { 1000 | "version": "4.2.2", 1001 | "resolved": "https://registry.npmjs.org/uri-js/-/uri-js-4.2.2.tgz", 1002 | "integrity": "sha512-KY9Frmirql91X2Qgjry0Wd4Y+YTdrdZheS8TFwvkbLWf/G5KNJDCh6pKL5OZctEW4+0Baa5idK2ZQuELRwPznQ==", 1003 | "dev": true, 1004 | "requires": { 1005 | "punycode": "^2.1.0" 1006 | } 1007 | }, 1008 | "which": { 1009 | "version": "1.3.1", 1010 | "resolved": "https://registry.npmjs.org/which/-/which-1.3.1.tgz", 1011 | "integrity": "sha512-HxJdYWq1MTIQbJ3nw0cqssHoTNU267KlrDuGZ1WYlxDStUtKUhOaJmh112/TZmHxxUfuJqPXSOm7tDyas0OSIQ==", 1012 | "dev": true, 1013 | "requires": { 1014 | "isexe": "^2.0.0" 1015 | } 1016 | }, 1017 | "wordwrap": { 1018 | "version": "1.0.0", 1019 | "resolved": "https://registry.npmjs.org/wordwrap/-/wordwrap-1.0.0.tgz", 1020 | "integrity": "sha1-J1hIEIkUVqQXHI0CJkQa3pDLyus=", 1021 | "dev": true 1022 | }, 1023 | "wrappy": { 1024 | "version": "1.0.2", 1025 | "resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz", 1026 | "integrity": "sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8=", 1027 | "dev": true 1028 | }, 1029 | "write": { 1030 | "version": "0.2.1", 1031 | "resolved": "https://registry.npmjs.org/write/-/write-0.2.1.tgz", 1032 | "integrity": "sha1-X8A4KOJkzqP+kUVUdvejxWbLB1c=", 1033 | "dev": true, 1034 | "requires": { 1035 | "mkdirp": "^0.5.1" 1036 | } 1037 | } 1038 | } 1039 | } 1040 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "idlize", 3 | "version": "0.1.1", 4 | "description": "Helper classes and methods for implementing the idle-until-urgent pattern", 5 | "license": "Apache-2.0", 6 | "scripts": { 7 | "test": "eslint *.mjs lib/*.mjs test/*-test.mjs" 8 | }, 9 | "repository": { 10 | "type": "git", 11 | "url": "https://github.com/GoogleChromeLabs/idlize.git" 12 | }, 13 | "bugs": { 14 | "url": "https://github.com/GoogleChromeLabs/idlize/issues" 15 | }, 16 | "author": { 17 | "name": "Philip Walton", 18 | "email": "philip@philipwalton.com", 19 | "url": "http://philipwalton.com" 20 | }, 21 | "keywords": [ 22 | "idle", 23 | "until", 24 | "urgent", 25 | "idle-until-urget", 26 | "requestIdleCallback", 27 | "cancelIdleCallback" 28 | ], 29 | "devDependencies": { 30 | "eslint": "^5.4.0", 31 | "eslint-config-google": "^0.10.0" 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /test/IdleQueue-test.mjs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 Google Inc. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | import {dispatchEvent, nextIdleCallback, when} from './helpers.mjs'; 18 | import {IdleQueue} from '../IdleQueue.mjs'; 19 | import {rIC} from '../idle-callback-polyfills.mjs'; 20 | 21 | 22 | const isSafari_ = !!(typeof safari === 'object' && safari.pushNotification); 23 | 24 | const sandbox = sinon.createSandbox(); 25 | 26 | const blockingSpy = (ms) => { 27 | return sandbox.stub().callsFake(() => { 28 | const startTime = +new Date; 29 | while (new Date - startTime < ms) { 30 | // Do nothing. 31 | } 32 | }); 33 | }; 34 | 35 | const getIdleDeadlinePrototype = async () => { 36 | return await new Promise((resolve) => { 37 | rIC((deadline) => resolve(deadline.constructor.prototype)); 38 | }); 39 | }; 40 | 41 | /** 42 | * A wrapper around `sinon.stub()` that supports non-existent own properties. 43 | * @param {!Object} obj 44 | * @param {string} prop 45 | * @param {*} value 46 | * @return {{value: !Function}} 47 | */ 48 | const stubProperty = (obj, prop, value) => { 49 | if (!obj.hasOwnProperty(prop)) { 50 | return { 51 | value: (value) => { 52 | Object.defineProperty(obj, prop, {value, configurable: true}); 53 | }, 54 | }; 55 | } else { 56 | return sandbox.stub(obj, prop); 57 | } 58 | }; 59 | 60 | 61 | describe(`IdleQueue`, () => { 62 | beforeEach(() => { 63 | sandbox.restore(); 64 | stubProperty(document, 'visibilityState').value('visible'); 65 | }); 66 | 67 | afterEach(() => { 68 | sandbox.restore(); 69 | }); 70 | 71 | describe(`constructor`, () => { 72 | it(`accepts a defaultMinTaskTime option`, async () => { 73 | const idleDeadlinePrototype = await getIdleDeadlinePrototype(); 74 | 75 | let timeRemaining; 76 | sandbox.stub(idleDeadlinePrototype, 'timeRemaining').callsFake(() => { 77 | return timeRemaining; 78 | }); 79 | 80 | const queue1 = new IdleQueue({defaultMinTaskTime: 10}); 81 | const spy1 = sandbox.spy(); 82 | const rICSpy1 = sandbox.spy(); 83 | 84 | timeRemaining = 9; 85 | queue1.pushTask(spy1); 86 | rIC(rICSpy1); 87 | 88 | // The added spy should not run because the timeRemaining value will 89 | // always be less than the defaultMinTaskTime. 90 | await when(() => rICSpy1.calledOnce); 91 | assert(spy1.notCalled); 92 | 93 | // Simulate a longer idle period and assert spy1 is eventually called. 94 | timeRemaining = 50; 95 | await when(() => spy1.calledOnce); 96 | 97 | const queue2 = new IdleQueue({defaultMinTaskTime: 25}); 98 | const spy2 = sandbox.spy(); 99 | const rICSpy2 = sandbox.spy(); 100 | 101 | timeRemaining = 26; 102 | 103 | queue2.pushTask(spy2); 104 | rIC(rICSpy2); 105 | 106 | await when(() => rICSpy2.calledOnce); 107 | assert(spy1.calledOnce); 108 | 109 | queue1.destroy(); 110 | queue2.destroy(); 111 | }); 112 | 113 | it(`adds lifecycle event listeners when ensureTasksRun is true`, () => { 114 | sandbox.spy(window, 'addEventListener'); 115 | 116 | const queue = new IdleQueue({ensureTasksRun: true}); 117 | 118 | assert(window.addEventListener.calledWith( 119 | 'visibilitychange', sinon.match.func, true)); 120 | 121 | if (isSafari_) { 122 | assert(window.addEventListener.calledWith( 123 | 'beforeunload', sinon.match.func, true)); 124 | } else { 125 | assert(!window.addEventListener.calledWith( 126 | 'beforeunload', sinon.match.func, true)); 127 | } 128 | 129 | const spy1 = sandbox.spy(); 130 | const spy2 = sandbox.spy(); 131 | 132 | queue.pushTask(spy1); 133 | queue.pushTask(spy2); 134 | dispatchEvent(window, 'beforeunload'); 135 | 136 | if (isSafari_) { 137 | assert(spy1.calledOnce); 138 | assert(spy2.calledOnce); 139 | } else { 140 | assert(spy1.notCalled); 141 | assert(spy2.notCalled); 142 | } 143 | 144 | const spy3 = sandbox.spy(); 145 | const spy4 = sandbox.spy(); 146 | const spy5 = sandbox.spy(); 147 | 148 | queue.pushTask(spy3); 149 | queue.pushTask(spy4); 150 | queue.pushTask(spy5); 151 | 152 | stubProperty(document, 'visibilityState').value('hidden'); 153 | dispatchEvent(document, 'visibilitychange'); 154 | 155 | assert(spy3.calledOnce); 156 | assert(spy4.calledOnce); 157 | assert(spy5.calledOnce); 158 | 159 | queue.destroy(); 160 | }); 161 | 162 | it(`handles changes in lifecycle state while the queue is pending`, async () => { 163 | const spy1 = sandbox.spy(); 164 | const spy2 = sandbox.spy(); 165 | const spy3 = sandbox.spy(); 166 | 167 | const queue = new IdleQueue({ensureTasksRun: true}); 168 | 169 | queue.pushTask(spy1); 170 | queue.pushTask(spy2); 171 | queue.pushTask(spy3); 172 | 173 | assert(spy1.notCalled); 174 | assert(spy2.notCalled); 175 | assert(spy3.notCalled); 176 | 177 | dispatchEvent(window, 'beforeunload'); 178 | 179 | if (isSafari_) { 180 | assert(spy1.calledOnce); 181 | assert(spy2.calledOnce); 182 | assert(spy3.calledOnce); 183 | } else { 184 | assert(spy1.notCalled); 185 | assert(spy2.notCalled); 186 | assert(spy3.notCalled); 187 | } 188 | 189 | stubProperty(document, 'visibilityState').value('hidden'); 190 | dispatchEvent(document, 'visibilitychange'); 191 | 192 | assert(spy1.calledOnce); 193 | assert(spy2.calledOnce); 194 | assert(spy3.calledOnce); 195 | 196 | queue.destroy(); 197 | }); 198 | }); 199 | 200 | describe(`pushTask`, () => { 201 | it(`queues a task to run when idle`, async () => { 202 | const spy1 = sandbox.spy(); 203 | const spy2 = sandbox.spy(); 204 | const spy3 = sandbox.spy(); 205 | 206 | const queue = new IdleQueue(); 207 | 208 | // Since this idle callback is scheduled before the spies are added, 209 | // It should always run first. 210 | rIC(() => { 211 | assert(spy1.notCalled); 212 | assert(spy2.notCalled); 213 | assert(spy3.notCalled); 214 | }); 215 | 216 | queue.pushTask(spy1); 217 | queue.pushTask(spy2); 218 | queue.pushTask(spy3); 219 | 220 | assert(spy1.notCalled); 221 | assert(spy2.notCalled); 222 | assert(spy3.notCalled); 223 | 224 | await when(() => spy3.calledOnce); 225 | 226 | assert(spy1.calledOnce); 227 | assert(spy2.calledOnce); 228 | assert(spy3.calledOnce); 229 | 230 | queue.destroy(); 231 | }); 232 | 233 | it(`calls the task with the state at add time`, async () => { 234 | const spy1 = sandbox.spy(); 235 | const spy2 = sandbox.spy(); 236 | 237 | const queue = new IdleQueue(); 238 | 239 | const clock = sinon.useFakeTimers({now: 1e12, toFake: ['Date']}); 240 | 241 | stubProperty(document, 'visibilityState').value('hidden'); 242 | queue.pushTask(spy1); 243 | 244 | clock.tick(1000); 245 | 246 | stubProperty(document, 'visibilityState').value('visible'); 247 | queue.pushTask(spy2); 248 | 249 | clock.restore(); 250 | 251 | assert(spy1.notCalled); 252 | assert(spy2.notCalled); 253 | 254 | await when(() => spy2.calledOnce); 255 | 256 | assert(spy1.calledOnce); 257 | assert.strictEqual(spy1.firstCall.args[0].time, 1e12); 258 | assert.strictEqual(spy1.firstCall.args[0].visibilityState, 'hidden'); 259 | 260 | assert(spy2.calledOnce); 261 | assert.strictEqual(spy2.firstCall.args[0].time, 1e12 + 1000); 262 | assert.strictEqual(spy2.firstCall.args[0].visibilityState, 'visible'); 263 | 264 | queue.destroy(); 265 | }); 266 | 267 | it(`waits until the next idle period if all tasks cannot finish`, async () => { 268 | const spy1 = blockingSpy(5); 269 | const spy2 = blockingSpy(45); 270 | const spy3 = blockingSpy(5); 271 | const spy4 = blockingSpy(5); 272 | const rICSpy = sandbox.spy(); 273 | 274 | const queue = new IdleQueue(); 275 | 276 | queue.pushTask(spy1); 277 | queue.pushTask(spy2); 278 | queue.pushTask(spy3); 279 | queue.pushTask(spy4); 280 | 281 | // This callback is queued after the 4 spies, but it should run at some 282 | // point before the last one (implying the queue needed to reschedule). 283 | rIC(rICSpy); 284 | 285 | assert(spy1.notCalled); 286 | assert(spy2.notCalled); 287 | assert(spy3.notCalled); 288 | assert(spy4.notCalled); 289 | assert(rICSpy.notCalled); 290 | 291 | await when(() => spy4.calledOnce); 292 | 293 | assert(spy1.calledOnce); 294 | assert(spy2.calledOnce); 295 | assert(spy3.calledOnce); 296 | assert(spy4.calledOnce); 297 | 298 | assert(rICSpy.calledOnce); 299 | assert(rICSpy.calledBefore(spy4)); 300 | 301 | queue.destroy(); 302 | }); 303 | 304 | it(`runs the task as a microtask when in the hidden state if ensureTasksRun is true`, async () => { 305 | stubProperty(document, 'visibilityState').value('hidden'); 306 | 307 | const spy1 = sandbox.spy(); 308 | const spy2 = sandbox.spy(); 309 | const spy3 = sandbox.spy(); 310 | 311 | const queue = new IdleQueue({ensureTasksRun: true}); 312 | 313 | queue.pushTask(spy1); 314 | queue.pushTask(spy2); 315 | queue.pushTask(spy3); 316 | 317 | assert(spy1.notCalled); 318 | assert(spy2.notCalled); 319 | assert(spy3.notCalled); 320 | 321 | // next microtask 322 | await Promise.resolve(); 323 | 324 | assert(spy1.calledOnce); 325 | assert(spy2.calledOnce); 326 | assert(spy3.calledOnce); 327 | 328 | queue.destroy(); 329 | }); 330 | 331 | it(`runs tasks in order`, async () => { 332 | const testQueueOrder = async (visibilityState) => { 333 | stubProperty(document, 'visibilityState').value(visibilityState); 334 | 335 | const spy1 = sandbox.spy(); 336 | const spy2 = sandbox.spy(); 337 | const spy3 = sandbox.spy(); 338 | const queue = new IdleQueue(); 339 | 340 | queue.pushTask(spy1); 341 | queue.pushTask(spy2); 342 | queue.pushTask(spy3); 343 | 344 | assert(spy1.notCalled); 345 | assert(spy2.notCalled); 346 | assert(spy3.notCalled); 347 | 348 | await when(() => spy3.calledOnce); 349 | 350 | assert(spy1.calledOnce); 351 | assert(spy1.calledBefore(spy2)); 352 | assert(spy2.calledOnce); 353 | assert(spy2.calledBefore(spy3)); 354 | assert(spy3.calledOnce); 355 | 356 | queue.destroy(); 357 | }; 358 | 359 | await testQueueOrder('visible'); 360 | await testQueueOrder('hidden'); 361 | }); 362 | 363 | it(`runs nested tasks in order`, async () => { 364 | const testQueueOrder = async (visibilityState) => { 365 | stubProperty(document, 'visibilityState').value(visibilityState); 366 | 367 | const spy1 = sandbox.spy(); 368 | const spy2 = sandbox.spy(); 369 | const spy3 = sandbox.spy(); 370 | const spy4 = sandbox.spy(); 371 | const spy5 = sandbox.spy(); 372 | const spy6 = sandbox.spy(); 373 | 374 | const queue = new IdleQueue(); 375 | 376 | queue.pushTask(spy1); 377 | queue.pushTask(() => { 378 | queue.pushTask(() => { 379 | spy4(); 380 | queue.pushTask(spy6); 381 | }); 382 | spy2(); 383 | }); 384 | queue.pushTask(() => { 385 | queue.pushTask(spy5); 386 | spy3(); 387 | }); 388 | 389 | await when(() => spy6.calledOnce); 390 | 391 | assert(spy1.calledOnce); 392 | assert(spy1.calledBefore(spy2)); 393 | assert(spy2.calledOnce); 394 | assert(spy2.calledBefore(spy3)); 395 | assert(spy3.calledOnce); 396 | assert(spy3.calledBefore(spy4)); 397 | assert(spy4.calledOnce); 398 | assert(spy4.calledBefore(spy5)); 399 | assert(spy5.calledOnce); 400 | assert(spy5.calledBefore(spy6)); 401 | assert(spy6.calledOnce); 402 | 403 | queue.destroy(); 404 | }; 405 | 406 | await testQueueOrder('visible'); 407 | await testQueueOrder('hidden'); 408 | }); 409 | 410 | it(`runs nested tasks in order across idle periods`, async () => { 411 | const spy1 = blockingSpy(5); 412 | const spy2 = blockingSpy(45); 413 | const spy3 = blockingSpy(5); 414 | const spy4 = blockingSpy(45); 415 | const spy5 = blockingSpy(5); 416 | const spy6 = blockingSpy(45); 417 | 418 | const queue = new IdleQueue(); 419 | 420 | queue.pushTask(spy1); 421 | queue.pushTask(() => { 422 | queue.pushTask(() => { 423 | spy4(); 424 | queue.pushTask(spy6); 425 | }); 426 | spy2(); 427 | }); 428 | queue.pushTask(() => { 429 | queue.pushTask(spy5); 430 | spy3(); 431 | }); 432 | 433 | await when(() => spy6.calledOnce); 434 | 435 | assert(spy1.calledOnce); 436 | assert(spy1.calledBefore(spy2)); 437 | assert(spy2.calledOnce); 438 | assert(spy2.calledBefore(spy3)); 439 | assert(spy3.calledOnce); 440 | assert(spy3.calledBefore(spy4)); 441 | assert(spy4.calledOnce); 442 | assert(spy4.calledBefore(spy5)); 443 | assert(spy5.calledOnce); 444 | assert(spy5.calledBefore(spy6)); 445 | assert(spy6.calledOnce); 446 | 447 | queue.destroy(); 448 | }); 449 | 450 | it(`accepts a minTaskTime option`, async () => { 451 | const idleDeadlinePrototype = await getIdleDeadlinePrototype(); 452 | 453 | const queue = new IdleQueue(); 454 | 455 | let timeRemaining; 456 | sandbox.stub(idleDeadlinePrototype, 'timeRemaining').callsFake(() => { 457 | return timeRemaining; 458 | }); 459 | 460 | const spy1 = sandbox.spy(); 461 | const rICSpy1 = sandbox.spy(); 462 | 463 | timeRemaining = 13; 464 | queue.pushTask(spy1); 465 | rIC(rICSpy1); 466 | 467 | // With the default minTaskTime, spy1 should be called before rICSpy1. 468 | await when(() => rICSpy1.calledOnce); 469 | assert(spy1.called); 470 | 471 | 472 | const spy2 = sandbox.spy(); 473 | const rICSpy2 = sandbox.spy(); 474 | 475 | queue.pushTask(spy2, {minTaskTime: 25}); 476 | rIC(rICSpy2); 477 | 478 | // With a minTaskTime of 25, rICSpy should be called before spy1. 479 | await when(() => rICSpy2.calledOnce); 480 | assert(spy2.notCalled); 481 | 482 | // Simulate a longer idle period. 483 | timeRemaining = 50; 484 | 485 | await when(() => spy2.calledOnce); 486 | 487 | queue.destroy(); 488 | }); 489 | }); 490 | 491 | describe(`unshiftTask`, () => { 492 | it(`adds a task to the beginning of the queue`, async () => { 493 | const spy1 = sandbox.spy(); 494 | const spy2 = sandbox.spy(); 495 | const spy3 = sandbox.spy(); 496 | 497 | const queue = new IdleQueue(); 498 | 499 | // Since this idle callback is scheduled before the spies are added, 500 | // It should always run first. 501 | rIC(() => { 502 | assert(spy1.notCalled); 503 | assert(spy2.notCalled); 504 | assert(spy3.notCalled); 505 | }); 506 | 507 | queue.pushTask(spy1); 508 | queue.pushTask(spy2); 509 | queue.unshiftTask(spy3); 510 | 511 | assert(spy1.notCalled); 512 | assert(spy2.notCalled); 513 | assert(spy3.notCalled); 514 | 515 | await when(() => spy2.calledOnce); 516 | 517 | assert(spy1.calledOnce); 518 | assert(spy2.calledOnce); 519 | assert(spy3.calledOnce); 520 | 521 | assert(spy3.calledBefore(spy1)); 522 | assert(spy1.calledBefore(spy2)); 523 | 524 | queue.destroy(); 525 | }); 526 | }); 527 | 528 | describe(`clearPendingTasks`, () => { 529 | it(`removes scheduled tasks from the queue`, async () => { 530 | const spy1 = sandbox.spy(); 531 | const spy2 = sandbox.spy(); 532 | const spy3 = sandbox.spy(); 533 | 534 | const queue = new IdleQueue(); 535 | 536 | // Since this idle callback is scheduled before the spies are added, 537 | // It should always run first. 538 | rIC(() => { 539 | assert(spy1.notCalled); 540 | assert(spy2.notCalled); 541 | assert(spy3.notCalled); 542 | }); 543 | 544 | queue.pushTask(spy1); 545 | queue.pushTask(spy2); 546 | 547 | assert(spy1.notCalled); 548 | assert(spy2.notCalled); 549 | 550 | queue.clearPendingTasks(); 551 | queue.pushTask(spy3); 552 | 553 | await when(() => spy3.calledOnce); 554 | 555 | assert(spy3.calledOnce); 556 | 557 | // Assert spy1 and spy2 were actually cleared (and not run). 558 | assert(spy1.notCalled); 559 | assert(spy2.notCalled); 560 | 561 | queue.destroy(); 562 | }); 563 | }); 564 | 565 | describe(`runTasksImmediately`, () => { 566 | it(`runs all pending tasks synchronously`, () => { 567 | const spy1 = sandbox.spy(); 568 | const spy2 = sandbox.spy(); 569 | const spy3 = sandbox.spy(); 570 | 571 | const queue = new IdleQueue(); 572 | 573 | queue.pushTask(spy1); 574 | queue.pushTask(spy2); 575 | queue.pushTask(spy3); 576 | 577 | assert(spy1.notCalled); 578 | assert(spy2.notCalled); 579 | assert(spy3.notCalled); 580 | 581 | queue.runTasksImmediately(); 582 | 583 | assert(spy1.calledOnce); 584 | assert(spy2.calledOnce); 585 | assert(spy3.calledOnce); 586 | 587 | queue.destroy(); 588 | }); 589 | 590 | it(`works when the queue is already running`, async () => { 591 | const spy1 = blockingSpy(5); 592 | const spy2 = blockingSpy(45); 593 | const spy3 = blockingSpy(5); 594 | const spy4 = blockingSpy(45); 595 | const spy5 = blockingSpy(5); 596 | const spy6 = blockingSpy(45); 597 | 598 | const queue = new IdleQueue(); 599 | 600 | queue.pushTask(spy1); 601 | queue.pushTask(() => { 602 | queue.pushTask(() => { 603 | spy4(); 604 | queue.pushTask(spy6); 605 | }); 606 | spy2(); 607 | }); 608 | queue.pushTask(() => { 609 | queue.pushTask(spy5); 610 | spy3(); 611 | }); 612 | 613 | // This should run at some point in the middle of the 6 spies running. 614 | // Ensure that the remaining spies are called immediately. 615 | rIC(() => { 616 | assert(spy6.notCalled); 617 | 618 | queue.runTasksImmediately(); 619 | 620 | assert(spy6.calledOnce); 621 | }); 622 | 623 | await when(() => spy6.calledOnce); 624 | 625 | assert(spy1.calledOnce); 626 | assert(spy1.calledBefore(spy2)); 627 | assert(spy2.calledOnce); 628 | assert(spy2.calledBefore(spy3)); 629 | assert(spy3.calledOnce); 630 | assert(spy3.calledBefore(spy4)); 631 | assert(spy4.calledOnce); 632 | assert(spy4.calledBefore(spy5)); 633 | assert(spy5.calledOnce); 634 | assert(spy5.calledBefore(spy6)); 635 | assert(spy6.calledOnce); 636 | 637 | queue.destroy(); 638 | }); 639 | 640 | it(`cancels pending idle callbacks to not run tasks twice`, async () => { 641 | const spy1 = sandbox.spy(); 642 | const spy2 = sandbox.spy(); 643 | const queue = new IdleQueue(); 644 | 645 | queue.pushTask(spy1); 646 | queue.pushTask(spy2); 647 | 648 | assert(spy1.notCalled); 649 | assert(spy2.notCalled); 650 | 651 | queue.runTasksImmediately(); 652 | 653 | assert(spy1.calledOnce); 654 | assert(spy2.calledOnce); 655 | 656 | // Wait until the next idle point to assert the tasks weren't re-run. 657 | await nextIdleCallback(); 658 | 659 | assert(spy1.calledOnce); 660 | assert(spy2.calledOnce); 661 | 662 | queue.destroy(); 663 | }); 664 | }); 665 | 666 | describe(`hasPendingTasks`, () => { 667 | it(`returns true if there are tasks in the queue`, async () => { 668 | const spy1 = sandbox.spy(); 669 | const spy2 = sandbox.spy(); 670 | const spy3 = sandbox.spy(); 671 | 672 | const queue = new IdleQueue(); 673 | 674 | assert.strictEqual(queue.hasPendingTasks(), false); 675 | 676 | queue.pushTask(spy1); 677 | queue.pushTask(spy2); 678 | queue.pushTask(spy3); 679 | 680 | assert.strictEqual(queue.hasPendingTasks(), true); 681 | 682 | await when(() => spy3.calledOnce); 683 | 684 | assert.strictEqual(queue.hasPendingTasks(), false); 685 | 686 | queue.destroy(); 687 | }); 688 | 689 | it(`returns true after running if more tasks are still scheduled`, async () => { 690 | const spy1 = blockingSpy(5); 691 | const spy2 = blockingSpy(45); 692 | const spy3 = blockingSpy(5); 693 | const spy4 = blockingSpy(5); 694 | 695 | const queue = new IdleQueue(); 696 | 697 | assert.strictEqual(queue.hasPendingTasks(), false); 698 | 699 | queue.pushTask(spy1); 700 | queue.pushTask(spy2); 701 | queue.pushTask(spy3); 702 | queue.pushTask(spy4); 703 | 704 | assert.strictEqual(queue.hasPendingTasks(), true); 705 | 706 | // This callback is queued after the 4 spies, but it should run at some 707 | // point before the last one (implying the queue needed to reschedule). 708 | rIC(() => { 709 | assert.strictEqual(queue.hasPendingTasks(), true); 710 | }); 711 | 712 | await when(() => spy4.calledOnce); 713 | 714 | assert.strictEqual(queue.hasPendingTasks(), false); 715 | 716 | queue.destroy(); 717 | }); 718 | }); 719 | 720 | describe(`getState`, () => { 721 | it(`returns the state (at add time) of the currently running task`, async () => { 722 | const queue = new IdleQueue(); 723 | 724 | const stub1 = sandbox.stub().callsFake((state) => { 725 | assert.strictEqual(queue.getState(), state); 726 | assert.strictEqual(queue.getState().time, 1e12); 727 | assert.strictEqual(queue.getState().visibilityState, 'hidden'); 728 | }); 729 | const stub2 = sandbox.stub().callsFake((state) => { 730 | assert.strictEqual(queue.getState(), state); 731 | assert.strictEqual(queue.getState().time, 1e12 + 1000); 732 | assert.strictEqual(queue.getState().visibilityState, 'visible'); 733 | }); 734 | 735 | const clock = sinon.useFakeTimers({now: 1e12, toFake: ['Date']}); 736 | 737 | stubProperty(document, 'visibilityState').value('hidden'); 738 | queue.pushTask(stub1); 739 | 740 | clock.tick(1000); 741 | 742 | stubProperty(document, 'visibilityState').value('visible'); 743 | queue.pushTask(stub2); 744 | 745 | clock.restore(); 746 | 747 | assert(stub1.notCalled); 748 | assert(stub2.notCalled); 749 | 750 | await when(() => stub2.calledOnce); 751 | 752 | assert(stub1.calledOnce); 753 | assert(stub2.calledOnce); 754 | 755 | queue.destroy(); 756 | }); 757 | 758 | it(`returns null if no tasks are running`, () => { 759 | const queue = new IdleQueue(); 760 | 761 | assert.strictEqual(queue.getState(), null); 762 | 763 | queue.destroy(); 764 | }); 765 | }); 766 | 767 | describe(`destroy`, () => { 768 | it(`removes added lifecycle listeners when ensureTasksRun is true`, () => { 769 | sandbox.spy(self, 'removeEventListener'); 770 | 771 | const queue = new IdleQueue({ensureTasksRun: true}); 772 | assert(self.removeEventListener.notCalled); 773 | 774 | queue.destroy(); 775 | 776 | assert(self.removeEventListener.calledWith( 777 | 'visibilitychange', sinon.match.func, true)); 778 | 779 | if (isSafari_) { 780 | assert(window.removeEventListener.calledWith( 781 | 'beforeunload', sinon.match.func, true)); 782 | } else { 783 | assert(!window.removeEventListener.calledWith( 784 | 'beforeunload', sinon.match.func, true)); 785 | } 786 | }); 787 | }); 788 | }); 789 | -------------------------------------------------------------------------------- /test/IdleValue-test.mjs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 Google Inc. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | import {nextIdleCallback} from './helpers.mjs'; 18 | import {IdleValue} from '../IdleValue.mjs'; 19 | 20 | 21 | const sandbox = sinon.createSandbox(); 22 | 23 | describe(`IdleValue`, () => { 24 | afterEach(() => { 25 | sandbox.restore(); 26 | }); 27 | 28 | describe(`IdleValue`, () => { 29 | describe(`constructor`, () => { 30 | it(`initializes the value when idle`, async () => { 31 | const initStub = sandbox.stub().returns('42'); 32 | new IdleValue(initStub); 33 | 34 | assert(initStub.notCalled); 35 | 36 | await nextIdleCallback(); 37 | 38 | assert(initStub.calledOnce); 39 | }); 40 | }); 41 | 42 | describe(`getValue`, () => { 43 | it(`returns the value immediately when already initialized`, async () => { 44 | const initStub = sandbox.stub().returns('42'); 45 | const idleVal = new IdleValue(initStub); 46 | 47 | await nextIdleCallback(); 48 | assert(initStub.calledOnce); 49 | 50 | const val = idleVal.getValue(); 51 | 52 | assert.strictEqual(val, '42'); 53 | }); 54 | 55 | it(`runs the init function immediately if the value not yet set`, () => { 56 | const initStub = sandbox.stub().returns('42'); 57 | const idleVal = new IdleValue(initStub); 58 | 59 | assert(initStub.notCalled); 60 | 61 | const val = idleVal.getValue(); 62 | assert.strictEqual(val, '42'); 63 | assert(initStub.calledOnce); 64 | }); 65 | 66 | it(`cancels the idle request if run before idle`, async () => { 67 | const initStub = sandbox.stub().returns('42'); 68 | const idleVal = new IdleValue(initStub); 69 | 70 | const val = idleVal.getValue(); 71 | assert(initStub.calledOnce); 72 | assert.strictEqual(val, '42'); 73 | 74 | await nextIdleCallback(); 75 | 76 | // Assert the init function wasn't called again. 77 | assert(initStub.calledOnce); 78 | }); 79 | 80 | it(`does not initialize the value more than once`, async () => { 81 | const initStub = sandbox.stub().returns('42'); 82 | const idleVal = new IdleValue(initStub); 83 | 84 | let val = idleVal.getValue(); 85 | assert.strictEqual(val, '42'); 86 | assert(initStub.calledOnce); 87 | 88 | val = idleVal.getValue(); 89 | assert.strictEqual(val, '42'); 90 | assert(initStub.calledOnce); 91 | 92 | await nextIdleCallback(); 93 | 94 | val = idleVal.getValue(); 95 | assert.strictEqual(val, '42'); 96 | assert(initStub.calledOnce); 97 | }); 98 | }); 99 | 100 | describe(`setValue`, () => { 101 | it(`updates the value`, () => { 102 | const initStub = sandbox.stub().returns('42'); 103 | const idleVal = new IdleValue(initStub); 104 | 105 | let val = idleVal.getValue(); 106 | assert.strictEqual(val, '42'); 107 | 108 | idleVal.setValue('43'); 109 | 110 | val = idleVal.getValue(); 111 | assert.strictEqual(val, '43'); 112 | }); 113 | 114 | it(`cancels the idle request if run before idle`, async () => { 115 | const initStub = sandbox.stub().returns('42'); 116 | const idleVal = new IdleValue(initStub); 117 | 118 | idleVal.setValue('43'); 119 | assert(initStub.notCalled); 120 | 121 | let val = idleVal.getValue(); 122 | assert.strictEqual(val, '43'); 123 | assert(initStub.notCalled); 124 | 125 | await nextIdleCallback(); 126 | 127 | assert(initStub.notCalled); 128 | }); 129 | }); 130 | }); 131 | }); 132 | -------------------------------------------------------------------------------- /test/defineIdleProperties-test.mjs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 Google Inc. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | import {defineIdleProperties} from '../defineIdleProperties.mjs'; 18 | import {IdleValue} from '../IdleValue.mjs'; 19 | 20 | 21 | const sandbox = sinon.createSandbox(); 22 | 23 | describe(`defineIdleProperties`, () => { 24 | afterEach(() => { 25 | sandbox.restore(); 26 | }); 27 | 28 | describe(`defineIdleProperties`, () => { 29 | it(`defines a property for each passed prop`, () => { 30 | const obj = {}; 31 | const spy1 = sinon.spy(); 32 | const spy2 = sinon.spy(); 33 | const spy3 = sinon.spy(); 34 | 35 | defineIdleProperties(obj, { 36 | prop1: spy1, 37 | prop2: spy2, 38 | prop3: spy3, 39 | }); 40 | 41 | for (let i = 1; i <= 3; ++i) { 42 | assert(obj.hasOwnProperty(`prop${i}`)); 43 | const descriptor = Object.getOwnPropertyDescriptor(obj, `prop${i}`); 44 | 45 | assert.equal(descriptor.configurable, true); 46 | assert.equal(descriptor.enumerable, false); 47 | assert(typeof descriptor.get === 'function'); 48 | assert(typeof descriptor.set === 'function'); 49 | } 50 | }); 51 | 52 | it(`defines getters shadowing IdleValue#getValue for each prop`, () => { 53 | sandbox.spy(IdleValue.prototype, 'getValue'); 54 | 55 | const obj = {}; 56 | const initStub1 = sandbox.stub().returns('A'); 57 | const initStub2 = sandbox.stub().returns('B'); 58 | const initStub3 = sandbox.stub().returns('C'); 59 | 60 | defineIdleProperties(obj, { 61 | prop1: initStub1, 62 | prop2: initStub2, 63 | prop3: initStub3, 64 | }); 65 | 66 | assert(IdleValue.prototype.getValue.notCalled); 67 | 68 | assert.equal(obj.prop1, 'A'); 69 | assert(IdleValue.prototype.getValue.calledOnce); 70 | assert.equal(obj.prop2, 'B'); 71 | assert(IdleValue.prototype.getValue.calledTwice); 72 | assert.equal(obj.prop3, 'C'); 73 | assert(IdleValue.prototype.getValue.calledThrice); 74 | }); 75 | 76 | it(`defines setters shadowing IdleValue#setValue for each prop`, () => { 77 | sandbox.spy(IdleValue.prototype, 'setValue'); 78 | 79 | const obj = {}; 80 | const initStub1 = sandbox.stub().returns('A'); 81 | const initStub2 = sandbox.stub().returns('B'); 82 | const initStub3 = sandbox.stub().returns('C'); 83 | 84 | defineIdleProperties(obj, { 85 | prop1: initStub1, 86 | prop2: initStub2, 87 | prop3: initStub3, 88 | }); 89 | 90 | assert(IdleValue.prototype.setValue.notCalled); 91 | 92 | obj.prop1 = 'A2'; 93 | assert(IdleValue.prototype.setValue.calledOnce); 94 | assert(IdleValue.prototype.setValue.getCall(0).calledWith('A2')); 95 | assert.equal(obj.prop1, 'A2'); 96 | 97 | obj.prop2 = 'B2'; 98 | assert(IdleValue.prototype.setValue.calledTwice); 99 | assert(IdleValue.prototype.setValue.getCall(1).calledWith('B2')); 100 | assert.equal(obj.prop2, 'B2'); 101 | 102 | obj.prop3 = 'C2'; 103 | assert(IdleValue.prototype.setValue.calledThrice); 104 | assert(IdleValue.prototype.setValue.getCall(2).calledWith('C2')); 105 | assert.equal(obj.prop3, 'C2'); 106 | }); 107 | }); 108 | }); 109 | -------------------------------------------------------------------------------- /test/defineIdleProperty-test.mjs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 Google Inc. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | import {defineIdleProperty} from '../defineIdleProperty.mjs'; 18 | import {IdleValue} from '../IdleValue.mjs'; 19 | 20 | 21 | const sandbox = sinon.createSandbox(); 22 | 23 | describe(`defineIdleProperty`, () => { 24 | afterEach(() => { 25 | sandbox.restore(); 26 | }); 27 | 28 | describe(`defineIdleProperty`, () => { 29 | it(`defines a property on the passed object`, () => { 30 | const obj = {}; 31 | defineIdleProperty(obj, 'prop', sandbox.spy()); 32 | 33 | assert(obj.hasOwnProperty('prop')); 34 | 35 | const descriptor = Object.getOwnPropertyDescriptor(obj, 'prop'); 36 | 37 | assert.equal(descriptor.configurable, true); 38 | assert.equal(descriptor.enumerable, false); 39 | assert(typeof descriptor.get === 'function'); 40 | assert(typeof descriptor.set === 'function'); 41 | }); 42 | 43 | it(`defines a getter that shadows IdleValue#getValue`, () => { 44 | sandbox.spy(IdleValue.prototype, 'getValue'); 45 | 46 | const initStub = sandbox.stub().returns('42'); 47 | 48 | const obj = {}; 49 | defineIdleProperty(obj, 'prop', initStub); 50 | 51 | assert(IdleValue.prototype.getValue.notCalled); 52 | 53 | assert.equal(obj.prop, '42'); 54 | assert(IdleValue.prototype.getValue.calledOnce); 55 | }); 56 | 57 | it(`defines a setter that shadows IdleValue#setValue`, () => { 58 | sandbox.spy(IdleValue.prototype, 'setValue'); 59 | 60 | const initStub = sandbox.stub().returns('42'); 61 | 62 | const obj = {}; 63 | defineIdleProperty(obj, 'prop', initStub); 64 | 65 | assert(IdleValue.prototype.setValue.notCalled); 66 | 67 | obj.prop = 'newValue'; 68 | 69 | assert(IdleValue.prototype.setValue.calledOnce); 70 | assert(IdleValue.prototype.setValue.calledWith('newValue')); 71 | assert.equal(obj.prop, 'newValue'); 72 | }); 73 | }); 74 | }); 75 | -------------------------------------------------------------------------------- /test/helpers.mjs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 Google Inc. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | import {rIC} from '../idle-callback-polyfills.mjs'; 18 | 19 | 20 | export const when = async (fn, intervalMillis = 100, retries = 20) => { 21 | for (let i = 0; i < retries; i++) { 22 | const result = await fn(); 23 | if (result) { 24 | return; 25 | } 26 | await new Promise((resolve) => setTimeout(resolve, intervalMillis)); 27 | } 28 | throw new Error(`${fn} didn't return true after ${retries} retries.`); 29 | }; 30 | 31 | export const nextIdleCallback = () => new Promise((res) => rIC(res)); 32 | 33 | export const dispatchEvent = (target, eventType) => { 34 | const event = new Event(eventType); 35 | target.dispatchEvent(event); 36 | } 37 | -------------------------------------------------------------------------------- /test/idle-callback-polyfills-test.mjs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 Google Inc. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | import {when} from './helpers.mjs'; 18 | import {cIC, rIC} from '../idle-callback-polyfills.mjs'; 19 | 20 | 21 | const sandbox = sinon.createSandbox(); 22 | 23 | describe(`idle-callback-polyfills`, () => { 24 | describe(`rIC`, () => { 25 | afterEach(() => { 26 | sandbox.restore(); 27 | }); 28 | 29 | it(`accepts a function and calls it with an IdleDealine object`, async () => { 30 | const spy = sandbox.spy(); 31 | 32 | rIC(spy); 33 | 34 | await when(() => spy.calledOnce); 35 | 36 | assert(spy.calledWith(sinon.match({ 37 | didTimeout: false, 38 | timeRemaining: sinon.match.func, 39 | }))); 40 | }); 41 | 42 | it(`does not call the function in the current task`, () => { 43 | const spy = sandbox.spy(); 44 | 45 | rIC(spy); 46 | assert(spy.notCalled); 47 | }); 48 | }); 49 | 50 | describe(`cIC`, () => { 51 | afterEach(() => { 52 | sandbox.restore(); 53 | }); 54 | 55 | it(`cancels a scheduled rIC`, async () => { 56 | const spy1 = sandbox.spy(); 57 | const spy2 = sandbox.spy(); 58 | 59 | const handle1 = rIC(spy1); 60 | rIC(spy2); 61 | 62 | assert(spy1.notCalled); 63 | assert(spy2.notCalled); 64 | 65 | cIC(handle1); 66 | 67 | // Idle callbacks are called in the order they're queued, so spy2 can 68 | // only be called is either spy1 is called or the first rIC is cancelled. 69 | await when(() => spy2.calledOnce); 70 | 71 | assert(spy1.notCalled); 72 | assert(spy2.calledOnce); 73 | }); 74 | }); 75 | }); 76 | -------------------------------------------------------------------------------- /test/index.html: -------------------------------------------------------------------------------- 1 | 2 | 17 | 18 | 19 | 20 | Mocha Tests 21 | 22 | 23 | 24 |
25 | 26 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 87 | 88 | 89 | --------------------------------------------------------------------------------