1 import { Pipe, PipeTransform } from '@angular/core';
4 name: 'octalToHumanReadable'
6 export class OctalToHumanReadablePipe implements PipeTransform {
7 transform(value: number, toTableArray = false): any {
11 const permissionSummary = [];
12 const permissions = ['---', '--x', '-w-', '-wx', 'r--', 'r-x', 'rw-', 'rwx'];
13 const octal = value.toString(8).padStart(7, '0');
14 const digits = octal.split('');
16 const fileType = this.getFileTypeSymbol(parseInt(digits[1] + digits[2]));
17 const owner = permissions[parseInt(digits[4])];
18 const group = permissions[parseInt(digits[5])];
19 const others = permissions[parseInt(digits[6])];
23 owner: this.getItem(owner),
24 group: this.getItem(group),
25 others: this.getItem(others)
29 if (fileType !== 'directory') {
30 permissionSummary.push({
32 class: 'badge-primary me-1'
36 if (owner !== '---') {
37 permissionSummary.push({
38 content: `owner: ${owner}`,
39 class: 'badge-primary me-1'
43 if (group !== '---') {
44 permissionSummary.push({
45 content: `group: ${group}`,
46 class: 'badge-primary me-1'
50 if (others !== '---') {
51 permissionSummary.push({
52 content: `others: ${others}`,
53 class: 'badge-primary me-1'
57 if (permissionSummary.length === 0) {
60 content: 'no permissions',
61 class: 'badge-warning me-1',
62 toolTip: `owner: ${owner}, group: ${group}, others: ${others}`
67 return permissionSummary;
70 private getFileTypeSymbol(fileType: number): string {
83 return 'symbolic-link';
89 private getItem(item: string) {
90 const returnlist = [];
91 if (item.includes('r')) returnlist.push('read');
92 if (item.includes('w')) returnlist.push('write');
93 if (item.includes('x')) returnlist.push('execute');