Skip to content

Commit 93ef73b

Browse files
authored
client(common): byteSize function (jhipster#31984)
1 parent 3d1604e commit 93ef73b

File tree

3 files changed

+9
-6
lines changed

3 files changed

+9
-6
lines changed

generators/angular/templates/src/main/webapp/app/core/util/data-util.service.ts.ejs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import { Injectable } from '@angular/core';
2020
import { FormGroup } from '@angular/forms';
2121
import { Observable, Observer } from 'rxjs';
2222

23-
import { formatAsBytes, openFile, paddingSize, size, toBase64 } from 'app/shared/jhipster/data-utils';
23+
import { byteSize, openFile, paddingSize, toBase64 } from 'app/shared/jhipster/data-utils';
2424

2525
export type FileLoadErrorType = 'not.image' | 'could.not.extract';
2626

@@ -41,7 +41,7 @@ export class DataUtils {
4141
* Method to find the byte size of the string provides
4242
*/
4343
byteSize(base64String: string): string {
44-
return formatAsBytes(size(base64String));
44+
return byteSize(base64String);
4545
}
4646

4747
/**

generators/client/generators/common/templates/src/main/webapp/app/shared/jhipster/data-utils.ts.ejs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
See the License for the specific language governing permissions and
1717
limitations under the License.
1818
-%>
19-
export const formatAsBytes = (size: number): string =>
19+
const formatAsBytes = (size: number): string =>
2020
`${size.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ' ')} bytes`; // NOSONAR
2121

2222
export const endsWith = (suffix: string, str: string): boolean =>
@@ -32,7 +32,7 @@ export const paddingSize = (value: string): number => {
3232
return 0;
3333
}
3434

35-
export const size = (value: string): number =>
35+
const size = (value: string): number =>
3636
(value.length / 4) * 3 - paddingSize(value);
3737

3838
export const toBase64 = (file: File, callback: (base64Data: string) => void): void => {
@@ -64,3 +64,6 @@ export const openFile = (data: string, contentType: string | null | undefined):
6464
win.onload = () => URL.revokeObjectURL(fileURL);
6565
}
6666
}
67+
68+
export const byteSize = (base64String: string): string =>
69+
formatAsBytes(size(base64String));

generators/vue/templates/src/main/webapp/app/shared/data/data-utils.service.ts.ejs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
See the License for the specific language governing permissions and
1717
limitations under the License.
1818
-%>
19-
import { formatAsBytes, openFile, paddingSize, size, toBase64 } from '@/shared/jhipster/data-utils';
19+
import { byteSize, openFile, paddingSize, toBase64 } from '@/shared/jhipster/data-utils';
2020

2121
/**
2222
* An composable utility for data.
@@ -36,7 +36,7 @@ const useDataUtils = () => ({
3636
* Method to find the byte size of the string provides
3737
*/
3838
byteSize(base64String) {
39-
return formatAsBytes(size(base64String));
39+
return byteSize(base64String);
4040
},
4141

4242
/**

0 commit comments

Comments
 (0)