{"id":28780856,"url":"https://github.com/dguo/sunrise-sunset-js","last_synced_at":"2025-10-22T03:01:32.376Z","repository":{"id":42660187,"uuid":"312913932","full_name":"dguo/sunrise-sunset-js","owner":"dguo","description":"JavaScript client for the Sunrise-Sunset API","archived":false,"fork":false,"pushed_at":"2023-01-07T06:18:54.000Z","size":534,"stargazers_count":3,"open_issues_count":10,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-10-06T07:13:42.052Z","etag":null,"topics":["sunrise","sunrise-sunset-api","sunrise-times","sunset","sunset-times"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/dguo.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-11-14T22:33:53.000Z","updated_at":"2024-04-16T04:25:03.000Z","dependencies_parsed_at":"2023-02-06T13:46:43.362Z","dependency_job_id":null,"html_url":"https://github.com/dguo/sunrise-sunset-js","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"purl":"pkg:github/dguo/sunrise-sunset-js","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dguo%2Fsunrise-sunset-js","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dguo%2Fsunrise-sunset-js/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dguo%2Fsunrise-sunset-js/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dguo%2Fsunrise-sunset-js/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dguo","download_url":"https://codeload.github.com/dguo/sunrise-sunset-js/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dguo%2Fsunrise-sunset-js/sbom","scorecard":{"id":339831,"data":{"date":"2025-08-11","repo":{"name":"github.com/dguo/sunrise-sunset-js","commit":"b0aa0f20892a7e4f5fc44cae51c09a80cf7044db"},"scorecard":{"version":"v5.2.1-40-gf6ed084d","commit":"f6ed084d17c9236477efd66e5b258b9d4cc7b389"},"score":2.5,"checks":[{"name":"Code-Review","score":0,"reason":"Found 0/29 approved changesets -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project requires human code review before pull requests (aka merge requests) are merged.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#code-review"}},{"name":"Maintained","score":0,"reason":"0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project is \"actively maintained\".","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#maintained"}},{"name":"Packaging","score":-1,"reason":"packaging workflow not detected","details":["Warn: no GitHub/GitLab publishing workflow detected."],"documentation":{"short":"Determines if the project is published as a package that others can easily download, install, easily update, and uninstall.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#packaging"}},{"name":"Binary-Artifacts","score":10,"reason":"no binaries found in the repo","details":null,"documentation":{"short":"Determines if the project has generated executable (binary) artifacts in the source repository.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#binary-artifacts"}},{"name":"Dangerous-Workflow","score":10,"reason":"no dangerous workflow patterns detected","details":null,"documentation":{"short":"Determines if the project's GitHub Action workflows avoid dangerous patterns.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#dangerous-workflow"}},{"name":"Pinned-Dependencies","score":0,"reason":"dependency not pinned by hash detected -- score normalized to 0","details":["Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/continuous-deployment.yml:13: update your workflow using https://app.stepsecurity.io/secureworkflow/dguo/sunrise-sunset-js/continuous-deployment.yml/main?enable=pin","Warn: third-party GitHubAction not pinned by hash: .github/workflows/continuous-deployment.yml:15: update your workflow using https://app.stepsecurity.io/secureworkflow/dguo/sunrise-sunset-js/continuous-deployment.yml/main?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/continuous-integration.yml:14: update your workflow using https://app.stepsecurity.io/secureworkflow/dguo/sunrise-sunset-js/continuous-integration.yml/main?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/continuous-integration.yml:15: update your workflow using https://app.stepsecurity.io/secureworkflow/dguo/sunrise-sunset-js/continuous-integration.yml/main?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/continuous-integration.yml:21: update your workflow using https://app.stepsecurity.io/secureworkflow/dguo/sunrise-sunset-js/continuous-integration.yml/main?enable=pin","Warn: third-party GitHubAction not pinned by hash: .github/workflows/continuous-integration.yml:39: update your workflow using https://app.stepsecurity.io/secureworkflow/dguo/sunrise-sunset-js/continuous-integration.yml/main?enable=pin","Info:   0 out of   4 GitHub-owned GitHubAction dependencies pinned","Info:   0 out of   2 third-party GitHubAction dependencies pinned"],"documentation":{"short":"Determines if the project has declared and pinned the dependencies of its build process.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#pinned-dependencies"}},{"name":"Token-Permissions","score":0,"reason":"detected GitHub workflow tokens with excessive permissions","details":["Warn: no topLevel permission defined: .github/workflows/continuous-deployment.yml:1","Warn: no topLevel permission defined: .github/workflows/continuous-integration.yml:1","Info: no jobLevel write permissions found"],"documentation":{"short":"Determines if the project's workflows follow the principle of least privilege.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#token-permissions"}},{"name":"CII-Best-Practices","score":0,"reason":"no effort to earn an OpenSSF best practices badge detected","details":null,"documentation":{"short":"Determines if the project has an OpenSSF (formerly CII) Best Practices Badge.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#cii-best-practices"}},{"name":"Fuzzing","score":0,"reason":"project is not fuzzed","details":["Warn: no fuzzer integrations found"],"documentation":{"short":"Determines if the project uses fuzzing.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#fuzzing"}},{"name":"License","score":10,"reason":"license file detected","details":["Info: project has a license file: LICENSE.txt:0","Info: FSF or OSI recognized license: MIT License: LICENSE.txt:0"],"documentation":{"short":"Determines if the project has defined a license.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#license"}},{"name":"Signed-Releases","score":-1,"reason":"no releases found","details":null,"documentation":{"short":"Determines if the project cryptographically signs release artifacts.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#signed-releases"}},{"name":"Branch-Protection","score":0,"reason":"branch protection not enabled on development/release branches","details":["Warn: branch protection not enabled for branch 'main'"],"documentation":{"short":"Determines if the default and release branches are protected with GitHub's branch protection settings.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#branch-protection"}},{"name":"Security-Policy","score":0,"reason":"security policy file not detected","details":["Warn: no security policy file detected","Warn: no security file to analyze","Warn: no security file to analyze","Warn: no security file to analyze"],"documentation":{"short":"Determines if the project has published a security policy.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#security-policy"}},{"name":"SAST","score":0,"reason":"SAST tool is not run on all commits -- score normalized to 0","details":["Warn: 0 commits out of 5 are checked with a SAST tool"],"documentation":{"short":"Determines if the project uses static code analysis.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#sast"}},{"name":"Vulnerabilities","score":0,"reason":"24 existing vulnerabilities detected","details":["Warn: Project is vulnerable to: GHSA-968p-4wvh-cqc8","Warn: Project is vulnerable to: GHSA-67hx-6x53-jw92","Warn: Project is vulnerable to: GHSA-93q8-gq69-wqmw","Warn: Project is vulnerable to: GHSA-v6h2-p8h4-qcjw","Warn: Project is vulnerable to: GHSA-grv7-fg5c-xmjg","Warn: Project is vulnerable to: GHSA-w8qv-6jwh-64r5","Warn: Project is vulnerable to: GHSA-3xgq-45jj-v275","Warn: Project is vulnerable to: GHSA-w573-4hg7-7wgq","Warn: Project is vulnerable to: GHSA-fjxv-7rqg-78g4","Warn: Project is vulnerable to: GHSA-896r-f27r-55mw","Warn: Project is vulnerable to: GHSA-9c47-m6qq-7p4h","Warn: Project is vulnerable to: GHSA-952p-6rrq-rcjv","Warn: Project is vulnerable to: GHSA-f8q6-p94x-37v3","Warn: Project is vulnerable to: GHSA-xvch-5gv4-984h","Warn: Project is vulnerable to: GHSA-hj48-42vr-x3v9","Warn: Project is vulnerable to: GHSA-9wv6-86v2-598j","Warn: Project is vulnerable to: GHSA-hrpp-h998-j3pp","Warn: Project is vulnerable to: GHSA-p8p7-x288-28g6","Warn: Project is vulnerable to: GHSA-c2qf-rxjj-qqgw","Warn: Project is vulnerable to: GHSA-jgrx-mgxx-jf9v","Warn: Project is vulnerable to: GHSA-72xf-g2v4-qvf3","Warn: Project is vulnerable to: GHSA-j8xg-fqg3-53r7","Warn: Project is vulnerable to: GHSA-6fc8-4gx4-v693","Warn: Project is vulnerable to: GHSA-3h5v-q93c-6h6q"],"documentation":{"short":"Determines if the project has open, known unfixed vulnerabilities.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#vulnerabilities"}}]},"last_synced_at":"2025-08-18T05:31:50.104Z","repository_id":42660187,"created_at":"2025-08-18T05:31:50.105Z","updated_at":"2025-08-18T05:31:50.105Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":280370891,"owners_count":26319317,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-22T02:00:06.515Z","response_time":63,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["sunrise","sunrise-sunset-api","sunrise-times","sunset","sunset-times"],"created_at":"2025-06-17T18:08:42.652Z","updated_at":"2025-10-22T03:01:32.367Z","avatar_url":"https://github.com/dguo.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Sunrise-Sunset JS\n\n[![npm](https://img.shields.io/npm/v/sunrise-sunset-api.svg)](https://www.npmjs.com/package/sunrise-sunset-api)\n[![license](https://img.shields.io/npm/l/sunrise-sunset-api.svg)](https://github.com/dguo/sunrise-sunset-api/blob/main/LICENSE.txt)\n[![bundle size](https://img.shields.io/bundlephobia/minzip/sunrise-sunset-api)](https://bundlephobia.com/result?p=sunrise-sunset-api)\n[![CI status](https://github.com/dguo/sunrise-sunset-js/workflows/CI/badge.svg)](https://github.com/dguo/sunrise-sunset-js/actions?query=branch%3Amain)\n[![test coverage](https://codecov.io/gh/dguo/sunrise-sunset-js/branch/main/graph/badge.svg)](https://codecov.io/gh/dguo/sunrise-sunset-js)\n[![known vulnerabilities](https://snyk.io/test/github/dguo/sunrise-sunset-js/badge.svg?targetFile=package.json)](https://snyk.io/test/github/dguo/sunrise-sunset-js?targetFile=package.json)\n\nJavaScript client for the [Sunrise-Sunset API](https://sunrise-sunset.org/api).\nThis client works in browser and Node.js environments.\n\n## Installation\n\n```sh\nnpm install --save sunrise-sunset-api\n```\n\nor\n\n```sh\nyarn add sunrise-sunset-api\n```\n\n## Usage\n\n```js\nimport {getSunriseSunsetInfo} from \"sunrise-sunset-api\";\n\n(async function main() {\n    const response = await getSunriseSunsetInfo({\n        latitude: 36.72016,\n        longitude: -44.42034,\n    });\n})();\n```\n\nThe response is in this format. Note that all times are in\n[UTC](https://en.wikipedia.org/wiki/Coordinated_Universal_Time).\n\n```js\n{\n    sunrise: \"8:02:42 AM\",\n    sunset: \"9:46:40 PM\",\n    solarNoon: \"2:54:41 PM\",\n    dayLength: \"13:43:58\",\n    civilTwilightBegin: \"7:34:56 AM\",\n    civilTwilightEnd: \"10:14:26 PM\",\n    nauticalTwilightBegin: \"7:01:18 AM\",\n    nauticalTwilightEnd: \"10:48:04 PM\",\n    astronomicalTwilightBegin: \"6:25:35 AM\",\n    astronomicalTwilightEnd: \"11:23:47 PM\"\n}\n```\n\nYou can get the response for a specific date (in `YYYY-MM-DD` format) with the\n`date` option. If you don't pass a date, you'll get the response for whatever\nthe API thinks is the current date.\n\n```js\nconst response = await getSunriseSunsetInfo({\n    latitude: 36.72016,\n    longitude: -44.42034,\n    date: \"2021-10-31\"\n});\n```\n\nYou can turn off formatting with the `formatted` option.\n\n```js\nconst response = await getSunriseSunsetInfo({\n    latitude: 36.72016,\n    longitude: -44.42034,\n    formatted: false\n});\n```\n\nWhich makes the info come back in this format: `dayLength` is an integer number\nof seconds, and the times are in [ISO\n8601](https://en.wikipedia.org/wiki/ISO_8601) format.\n\n```js\n{\n    sunrise: \"2021-05-01T08:02:42+00:00\",\n    sunset: \"2021-05-01T21:46:40+00:00\",\n    solarNoon: \"2021-05-01T14:54:41+00:00\",\n    dayLength: 49438,\n    civilTwilightBegin: \"2021-05-01T07:34:56+00:00\",\n    civilTwilightEnd: \"2021-05-01T22:14:26+00:00\",\n    nauticalTwilightBegin: \"2021-05-01T07:01:18+00:00\",\n    nauticalTwilightEnd: \"2021-05-01T22:48:04+00:00\",\n    astronomicalTwilightBegin: \"2021-05-01T06:25:35+00:00\",\n    astronomicalTwilightEnd: \"2021-05-01T23:23:47+00:00\"\n}\n```\n\n## Attribution\n\nDon't forget to properly attribute the Sunrise-Sunset API with a link to\ntheir site.\n\n## Ky\n\nThis client uses [Ky](https://github.com/sindresorhus/ky) to make the API\nrequest. Be aware that Ky has a built-in\n[retry](https://github.com/sindresorhus/ky#retry) mechanism for failed requests.\n\nKy is built on the [Fetch\nAPI](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API), and here's an\nexample of how you might handle a Fetch error.\n\n```js\nimport ky from \"ky-universal\";\n\ntry {\n    const response = await getSunriseSunsetInfo({\n        latitude: 36.72016,\n        longitude: -44.42034,\n    });\n} catch (error) {\n    if (error instanceof ky.HTTPError \u0026\u0026 error.response.status === 400) {\n        // Get the actual body that the API responded with\n        console.error(await error.response.json());\n    }\n    console.error(error);\n}\n```\n\n## API\n\n### getSunriseSunsetInfo(options)\n\n#### options\n\nType: `object`\n\n##### latitude\n\nType: `number`\n\nShould be a value between -90 and 90 (inclusive).\n\n##### longitude\n\nType: `number`\n\nShould be a value between -180 and 180 (inclusive).\n\n##### date\n\nType: `string | null`\\\nDefault: `current date (according to the API)`\n\nPass this to get the info for a particular date. The value should be in a\n`YYYY-MM-DD` format.\n\n##### formatted\n\nType: `boolean`\\\nDefault: `true`\n\nFormatted responses have times like `8:02:42 AM` and a `dayLength` like\n`13:43:58` (`HH:MM:SS` format). Unformatted responses have times like\n`2021-05-01T08:02:42+00:00` (ISO 8601 format) and a `dayLength` like `49438`\n(integer number of seconds).\n\n##### apiUrl\n\nType: `string`\\\nDefault: `https://api.sunrise-sunset.org/json`\n\nPass this to override the API endpoint if it changes, and I am slow to update the\ncode.\n\n##### kyOptions\n\nType: `object`\\\nDefault: `{}`\n\nPass this to override any [Ky\noptions](https://github.com/sindresorhus/ky/blob/main/readme.md#options).\n\n##### useMocks\n\nType: `boolean`\\\nDefault: `false`\n\nTurn on [mock mode](#Mocks).\n\n## Getting the Latitude and Longitude\n\nIn the browser, you can use the [Geolocation\nAPI](https://developer.mozilla.org/en-US/docs/Web/API/Geolocation_API) to get\nthe user's latitude and longitude, assuming the user gives permission.\n\nIn a Node.js environment, you can look up the coordinates based on an IP\naddress. There are several APIs for this, like [IPinfo](https://ipinfo.io/),\n[ipstack](https://ipstack.com/), and [ipapi](https://ipapi.co/).\n\n## Types\n\nThis library is written in [TypeScript](https://www.typescriptlang.org/) and\nexports some types that you might find useful.\n\n```ts\nimport {\n    SunriseSunsetOptions,\n    UnformattedSunriseSunsetResponse,\n    FormattedSunriseSunsetResponse,\n    SunriseSunsetResponse\n} from \"sunrise-sunset-js\";\n```\n\n`SunriseSunsetOptions` describes the object that is passed to\n`getSunriseSunsetInfo`.\n\n`SunriseSunsetResponse` is just a union of the unformatted and formatted\nresponses.\n\n## Mocks\n\nFor automated tests or for any other situation where you don't want to make\nactual network requests, you can turn on mock mode, which will make the function\nreturn hardcoded responses.\n\n```js\nconst response = await getSunriseSunsetInfo({\n    latitude: 36.72016,\n    longitude: -44.42034,\n    useMocks: true\n});\n```\n\nYou can also import the mock responses.\n\n```js\nimport {\n    MOCK_FORMATTED_RESPONSE,\n    MOCK_UNFORMATTED_RESPONSE\n} from \"sunrise-sunset-js\";\n\nmockFunction.mockResolvedValue(MOCK_FORMATTED_RESPONSE);\n```\n\nOf course, you can always come up with your own mocks or overwrite specific\nfields as necessary.\n\n```js\nconst mockResponse = {\n    ...MOCK_FORMATTED_RESPONSE,\n    dayLength: \"12:00:00\"\n}\n```\n\n## License\n\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdguo%2Fsunrise-sunset-js","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdguo%2Fsunrise-sunset-js","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdguo%2Fsunrise-sunset-js/lists"}