[
  {
    "path": ".github/FUNDING.yml",
    "content": "github:\n    - 'lukechilds'\ncustom:\n    - 'https://blockstream.info/address/1LukeQU5jwebXbMLDVydeH4vFSobRV9rkj'\n    - 'https://blockstream.info/address/3Luke2qRn5iLj4NiFrvLBu2jaEj7JeMR6w'\n    - 'https://blockstream.info/address/bc1qlukeyq0c69v97uss68fet26kjkcsrymd2kv6d4'\n    - 'https://tippin.me/@lukechilds'\n"
  },
  {
    "path": ".gitignore",
    "content": "## Project\ndist\n\n## Node\n\n# Logs\nlogs\n*.log\nnpm-debug.log*\n\n# Runtime data\npids\n*.pid\n*.seed\n*.pid.lock\n\n# Directory for instrumented libs generated by jscoverage/JSCover\nlib-cov\n\n# Coverage directory used by tools like istanbul\ncoverage\n\n# nyc test coverage\n.nyc_output\n\n# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)\n.grunt\n\n# node-waf configuration\n.lock-wscript\n\n# Compiled binary addons (http://nodejs.org/api/addons.html)\nbuild/Release\n\n# Dependency directories\nnode_modules\njspm_packages\n\n# Optional npm cache directory\n.npm\n\n# Optional eslint cache\n.eslintcache\n\n# Optional REPL history\n.node_repl_history\n\n## OS X\n\n*.DS_Store\n.AppleDouble\n.LSOverride\n\n# Icon must end with two \\r\nIcon\n\n\n# Thumbnails\n._*\n\n# Files that might appear in the root of a volume\n.DocumentRevisions-V100\n.fseventsd\n.Spotlight-V100\n.TemporaryItems\n.Trashes\n.VolumeIcon.icns\n.com.apple.timemachine.donotpresent\n\n# Directories potentially created on remote AFP share\n.AppleDB\n.AppleDesktop\nNetwork Trash Folder\nTemporary Items\n.apdisk\n"
  },
  {
    "path": ".npmignore",
    "content": "src\n"
  },
  {
    "path": ".travis.yml",
    "content": "language: node_js\nnode_js: node\nscript: npm run lint && npm test\nafter_success: npm run coverage\nnotifications:\n  email:\n    on_success: never\n"
  },
  {
    "path": "LICENSE",
    "content": "MIT License\n\nCopyright (c) 2016 Luke Childs\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n"
  },
  {
    "path": "README.md",
    "content": "# when-dom-ready\n\n> $(document).ready() for the 21st century\n\n[![Build Status](https://travis-ci.org/lukechilds/when-dom-ready.svg?branch=master)](https://travis-ci.org/lukechilds/when-dom-ready)\n[![Coverage Status](https://coveralls.io/repos/github/lukechilds/when-dom-ready/badge.svg?branch=master)](https://coveralls.io/github/lukechilds/when-dom-ready?branch=master)\n[![npm](https://img.shields.io/npm/v/when-dom-ready.svg)](https://www.npmjs.com/package/when-dom-ready)\n[![GitHub Donate](https://badgen.net/badge/GitHub/Sponsor/D959A7?icon=github)](https://github.com/sponsors/lukechilds)\n[![Bitcoin Donate](https://badgen.net/badge/Bitcoin/Donate/F19537?icon=bitcoin)](https://lu.ke/tip/bitcoin)\n[![Lightning Donate](https://badgen.net/badge/Lightning/Donate/F6BC41?icon=bitcoin-lightning)](https://lu.ke/tip/lightning)\n\nReturns a Promise for cleaner usage, provides a Promise chain helper function and can also be used as a pure function. The Promise will resolve instantly if the DOM is already ready.\n\n## Browser Compatibility\n\n- IE9+ (requires Promise polyfill)\n- Edge *\n- Firefox 29+\n- Safari 8+\n- Chrome 33+\n- Opera 23+\n\n## Install\n\n```shell\nnpm install --save when-dom-ready\n```\n\nor for quick testing:\n\n```html\n<script src=\"https://unpkg.com/when-dom-ready\"></script>\n```\n\n## Usage\n\n```js\nimport whenDomReady from 'when-dom-ready';\n\nwhenDomReady().then(() => console.log('DOM is ready yo!'));\n```\n\nYou can still use callbacks if you want to:\n\n```js\nwhenDomReady(() => console.log('DOM is ready yo!'));\n```\n\n## Promise chain helper\n\nThere is also a little helper function, `whenDomReady.resume()`, that pauses the execution of a Promise chain and then resumes it with the last value once the DOM is ready.\n\nThis allows you to specify complex async control flow in simple readable code:\n\n```js\nfetch('/my-badass-api.json')\n  .then(getSomeProcessingDoneWhileWaitingForDom)\n  .then(whenDomReady.resume())\n  .then(injectDataIntoDom);\n```\n\n## Pure usage\n\nYou can make the function pure by passing in a `document` object. This is really [useful for tests](https://github.com/lukechilds/when-dom-ready/blob/master/test/unit.js) and mocking environments.\n\nFor example this works in Node.js:\n\n```js\nconst Window = require('window');\nconst whenDomReady = require('when-dom-ready');\n\nconst { document } = new Window();\n\nwhenDomReady(document).then(() => console.log('DOM is ready yo!'));\n```\n\nAgain, you can use the callback version as a pure function too:\n\n```js\nwhenDomReady(() => console.log('DOM is ready yo!'), document);\n```\n\nAnd of course the helper:\n\n```js\n//...\n  .then(whenDomReady.resume(document))\n```\n\n## License\n\nMIT © Luke Childs\n"
  },
  {
    "path": "package.json",
    "content": "{\n  \"name\": \"when-dom-ready\",\n  \"version\": \"1.2.12\",\n  \"description\": \"$(document).ready() for the 21st century\",\n  \"main\": \"dist/index.umd.js\",\n  \"module\": \"dist/index.es2015.js\",\n  \"scripts\": {\n    \"prebuild\": \"rm -rf dist\",\n    \"build\": \"rollup -c\",\n    \"pretest\": \"npm run build\",\n    \"lint\": \"xo\",\n    \"test\": \"nyc ava\",\n    \"coverage\": \"nyc report --reporter=text-lcov | coveralls\",\n    \"prepublish\": \"npm run build\"\n  },\n  \"babel\": {\n    \"presets\": [\n      [\n        \"es2015\",\n        {\n          \"modules\": false\n        }\n      ]\n    ],\n    \"plugins\": [\n      \"array-includes\"\n    ]\n  },\n  \"xo\": {\n    \"env\": \"browser\",\n    \"extends\": \"xo-lukechilds\"\n  },\n  \"repository\": {\n    \"type\": \"git\",\n    \"url\": \"git+https://github.com/lukechilds/when-dom-ready.git\"\n  },\n  \"keywords\": [\n    \"check\",\n    \"dom\",\n    \"loaded\",\n    \"ready\",\n    \"promise\",\n    \"async\",\n    \"asynchronous\",\n    \"pure\"\n  ],\n  \"author\": \"Luke Childs <lukechilds123@gmail.com> (http://lukechilds.co.uk)\",\n  \"license\": \"MIT\",\n  \"bugs\": {\n    \"url\": \"https://github.com/lukechilds/when-dom-ready/issues\"\n  },\n  \"homepage\": \"https://github.com/lukechilds/when-dom-ready\",\n  \"dependencies\": {},\n  \"devDependencies\": {\n    \"ava\": \"^0.25.0\",\n    \"babel-plugin-array-includes\": \"^2.0.3\",\n    \"babel-preset-es2015\": \"^6.24.1\",\n    \"camelcase\": \"^4.0.0\",\n    \"coveralls\": \"^3.0.0\",\n    \"eslint-config-xo-lukechilds\": \"^1.0.0\",\n    \"nyc\": \"^11.0.2\",\n    \"rollup\": \"^0.52.0\",\n    \"rollup-plugin-babel\": \"^2.7.1\",\n    \"window\": \"^4.2.1\",\n    \"xo\": \"^0.18.2\"\n  }\n}\n"
  },
  {
    "path": "rollup.config.js",
    "content": "import babel from 'rollup-plugin-babel';\nimport camelCase from 'camelcase';\n\nconst pkg = require('./package.json');\n\nexport default {\n\tentry: 'src/index.js',\n\tplugins: [\n\t\tbabel()\n\t],\n\ttargets: [\n\t\t{\n\t\t\tdest: pkg.main,\n\t\t\tformat: 'umd',\n\t\t\tmoduleName: camelCase(pkg.name),\n\t\t\tsourceMap: true\n\t\t},\n\t\t{\n\t\t\tdest: pkg.module,\n\t\t\tformat: 'es',\n\t\t\tsourceMap: true\n\t\t}\n\t]\n};\n"
  },
  {
    "path": "src/index.js",
    "content": "/* eslint no-void: \"off\" */\n\n// Loaded ready states\nconst loadedStates = ['interactive', 'complete'];\n\n// Return Promise\nconst whenDomReady = (cb, doc) => new Promise(resolve => {\n\t// Allow doc to be passed in as the lone first param\n\tif (cb && typeof cb !== 'function') {\n\t\tdoc = cb;\n\t\tcb = null;\n\t}\n\n\t// Use global document if we don't have one\n\tdoc = doc || window.document;\n\n\t// Handle DOM load\n\tconst done = () => resolve(void (cb && setTimeout(cb)));\n\n\t// Resolve now if DOM has already loaded\n\t// Otherwise wait for DOMContentLoaded\n\tif (loadedStates.includes(doc.readyState)) {\n\t\tdone();\n\t} else {\n\t\tdoc.addEventListener('DOMContentLoaded', done);\n\t}\n});\n\n// Promise chain helper\nwhenDomReady.resume = doc => val => whenDomReady(doc).then(() => val);\n\nexport default whenDomReady;\n"
  },
  {
    "path": "test/types.js",
    "content": "import test from 'ava';\nimport Window from 'window';\nimport whenDomReady from '../';\n\ntest('whenDomReady is a function', t => {\n\tt.is(typeof whenDomReady, 'function');\n});\n\ntest('whenDomReady returns a Promise', t => {\n\tconst { document } = new Window();\n\tt.true(whenDomReady(document) instanceof Promise);\n});\n\ntest('whenDomReady.resume is a function', t => {\n\tt.is(typeof whenDomReady.resume, 'function');\n});\n\ntest('whenDomReady.resume returns a function that returns a promise', t => {\n\tconst { document } = new Window();\n\tconst returnValue = whenDomReady.resume(document);\n\tt.is(typeof returnValue, 'function');\n\tt.true(returnValue() instanceof Promise);\n});\n\ntest('Promise value always resolves to undefined', async t => {\n\tt.plan(2);\n\tconst { document } = new Window();\n\tconst promises = [\n\t\twhenDomReady(() => 'foo', document).then(val => t.is(val, undefined)),\n\t\twhenDomReady(document).then(val => t.is(val, undefined))\n\t];\n\tawait Promise.all(promises);\n});\n"
  },
  {
    "path": "test/unit.js",
    "content": "import EventEmitter from 'events';\nimport test from 'ava';\nimport Window from 'window';\nimport whenDomReady from '../';\n\ntest.cb('callback fires', t => {\n\tt.plan(1);\n\tconst { document } = new Window();\n\twhenDomReady(() => {\n\t\tt.pass();\n\t\tt.end();\n\t}, document);\n});\n\ntest('Promise resolves', async t => {\n\tconst { document } = new Window();\n\tt.plan(1);\n\tawait whenDomReady(document).then(() => t.pass());\n});\n\ntest('Promise chain helper passes value through', async t => {\n\tconst { document } = new Window();\n\tt.plan(1);\n\tawait Promise\n\t\t.resolve('foo')\n\t\t.then(whenDomReady.resume(document))\n\t\t.then(val => t.is(val, 'foo'));\n});\n\ntest('If document.readyState is already \"interactive\" run cb', async t => {\n\tconst document = { readyState: 'interactive' };\n\tt.plan(1);\n\tawait whenDomReady(document).then(() => t.pass());\n});\n\ntest('If document.readyState is already \"complete\" run cb', async t => {\n\tconst document = { readyState: 'complete' };\n\tt.plan(1);\n\tawait whenDomReady(document).then(() => t.pass());\n});\n\ntest('If document.readyState is \"loading\" run cb on DOMContentLoaded event', async t => {\n\tconst document = new EventEmitter();\n\tdocument.addEventListener = document.on;\n\tdocument.readyState = 'loading';\n\tt.plan(1);\n\tsetTimeout(() => document.emit('DOMContentLoaded'), 500);\n\tawait whenDomReady(document).then(() => t.pass());\n});\n"
  }
]