Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add platform package #939

Merged
merged 1 commit into from
Oct 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions apps/demo/src/app/app.routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ export const ROUTES: Routes = [
path: DemoPath.CommonPage,
loadComponent: async () => import('./pages/common/common-page.component'),
},
{
path: DemoPath.PlatformPage,
loadComponent: async () => import('./pages/platform'),
},
{
path: DemoPath.UniversalPage,
loadComponent: async () => import('./pages/universal/universal-page.component'),
Expand Down
1 change: 1 addition & 0 deletions apps/demo/src/app/constants/demo-path.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
export enum DemoPath {
HomePage = 'home',
CommonPage = 'common',
PlatformPage = 'platform',
UniversalPage = 'universal',
AudioPage = 'audio',
ResizeObserverPage = 'resize-observer',
Expand Down
18 changes: 18 additions & 0 deletions apps/demo/src/app/pages/home/home-page.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,24 @@ <h2>Common</h2>
class="icon"
/>
</a>
<a
class="link"
[routerLink]="['/', link.PlatformPage]"
>
<div>
<h2>Platform</h2>
Reusable javascript
<strong>Web APIs</strong>
utils between Node.js and Browser
</div>
<img
alt="Platform utils logo"
height="64"
src="assets/logos/platform/logo.svg"
width="64"
class="icon"
/>
</a>
<a
class="link"
[routerLink]="['/', link.UniversalPage]"
Expand Down
1 change: 1 addition & 0 deletions apps/demo/src/app/pages/platform/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<markdown [data]="(readme | async) || ''" />
16 changes: 16 additions & 0 deletions apps/demo/src/app/pages/platform/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import {CommonModule} from '@angular/common';
import {ChangeDetectionStrategy, Component} from '@angular/core';
import {MarkdownModule} from 'ngx-markdown';

@Component({
standalone: true,
selector: 'platform-page',
imports: [CommonModule, MarkdownModule],
templateUrl: './index.html',
changeDetection: ChangeDetectionStrategy.OnPush,
})
export default class CommonPage {
protected readonly readme = import(
'../../../../../../libs/platform/README.md?raw'
).then((a) => a.default.replace('![logo](logo.svg) ', '')) as any as Promise<string>;
}
10 changes: 10 additions & 0 deletions libs/platform/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# ![ng-web-apis logo](https://raw.githubusercontent.com/taiga-family/ng-web-apis/main/libs/platform/logo.svg) Platform

## Install

```bash
npm i @ng-web-apis/platform
```

- `isApple`
- `isIos`
21 changes: 21 additions & 0 deletions libs/platform/logo.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 11 additions & 0 deletions libs/platform/ng-package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"$schema": "../../node_modules/ng-packagr/ng-package.schema.json",
"assets": [
"logo.svg",
"README.md"
],
"dest": "../../dist/platform",
"lib": {
"entryFile": "src/index.ts"
}
}
18 changes: 18 additions & 0 deletions libs/platform/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"name": "@ng-web-apis/platfrorm",
"version": "4.6.5",
"description": "A basic library for web apis",
"keywords": [
"angular",
"ng",
"web",
"platform"
],
"homepage": "https://github.com/taiga-family/ng-web-apis/blob/main/libs/platform/README.md",
"bugs": "https://github.com/taiga-family/ng-web-apis/issues",
"repository": "https://github.com/taiga-family/ng-web-apis",
"license": "Apache-2.0",
"publishConfig": {
"access": "public"
}
}
42 changes: 42 additions & 0 deletions libs/platform/project.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
{
"name": "platform",
"$schema": "../../node_modules/nx/schemas/project-schema.json",
"sourceRoot": "libs/platform",
"projectType": "library",
"targets": {
"build": {
"executor": "@nx/rollup:rollup",
"outputs": ["{workspaceRoot}/dist/{projectName}"],
"options": {
"project": "{projectRoot}/package.json",
"outputPath": "dist/{projectName}",
"entryFile": "{projectRoot}/src/index.ts",
"tsConfig": "{projectRoot}/tsconfig.lib.json",
"format": ["esm", "cjs"],
"compiler": "tsc",
"external": "all",
"assets": [
{
"glob": "{projectRoot}/README.md",
"input": ".",
"output": "."
}
]
}
},
"publish": {
"executor": "nx:run-commands",
"options": {
"parallel": false,
"commands": ["cp ./LICENSE ./dist/{projectName}", "npm publish ./dist/{projectName} --ignore-scripts"]
},
"dependsOn": [
{
"target": "build",
"params": "ignore",
"dependencies": false
}
]
}
}
}
2 changes: 2 additions & 0 deletions libs/platform/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from './is-apple';
export * from './is-ios';
13 changes: 13 additions & 0 deletions libs/platform/src/is-apple.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/**
* @description:
* All Chrome / Chromium-based browsers will return MacIntel on macOS,
* no matter what the hardware architecture is. See the source code here:
* https://source.chromium.org/chromium/chromium/src/+/master:third_party/blink/renderer/core/frame/navigator_id.cc;l=64;drc=703d3c472cf27470dad21a3f2c8972aca3732cd6
* But maybe in future years, it will be changed to MacM1
*
* Documentation:
* https://developer.mozilla.org/en-US/docs/Web/API/Navigator/platform
*/
export function isApple(navigator: Navigator): boolean {
return navigator.platform.startsWith('Mac') || navigator.platform === 'iPhone';
}
10 changes: 10 additions & 0 deletions libs/platform/src/is-ios.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import {isApple} from './is-apple';

const IOS_REG_EXP = /ipad|iphone|ipod/;

export function isIos(navigator: Navigator): boolean {
return (
IOS_REG_EXP.test(navigator.userAgent.toLowerCase()) ||
(isApple(navigator) && navigator.maxTouchPoints > 1)
);
}
5 changes: 5 additions & 0 deletions libs/platform/tsconfig.lib.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"extends": "../../tsconfig.build.json",
"files": ["src/index.ts"],
"include": ["src/*"]
}
Loading