{"_id":"@emboxcreative/business-days-js","name":"@emboxcreative/business-days-js","dist-tags":{"latest":"1.0.0"},"versions":{"1.0.0":{"name":"@emboxcreative/business-days-js","version":"1.0.0","description":"Checks whether a date is on a weekend or a U.S. holiday, forked to allow the subtraction of business days from a provided date.","source":"src/index.ts","main":"dist/index.umd.js","module":"dist/index.modern.module.js","types":"dist/index.d.ts","unpkg":"dist/index.umd.js","dependencies":{"date-holidays":"^3.19.0","dayjs":"^1.9.6"},"devDependencies":{"@babel/preset-typescript":"^7.21.0","@types/jest":"^29.5.0","babel-preset-env":"^1.7.0","eslint":"^7.14.0","jest":"^29.5.0","microbundle":"^0.15.1","ts-jest":"^29.0.5","ts-node":"^10.9.1","typescript":"^5.0.2"},"scripts":{"build":"microbundle --name getPkg","dev":"microbundle watch","test":"jest","coverage":"jest --coverage","watch":"jest --watch","pub":"npm run build && npm publish","pre":"npm version prerelease --preid=alpha","pre-pub":"npm run build && npm publish --tag alpha"},"author":{"name":"Originally by Daniel Simmons-Ritchie"},"license":"MIT","repository":{"type":"git","url":"git+https://github.com/emboxcreative/business-days-js.git"},"keywords":["business","dates","holidays","dayjs"],"gitHead":"f990efc3e198b72f6b4a4b70c6312056004f274b","bugs":{"url":"https://github.com/emboxcreative/business-days-js/issues"},"homepage":"https://github.com/emboxcreative/business-days-js#readme","_id":"@emboxcreative/business-days-js@1.0.0","_nodeVersion":"18.17.1","_npmVersion":"9.6.7","dist":{"integrity":"sha512-vCpshcPGfwpcPrqj7l7ur67fa6QFa2k6y2oEf/H+JX0mO5h2LQrY4YicXkWrOv+4pDvWw/Ed5vN7muPTYKQ0LQ==","shasum":"c98d4d40e259ba6cb300f98b937f327ad26f9bf4","tarball":"https://registry.npmjs.org/@emboxcreative/business-days-js/-/business-days-js-1.0.0.tgz","fileCount":25,"unpackedSize":127250,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQDbv2JxlxKXjnVwwzq+/vzToWO3El5KtI+KPPuPL/bJoQIgHZNMZ2+Im/1p8HkXlRv/vMeEzAhtOFYuQU4d3vjslSk="}]},"_npmUser":{"name":"emboxcreative","email":"daniel@emboxcreative.com"},"directories":{},"maintainers":[{"name":"emboxcreative","email":"daniel@emboxcreative.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/business-days-js_1.0.0_1718330373704_0.464483861548024"},"_hasShrinkwrap":false}},"time":{"created":"2024-06-14T01:59:33.561Z","1.0.0":"2024-06-14T01:59:33.845Z","modified":"2024-06-14T01:59:34.162Z"},"maintainers":[{"name":"emboxcreative","email":"daniel@emboxcreative.com"}],"description":"Checks whether a date is on a weekend or a U.S. holiday, forked to allow the subtraction of business days from a provided date.","homepage":"https://github.com/emboxcreative/business-days-js#readme","keywords":["business","dates","holidays","dayjs"],"repository":{"type":"git","url":"git+https://github.com/emboxcreative/business-days-js.git"},"author":{"name":"Originally by Daniel Simmons-Ritchie"},"bugs":{"url":"https://github.com/emboxcreative/business-days-js/issues"},"license":"MIT","readme":"# 💼 business-days-js\r\n\r\n![npm](https://img.shields.io/npm/v/business-days-js)\r\n![npm bundle size](https://img.shields.io/bundlephobia/min/business-days-js)\r\n![npm](https://img.shields.io/npm/dw/business-days-js?color=blue)\r\n![NPM](https://img.shields.io/npm/l/business-days-js?color=blue)\r\n\r\nDetermines whether a given date and time is on a weekend or a public holiday in the U.S. Can also add business days to a specified date to calculate a new date.\r\n\r\nThis package uses [dayjs](https://www.npmjs.com/package/dayjs) and [date-holidays](https://www.npmjs.com/package/date-holidays).\r\n\r\n## 📚 Install\r\n\r\n```\r\nnpm i business-days-js\r\n```\r\n\r\n## 📚 Usage\r\n\r\nFirst initialize a businessDays object:\r\n\r\n```\r\nimport businessDays from \"business-days-js\";\r\n\r\nconst bDays = businessDays();\r\n```\r\nBy default, businessDays treats 11 U.S. public holidays as non-business days. To use state-specific public holidays, instead initialize businessDays with an appropriate two-letter state abbreviation:\r\n\r\n```\r\nimport businessDays from \"business-days-js\";\r\n\r\nconst bDays = businessDays({state: \"pa\"}); // use public holidays for Pennsylvania\r\n```\r\nCheck out the docs for [date-holidays](https://github.com/commenthol/date-holidays#supported-countries-states-regions) for a full list of state abbreviations. Consult 'advanced usage' in this README for more information about customizing holidays.\r\n\r\n### Check business day\r\n\r\nTo check whether a native Date object is a business day:\r\n\r\n```\r\nimport businessDays from \"business-days-js\";\r\n\r\nconst bDays = businessDays({state: \"pa\"});\r\nconst presidentsDay = new Date(\"2016-02-15 00:00:00 GMT-0500\"); // 12 a.m. on Feb. 15, 2016 (EST)\r\nbDays.check(presidentsDay); // returns false\r\n\r\n```\r\nDates can also be provided as a string formatted as \"YYYY-MM-DD\":\r\n\r\n```\r\nimport businessDays from \"business-days-js\";\r\n\r\nconst bDays = businessDays({state: \"pa\"});\r\nconst bizDay = \"2021-11-17\"; // Wednesday, Nov 17, 2021\r\nbDays.check(bizDay); // returns true\r\n```\r\n\r\nOr dates can be provided as a Day.js object:\r\n\r\n```\r\nimport businessDays from \"business-days-js\";\r\nimport dayjs from \"dayjs\";\r\n\r\nconst bDays = businessDays({state: \"pa\"});\r\nconst xmasDay = dayjs(\"2020-12-25 00:00:00 GMT-0500\"); // 12 a.m. on Dec 25, 2020 (EST)\r\nbDays.check(xmasDay); // returns false\r\n```\r\n\r\n### Add business days \r\n\r\nAdd a specified number of business days to a date to calculate a new date. The returned date is a Day.js object.\r\n\r\n```\r\nimport businessDays from \"business-days-js\";\r\n\r\nconst bDays = businessDays({state: \"pa\"});\r\nconst startDate = new Date(\"2020-12-20 00:00:00 GMT-0500\");\r\nbDays.addDays(startDate, 5) // returns a Day.js object representing Dec 28, 2020.\r\n```\r\n\r\nAs with other methods, dates can be provided as a Day.js object or a string formatted as \"YYYY-MM-DD\":\r\n\r\n```\r\nimport businessDays from \"business-days-js\";\r\n\r\nconst bDays = businessDays({state: \"pa\"});\r\nconst newDate = bDays.addDays(\"2020-12-20\", 5) // returns a Day.js object representing Dec 28, 2020.\r\n```\r\n\r\n### Count days\r\n\r\nTo return an object with a tally of total days, business days, weekends, weekdays, and holidays between two dates:\r\n\r\n```\r\nimport businessDays from \"business-days-js\";\r\n\r\nconst bDays = businessDays({state: \"pa\"});\r\nbDays.countDays(\"2020-12-20\", \"2020-12-28\") // returns an object\r\n```\r\n\r\nNote that countDays excludes the start date from its calculations by default. For instance, by default countDays would count a total of eight days between \"2020-12-20\" to \"2020-12-28\" rather than nine days.\r\n\r\nTo include the start date in the tallies:\r\n\r\n```\r\nimport businessDays from \"business-days-js\";\r\n\r\nconst bDays = businessDays({state: \"pa\"});\r\nbDays.countDays(\"2020-12-20\", \"2020-12-28\", {excludeInitialDate: false})\r\n```\r\n\r\n### Get list of public holidays\r\n\r\nTo get a list of public holidays for a specific year with the dates they end and start:\r\n\r\n```\r\nimport businessDays from \"business-days-js\";\r\n\r\nconst bDays = businessDays({state: \"pa\"});\r\n// returns an array of objects with data on Pennsylvania public holidays in 2020\r\nbDays.getHolidays(\"2020\") \r\n\r\n```\r\n\r\n## 📚 Advanced Usage\r\n\r\n### Customize holidays\r\n\r\nYou can exclude specific public holidays from businessDays default list of public holidays. Simply initialize a businessDays object with a list of holidays to exclude.\r\n\r\n```\r\nimport businessDays from \"business-days-js\";\r\n\r\nconst bDays = businessDays({state: \"pa\", excludeHolidays: [\"Flag Day\", \"Presidents' Day\"]});\r\n\r\n// Flag Day and Presidents' Day will now be considered business days if they fall during the work week.\r\nconst flagDay = new Date(\"2019-06-14 00:00:00 GMT-0500\")\r\nconst presDay = new Date(\"2020-02-17 00:00:00 GMT-0500\")\r\nbDays.check(flagDay) // returns true\r\nbDays.check(presDay) // returns true\r\n```\r\n\r\nYou can also add custom holidays to to the default list. Each custom holiday is an object with a 'name' property and a 'rule' property. The rule defines the occurrence of the holiday based on the grammar of [date-holidays](https://www.npmjs.com/package/date-holidays).\r\n\r\n```\r\nimport businessDays from \"business-days-js\";\r\n\r\nconst CUSTOM_HOLIDAYS = [\r\n  {\r\n    rule: \"02-02\",\r\n    name: \"Groundhog Day\",\r\n  },\r\n  {\r\n    rule: \"07-15\",\r\n    name: \"Saint Swithin's Day\",\r\n  },\r\n]\r\nconst bDays = businessDays({\r\n  state: \"pa\",\r\n  excludeHolidays: [\"christmas day\", \"presidents' day\"],\r\n  addHolidays: CUSTOM_HOLIDAYS,\r\n});\r\n```\r\n\r\n## 📚 Notes\r\n\r\n### Holidays and substitution days\r\n\r\nBy default, when initialized without a state abbreviation, businessDays handles the following 11 U.S. public holidays as non-business days:\r\n\r\n- New Year's Day\r\n- Martin Luther King Jr. Day\r\n- Washington's Birthday\r\n- Memorial Day\r\n- Juneteenth\r\n- Independence Day\r\n- Labor Day\r\n- Columbus Day\r\n- Veterans Day\r\n- Thanksgiving Day\r\n- Christmas Day\r\n\r\nIf those days fall on a weekend, substitution days are used based on rules defined by [date-holidays](https://www.npmjs.com/package/date-holidays). For instance, if Christmas Day (Dec 25) falls on a Sunday, then Monday will be assumed to be a public holiday. If Christmas Day falls on a Saturday than Friday will be assumed to be a public holiday.\r\n\r\nFor more information about holiday rules, consult the documentation for [date-holidays](https://www.npmjs.com/package/date-holidays).\r\n\r\n### Contributions\r\nIf you find any bugs or have any suggestions for improvements, please feel free to open an issue or submit a pull request. Contributions are welcome!\r\n\r\n### License\r\nbusiness-days-js is licensed under the MIT License. See the LICENSE file for more information.","readmeFilename":"README.md"}