Skip to content

Commit

Permalink
Initial version
Browse files Browse the repository at this point in the history
  • Loading branch information
faisalman committed Sep 8, 2023
1 parent 78be360 commit e4dd474
Show file tree
Hide file tree
Showing 13 changed files with 1,571 additions and 0 deletions.
12 changes: 12 additions & 0 deletions .github/funding.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# These are supported funding model platforms

github: faisalman
patreon: # Replace with a single Patreon username
open_collective: ua-parser-js
ko_fi: # Replace with a single Ko-fi username
tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel
community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry
liberapay: # Replace with a single Liberapay username
issuehunt: # Replace with a single IssueHunt username
otechie: # Replace with a single Otechie username
custom: ['https://www.paypal.me/faisalman/']
25 changes: 25 additions & 0 deletions .github/workflows/npm-publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# This workflow will run tests using node and then publish a package to GitHub Packages when a release is created
# For more information see: https://docs.github.com/en/actions/publishing-packages/publishing-nodejs-packages

name: Publish Package to npmjs
on:
push:
tags:
- '*'
jobs:
build:
runs-on: ubuntu-latest
permissions:
contents: read
id-token: write
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: '18.x'
registry-url: 'https://registry.npmjs.org'
- run: npm install -g npm
- run: npm ci
- run: npm publish --provenance --access public
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
129 changes: 129 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log*
.pnpm-debug.log*

# Diagnostic reports (https://nodejs.org/api/report.html)
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json

# Runtime data
pids
*.pid
*.seed
*.pid.lock

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage
*.lcov

# nyc test coverage
.nyc_output

# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# Bower dependency directory (https://bower.io/)
bower_components

# node-waf configuration
.lock-wscript

# Compiled binary addons (https://nodejs.org/api/addons.html)
build/Release

# Dependency directories
node_modules/
jspm_packages/

# Snowpack dependency directory (https://snowpack.dev/)
web_modules/

# TypeScript cache
*.tsbuildinfo

# Optional npm cache directory
.npm

# Optional eslint cache
.eslintcache

# Optional stylelint cache
.stylelintcache

# Microbundle cache
.rpt2_cache/
.rts2_cache_cjs/
.rts2_cache_es/
.rts2_cache_umd/

# Optional REPL history
.node_repl_history

# Output of 'npm pack'
*.tgz

# Yarn Integrity file
.yarn-integrity

# dotenv environment variable files
.env
.env.development.local
.env.test.local
.env.production.local
.env.local

# parcel-bundler cache (https://parceljs.org/)
.cache
.parcel-cache

# Next.js build output
.next
out

# Nuxt.js build / generate output
.nuxt

# Gatsby files
.cache/
# Comment in the public line in if your project uses Gatsby and not Next.js
# https://nextjs.org/blog/next-9-1#public-directory-support
# public

# vuepress build output
.vuepress/dist

# vuepress v2.x temp and cache directory
.temp
.cache

# Docusaurus cache and generated files
.docusaurus

# Serverless directories
.serverless/

# FuseBox cache
.fusebox/

# DynamoDB Local files
.dynamodb/

# TernJS port file
.tern-port

# Stores VSCode versions used for testing VSCode extensions
.vscode-test

# yarn v2
.yarn/cache
.yarn/unplugged
.yarn/build-state.yml
.yarn/install-state.gz
.pnp.*
22 changes: 22 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# GPUDetect.js
Extracts GPU information from the browser

```sh
npm i gpu-detect-js
```

## Methods

`getGPU():GPUInfo`

`interface GPUInfo { vendor: string | undefined; model: string | undefined }`

## Code Example

```js
import { GPUDetect } from 'gpu-detect-js';

const gpuInfo = GPUDetect.getGPU();
console.log(gpuInfo);
// { vendor: "AMD", model: "Radeon R9 M295X" }
```
13 changes: 13 additions & 0 deletions dist/cjs/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/*! GPUDetect.js
Extracts GPU information from the browser
https://github.com/faisalman/ua-parser-js
Author: Faisal Salman <f@faisalman.com>
MIT License */
interface GPUInfo {
vendor: string | undefined;
model: string | undefined;
}
export declare class GPUDetect {
static getGPU(strRenderer?: string, strVendor?: string): GPUInfo;
}
export {};
68 changes: 68 additions & 0 deletions dist/cjs/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
"use strict";
/*! GPUDetect.js
Extracts GPU information from the browser
https://github.com/faisalman/ua-parser-js
Author: Faisal Salman <f@faisalman.com>
MIT License */
Object.defineProperty(exports, "__esModule", { value: true });
exports.GPUDetect = void 0;
var re_parse_js_1 = require("re-parse-js");
var rendererMap = [
[
[
/(intel).*\b(hd\sgraphics\s\d{4}|iris(?:\spro)|gma\s\w+)/i,
/(nvidia)\s(geforce\s(?:gtx?\s)\d\w+|quadro)/i,
/\b(sis)\s(\w+)/i
],
['vendor', 'model']
],
[
[
/\b(radeon[\shdr\d]+\w{4,5})/i
], ['model', ['vendor', 'AMD']]
],
[
[
/(adreno\s(?:\(tm\)\s)\w+)/i
],
[['model', /\(tm\)\s/i, ''], ['vendor', 'Qualcomm']]
]
];
var vendorMap = [
[[
/\b(amd|apple|arm|ati|img|intel|nvidia|qualcomm|samsung|sis)\b/i
], ['vendor']]
];
;
var GPUDetect = (function () {
function GPUDetect() {
}
GPUDetect.getGPU = function (strRenderer, strVendor) {
var _a;
var _b, _c;
var gpuInfo = { vendor: undefined, model: undefined };
if (typeof strRenderer !== 'string') {
if (globalThis.document) {
var canvas = document.createElement('canvas');
var gl = (canvas.getContext('webgl2') ||
canvas.getContext('webgl') ||
canvas.getContext('experimental-webgl'));
if (gl) {
var debugInfo = gl.getExtension('WEBGL_debug_renderer_info');
strVendor = gl.getParameter((debugInfo === null || debugInfo === void 0 ? void 0 : debugInfo.UNMASKED_VENDOR_WEBGL) || 0);
strRenderer = gl.getParameter((debugInfo === null || debugInfo === void 0 ? void 0 : debugInfo.UNMASKED_RENDERER_WEBGL) || 0);
}
}
}
if (strRenderer) {
var re = new re_parse_js_1.REParse();
(_a = re.use(rendererMap).parse(strRenderer), gpuInfo.vendor = _a.vendor, gpuInfo.model = _a.model);
if (strVendor) {
gpuInfo.vendor = gpuInfo.vendor || ((_b = re.parse(strVendor)) === null || _b === void 0 ? void 0 : _b.vendor) || ((_c = re.use(vendorMap).parse(strVendor)) === null || _c === void 0 ? void 0 : _c.vendor);
}
}
return gpuInfo;
};
return GPUDetect;
}());
exports.GPUDetect = GPUDetect;
13 changes: 13 additions & 0 deletions dist/esm/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/*! GPUDetect.js
Extracts GPU information from the browser
https://github.com/faisalman/ua-parser-js
Author: Faisal Salman <f@faisalman.com>
MIT License */
interface GPUInfo {
vendor: string | undefined;
model: string | undefined;
}
export declare class GPUDetect {
static getGPU(strRenderer?: string, strVendor?: string): GPUInfo;
}
export {};
60 changes: 60 additions & 0 deletions dist/esm/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/*! GPUDetect.js
Extracts GPU information from the browser
https://github.com/faisalman/ua-parser-js
Author: Faisal Salman <f@faisalman.com>
MIT License */
import { REParse } from 're-parse-js';
const rendererMap = [
[
[
/(intel).*\b(hd\sgraphics\s\d{4}|iris(?:\spro)|gma\s\w+)/i,
/(nvidia)\s(geforce\s(?:gtx?\s)\d\w+|quadro)/i,
/\b(sis)\s(\w+)/i
],
['vendor', 'model']
],
[
[
/\b(radeon[\shdr\d]+\w{4,5})/i
], ['model', ['vendor', 'AMD']]
],
[
[
/(adreno\s(?:\(tm\)\s)\w+)/i
],
[['model', /\(tm\)\s/i, ''], ['vendor', 'Qualcomm']]
]
];
const vendorMap = [
[[
/\b(amd|apple|arm|ati|img|intel|nvidia|qualcomm|samsung|sis)\b/i
], ['vendor']]
];
;
export class GPUDetect {
static getGPU(strRenderer, strVendor) {
var _a, _b;
let gpuInfo = { vendor: undefined, model: undefined };
if (typeof strRenderer !== 'string') {
if (globalThis.document) {
const canvas = document.createElement('canvas');
const gl = (canvas.getContext('webgl2') ||
canvas.getContext('webgl') ||
canvas.getContext('experimental-webgl'));
if (gl) {
const debugInfo = gl.getExtension('WEBGL_debug_renderer_info');
strVendor = gl.getParameter((debugInfo === null || debugInfo === void 0 ? void 0 : debugInfo.UNMASKED_VENDOR_WEBGL) || 0);
strRenderer = gl.getParameter((debugInfo === null || debugInfo === void 0 ? void 0 : debugInfo.UNMASKED_RENDERER_WEBGL) || 0);
}
}
}
if (strRenderer) {
const re = new REParse();
({ vendor: gpuInfo.vendor, model: gpuInfo.model } = re.use(rendererMap).parse(strRenderer));
if (strVendor) {
gpuInfo.vendor = gpuInfo.vendor || ((_a = re.parse(strVendor)) === null || _a === void 0 ? void 0 : _a.vendor) || ((_b = re.use(vendorMap).parse(strVendor)) === null || _b === void 0 ? void 0 : _b.vendor);
}
}
return gpuInfo;
}
}
Loading

0 comments on commit e4dd474

Please sign in to comment.