mirror of
https://github.com/Start9Labs/start-os.git
synced 2026-03-30 04:01:58 +00:00
chore: update packages (#3132)
* chore: update packages * start tunnel messaging * chore: standalone * pbpaste instead --------- Co-authored-by: Matt Hill <mattnine@protonmail.com>
This commit is contained in:
22
web/projects/shared/src/pipes/convert-bytes.pipe.ts
Normal file
22
web/projects/shared/src/pipes/convert-bytes.pipe.ts
Normal file
@@ -0,0 +1,22 @@
|
||||
import { Pipe, PipeTransform } from '@angular/core'
|
||||
|
||||
// converts bytes to gigabytes
|
||||
@Pipe({
|
||||
name: 'convertBytes',
|
||||
})
|
||||
export class ConvertBytesPipe implements PipeTransform {
|
||||
transform(bytes: number): string {
|
||||
return convertBytes(bytes)
|
||||
}
|
||||
}
|
||||
|
||||
export function convertBytes(bytes: number): string {
|
||||
if (bytes === 0) return '0 Bytes'
|
||||
|
||||
const k = 1024
|
||||
const i = Math.floor(Math.log(bytes) / Math.log(k))
|
||||
|
||||
return parseFloat((bytes / Math.pow(k, i)).toFixed(1)) + ' ' + sizes[i]
|
||||
}
|
||||
|
||||
const sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB']
|
||||
@@ -1,13 +1,11 @@
|
||||
import { Pipe, PipeTransform } from '@angular/core'
|
||||
import { isEmptyObject } from '../../util/misc.util'
|
||||
import { isEmptyObject } from '../util/misc.util'
|
||||
|
||||
@Pipe({
|
||||
name: 'empty',
|
||||
standalone: false,
|
||||
})
|
||||
export class EmptyPipe implements PipeTransform {
|
||||
transform(val: object | [] = {}): boolean {
|
||||
if (Array.isArray(val)) return !val.length
|
||||
return isEmptyObject(val)
|
||||
return Array.isArray(val) ? !val.length : isEmptyObject(val)
|
||||
}
|
||||
}
|
||||
@@ -1,28 +1,11 @@
|
||||
import { Pipe, PipeTransform } from '@angular/core'
|
||||
import { Exver } from '../../services/exver.service'
|
||||
|
||||
@Pipe({
|
||||
name: 'satisfiesExver',
|
||||
standalone: false,
|
||||
})
|
||||
export class ExverSatisfiesPipe implements PipeTransform {
|
||||
constructor(private readonly exver: Exver) {}
|
||||
|
||||
transform(versionUnderTest?: string, range?: string): boolean {
|
||||
return (
|
||||
!!versionUnderTest &&
|
||||
!!range &&
|
||||
this.exver.satisfies(versionUnderTest, range)
|
||||
)
|
||||
}
|
||||
}
|
||||
import { inject, Pipe, PipeTransform } from '@angular/core'
|
||||
import { Exver } from '../services/exver.service'
|
||||
|
||||
@Pipe({
|
||||
name: 'compareExver',
|
||||
standalone: false,
|
||||
})
|
||||
export class ExverComparesPipe implements PipeTransform {
|
||||
constructor(private readonly exver: Exver) {}
|
||||
private readonly exver = inject(Exver)
|
||||
|
||||
transform(first: string, second: string): SemverResult {
|
||||
try {
|
||||
@@ -1,8 +0,0 @@
|
||||
import { NgModule } from '@angular/core'
|
||||
import { ExverComparesPipe, ExverSatisfiesPipe } from './exver.pipe'
|
||||
|
||||
@NgModule({
|
||||
declarations: [ExverComparesPipe, ExverSatisfiesPipe],
|
||||
exports: [ExverComparesPipe, ExverSatisfiesPipe],
|
||||
})
|
||||
export class ExverPipesModule {}
|
||||
@@ -1,11 +0,0 @@
|
||||
import { Pipe, PipeTransform } from '@angular/core'
|
||||
|
||||
@Pipe({
|
||||
name: 'includes',
|
||||
standalone: false,
|
||||
})
|
||||
export class IncludesPipe implements PipeTransform {
|
||||
transform<T>(list: T[], val: T): boolean {
|
||||
return list.includes(val)
|
||||
}
|
||||
}
|
||||
@@ -1,10 +0,0 @@
|
||||
import { NgModule } from '@angular/core'
|
||||
import { IncludesPipe } from './includes.pipe'
|
||||
import { EmptyPipe } from './empty.pipe'
|
||||
import { TrustUrlPipe } from './trust.pipe'
|
||||
|
||||
@NgModule({
|
||||
declarations: [IncludesPipe, EmptyPipe, TrustUrlPipe],
|
||||
exports: [IncludesPipe, EmptyPipe, TrustUrlPipe],
|
||||
})
|
||||
export class SharedPipesModule {}
|
||||
@@ -1,35 +0,0 @@
|
||||
import { Pipe, PipeTransform } from '@angular/core'
|
||||
|
||||
@Pipe({
|
||||
name: 'sort',
|
||||
standalone: false,
|
||||
})
|
||||
export class SortPipe implements PipeTransform {
|
||||
transform(
|
||||
value: any[],
|
||||
column: string = '',
|
||||
direction: string = 'asc',
|
||||
): any[] {
|
||||
// If the value is not an array or is empty, return the original value
|
||||
if (!Array.isArray(value) || value.length === 0) {
|
||||
return value
|
||||
}
|
||||
|
||||
// Clone the array to avoid modifying the original value
|
||||
const sortedValue = [...value]
|
||||
|
||||
// Define the sorting function based on the column and direction parameters
|
||||
const sortingFn = (a: any, b: any): number => {
|
||||
if (a[column] < b[column]) {
|
||||
return direction === 'asc' ? -1 : 1
|
||||
} else if (a[column] > b[column]) {
|
||||
return direction === 'asc' ? 1 : -1
|
||||
} else {
|
||||
return 0
|
||||
}
|
||||
}
|
||||
|
||||
// Sort the array and return the result
|
||||
return sortedValue.sort(sortingFn)
|
||||
}
|
||||
}
|
||||
@@ -1,12 +1,11 @@
|
||||
import { Pipe, PipeTransform } from '@angular/core'
|
||||
import { inject, Pipe, PipeTransform } from '@angular/core'
|
||||
import { DomSanitizer, SafeResourceUrl } from '@angular/platform-browser'
|
||||
|
||||
@Pipe({
|
||||
name: 'trustUrl',
|
||||
standalone: false,
|
||||
})
|
||||
export class TrustUrlPipe implements PipeTransform {
|
||||
constructor(private readonly sanitizer: DomSanitizer) {}
|
||||
private readonly sanitizer = inject(DomSanitizer)
|
||||
|
||||
transform(base64Icon: string): SafeResourceUrl {
|
||||
return this.sanitizer.bypassSecurityTrustResourceUrl(base64Icon)
|
||||
@@ -1,8 +0,0 @@
|
||||
import { NgModule } from '@angular/core'
|
||||
import { ConvertBytesPipe, DurationToSecondsPipe } from './unit-conversion.pipe'
|
||||
|
||||
@NgModule({
|
||||
declarations: [ConvertBytesPipe, DurationToSecondsPipe],
|
||||
exports: [ConvertBytesPipe, DurationToSecondsPipe],
|
||||
})
|
||||
export class UnitConversionPipesModule {}
|
||||
@@ -1,49 +0,0 @@
|
||||
import { Pipe, PipeTransform } from '@angular/core'
|
||||
|
||||
// converts bytes to gigabytes
|
||||
@Pipe({
|
||||
name: 'convertBytes',
|
||||
standalone: false,
|
||||
})
|
||||
export class ConvertBytesPipe implements PipeTransform {
|
||||
transform(bytes: number): string {
|
||||
return convertBytes(bytes)
|
||||
}
|
||||
}
|
||||
|
||||
export function convertBytes(bytes: number): string {
|
||||
if (bytes === 0) return '0 Bytes'
|
||||
|
||||
const k = 1024
|
||||
const i = Math.floor(Math.log(bytes) / Math.log(k))
|
||||
|
||||
return parseFloat((bytes / Math.pow(k, i)).toFixed(1)) + ' ' + sizes[i]
|
||||
}
|
||||
|
||||
@Pipe({
|
||||
name: 'durationToSeconds',
|
||||
standalone: false,
|
||||
})
|
||||
export class DurationToSecondsPipe implements PipeTransform {
|
||||
transform(duration?: string | null): number {
|
||||
if (!duration) return 0
|
||||
|
||||
const regex = /^([0-9]*(\.[0-9]+)?)(ns|µs|ms|s|m|d)$/
|
||||
const [, num, , unit] = duration.match(regex) || []
|
||||
const multiplier = (unit && unitsToSeconds[unit]) || NaN
|
||||
|
||||
return unit ? Number(num) * multiplier : NaN
|
||||
}
|
||||
}
|
||||
|
||||
const sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB']
|
||||
|
||||
const unitsToSeconds: Record<string, number> = {
|
||||
ns: 1e-9,
|
||||
µs: 1e-6,
|
||||
ms: 0.001,
|
||||
s: 1,
|
||||
m: 60,
|
||||
h: 3600,
|
||||
d: 86400,
|
||||
}
|
||||
@@ -20,14 +20,10 @@ export * from './i18n/i18n.providers'
|
||||
export * from './i18n/i18n.service'
|
||||
export * from './i18n/localize.pipe'
|
||||
|
||||
export * from './pipes/exver/exver.module'
|
||||
export * from './pipes/exver/exver.pipe'
|
||||
export * from './pipes/shared/shared.module'
|
||||
export * from './pipes/shared/empty.pipe'
|
||||
export * from './pipes/shared/includes.pipe'
|
||||
export * from './pipes/shared/trust.pipe'
|
||||
export * from './pipes/unit-conversion/unit-conversion.module'
|
||||
export * from './pipes/unit-conversion/unit-conversion.pipe'
|
||||
export * from './pipes/exver-compares.pipe'
|
||||
export * from './pipes/empty.pipe'
|
||||
export * from './pipes/trust.pipe'
|
||||
export * from './pipes/convert-bytes.pipe'
|
||||
export * from './pipes/markdown.pipe'
|
||||
|
||||
export * from './services/copy.service'
|
||||
|
||||
Reference in New Issue
Block a user