Skip to content

Commit

Permalink
feat: add platform package
Browse files Browse the repository at this point in the history
  • Loading branch information
splincode committed Oct 8, 2024
1 parent e205530 commit 6ceca15
Show file tree
Hide file tree
Showing 21 changed files with 2,490 additions and 126 deletions.
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>;
}
23 changes: 23 additions & 0 deletions libs/platform/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# ![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
```

## Examples

`isArray`

```ts
expect(isArray([])).toBeTruthy();
expect(isArray(new Array())).toBeTruthy();
```

`toArray`

```ts
expect(toArray(1)).toEqual([1]);
expect(toArray([1])).toEqual([1]);
```
45 changes: 45 additions & 0 deletions libs/platform/karma.conf.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// Karma configuration file, see link for more information
// https://karma-runner.github.io/1.0/config/configuration-file.html

module.exports = function (config) {
config.set({
basePath: '',
frameworks: ['jasmine', '@angular-devkit/build-angular'],
plugins: [
require('karma-jasmine'),
require('karma-chrome-launcher'),
require('karma-jasmine-html-reporter'),
require('@angular-devkit/build-angular/plugins/karma'),
require('karma-coverage'),
],
client: {
clearContext: true, // leave Jasmine Spec Runner output visible in browser
},
preprocessors: {
'src/**/*.js': ['coverage'],
},
coverageReporter: {
type: 'html',
dir: require('node:path').join(__dirname, '../../coverage/payment-request'),
},
reporters: ['progress', 'kjhtml'],
port: 9876,
colors: true,
logLevel: config.LOG_INFO,
autoWatch: true,
browsers: ['ChromeHeadless'],
singleRun: true,
customLaunchers: {
ChromeHeadless: {
base: 'Chrome',
flags: [
'--no-sandbox',
'--headless',
'--disable-gpu',
'--disable-web-security',
'--remote-debugging-port=9222',
],
},
},
});
};
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"
}
}
53 changes: 53 additions & 0 deletions libs/platform/project.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
{
"name": "platform",
"$schema": "../../node_modules/nx/schemas/project-schema.json",
"sourceRoot": "libs/platform",
"projectType": "library",
"targets": {
"test": {
"executor": "@angular-devkit/build-angular:karma",
"outputs": ["{workspaceRoot}/coverage/{projectName}"],
"options": {
"main": "libs/{projectName}/test.ts",
"tsConfig": "tsconfig.spec.json",
"karmaConfig": "libs/{projectName}/karma.conf.js",
"codeCoverage": true,
"browsers": "ChromeHeadless"
}
},
"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-ios';
export * from './is-apple';
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)
);
}
13 changes: 13 additions & 0 deletions libs/platform/test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import 'zone.js';
import 'zone.js/testing';

import {getTestBed} from '@angular/core/testing';
import {
BrowserDynamicTestingModule,
platformBrowserDynamicTesting,
} from '@angular/platform-browser-dynamic/testing';

getTestBed().initTestEnvironment(
BrowserDynamicTestingModule,
platformBrowserDynamicTesting(),
);
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/*"]
}
4 changes: 4 additions & 0 deletions libs/platform/tsconfig.spec.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"extends": "../../tsconfig.spec.json",
"include": ["**/*.spec.ts", "test.ts", "**/*.d.ts"]
}
Loading

0 comments on commit 6ceca15

Please sign in to comment.