From f8f71c65d48292dbd30ed1db6c2dfb1e9dadac61 Mon Sep 17 00:00:00 2001 From: Faisal Salman Date: Tue, 24 Oct 2023 11:14:28 +0700 Subject: [PATCH] Add new helpers submodule --- package.json | 4 ++++ script/build-module.js | 6 ++++++ src/helpers/ua-parser-helpers.d.ts | 11 +++++++++++ src/helpers/ua-parser-helpers.js | 20 ++++++++++++++++++++ 4 files changed, 41 insertions(+) create mode 100644 src/helpers/ua-parser-helpers.d.ts create mode 100644 src/helpers/ua-parser-helpers.js diff --git a/package.json b/package.json index 35a3f0604..15c4746bb 100644 --- a/package.json +++ b/package.json @@ -183,6 +183,10 @@ "./extensions": { "require": "./src/extensions/ua-parser-extensions.js", "import": "./src/extensions/ua-parser-extensions.mjs" + }, + "./helpers": { + "require": "./src/extensions/ua-parser-helpers.js", + "import": "./src/extensions/ua-parser-helpers.mjs" } }, "files": [ diff --git a/script/build-module.js b/script/build-module.js index f8079233c..98fb8dbb2 100755 --- a/script/build-module.js +++ b/script/build-module.js @@ -46,6 +46,12 @@ const modules = [ dest : 'src/extensions/ua-parser-extensions.mjs', title : 'ua-parser-js/extensions', replacements : [] + }, + { + src : 'src/helpers/ua-parser-helpers.js', + dest : 'src/helpers/ua-parser-helpers.mjs', + title : 'ua-parser-js/helpers', + replacements : [] } ]; diff --git a/src/helpers/ua-parser-helpers.d.ts b/src/helpers/ua-parser-helpers.d.ts new file mode 100644 index 000000000..6a0e5705f --- /dev/null +++ b/src/helpers/ua-parser-helpers.d.ts @@ -0,0 +1,11 @@ +// Type definitions for Helpers submodule of UAParser.js v2.0.0-beta.1 +// Project: https://github.com/faisalman/ua-parser-js +// Definitions by: Faisal Salman + +import { IResult } from "../main/ua-parser"; + +declare function isAppleSilicon(res:IResult): boolean; + +export { + isAppleSilicon +} \ No newline at end of file diff --git a/src/helpers/ua-parser-helpers.js b/src/helpers/ua-parser-helpers.js new file mode 100644 index 000000000..180c8f211 --- /dev/null +++ b/src/helpers/ua-parser-helpers.js @@ -0,0 +1,20 @@ +/////////////////////////////////////////////// +/* Helpers for UAParser.js v2.0.0-beta.1 + https://github.com/faisalman/ua-parser-js + Author: Faisal Salman + AGPLv3 License */ +////////////////////////////////////////////// + +/*jshint esversion: 6 */ + +const { CPU, OS } = require('../enums/ua-parser-enums'); + +const isAppleSilicon = function (res) { + return res.os.is(OS.MACOS) && res.cpu.is(CPU.ARM); +} + +module.exports = { + isAppleSilicon +} + +// TODO: create test \ No newline at end of file