Skip to content

Commit

Permalink
feat: ES Module (#72)
Browse files Browse the repository at this point in the history
BREAKING CHANGE: This package is now pure ESM

BREAKING CHANGE: Node 12+ required
  • Loading branch information
gr2m authored Sep 16, 2021
1 parent 80dbe28 commit 31029b5
Show file tree
Hide file tree
Showing 12 changed files with 1,525 additions and 18,094 deletions.
30 changes: 21 additions & 9 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,36 @@ on:
push:
branches:
- master
- "greenkeeper/**"
pull_request:
types: [opened, synchronize]
types:
- opened
- synchronize

jobs:
test:
test_matrix:
runs-on: ubuntu-latest
strategy:
matrix:
node_version: [10, 12, 14]
node_version:
- 12
- 14
- 16

steps:
- uses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node_version }}
uses: actions/setup-node@v1
uses: actions/setup-node@v2
with:
node-version: ${{ matrix.node_version }}
- name: Install
run: npm ci
- name: Test
run: npm test
cache: npm
- run: npm ci
- run: npm run test:code

test:
runs-on: ubuntu-latest
needs: test_matrix
steps:
- uses: actions/checkout@v2
- run: npm ci
- run: npm run lint
- run: npm run test:types
4 changes: 1 addition & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
coverage
node_modules
pkg
node_modules
2 changes: 1 addition & 1 deletion LICENSE.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# [ISC License](https://spdx.org/licenses/ISC)

Copyright (c) 2018, Gregor Martynus (https://github.com/gr2m)
Copyright (c) 2018-2021, Gregor Martynus (https://github.com/gr2m)

Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies.

Expand Down
9 changes: 2 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
# universal-user-agent

> Get a user agent string in both browser and node
> Get a user agent string across all JavaScript Runtime Environments
[![@latest](https://img.shields.io/npm/v/universal-user-agent.svg)](https://www.npmjs.com/package/universal-user-agent)
[![Build Status](https://github.com/gr2m/universal-user-agent/workflows/Test/badge.svg)](https://github.com/gr2m/universal-user-agent/actions?query=workflow%3ATest+branch%3Amaster)
[![Greenkeeper](https://badges.greenkeeper.io/gr2m/universal-user-agent.svg)](https://greenkeeper.io/)
[![Build Status](https://github.com/gr2m/universal-user-agent/workflows/Test/badge.svg)](https://github.com/gr2m/universal-user-agent/actions/workflows/test.yml?query=workflow%3ATest)

```js
const { getUserAgent } = require("universal-user-agent");
Expand All @@ -16,10 +15,6 @@ const userAgent = getUserAgent();
// in node: Node.js/v8.9.4 (macOS High Sierra; x64)
```

## Credits

The Node implementation was originally inspired by [default-user-agent](https://www.npmjs.com/package/default-user-agent).

## License

[ISC](LICENSE.md)
4 changes: 4 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/**
* Returns a User Agent String based on the current environment (Browser, Node, Deno, etc).
*/
export function getUserAgent(): string;
2 changes: 1 addition & 1 deletion src/index.ts → index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export function getUserAgent(): string {
export function getUserAgent() {
if (typeof navigator === "object" && "userAgent" in navigator) {
return navigator.userAgent;
}
Expand Down
5 changes: 5 additions & 0 deletions index.test-d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { expectType } from "tsd";

import { getUserAgent } from "./index.js";

expectType<string>(getUserAgent());
Loading

0 comments on commit 31029b5

Please sign in to comment.