@bernierllc/content-type-audio 1.0.1 → 1.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +8 -0
- package/dist/AudioContentTypeManager.d.ts +47 -0
- package/dist/AudioContentTypeManager.d.ts.map +1 -0
- package/dist/AudioContentTypeManager.js +195 -0
- package/dist/AudioContentTypeManager.js.map +1 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +27 -0
- package/dist/index.js.map +1 -0
- package/dist/schemas.d.ts +103 -0
- package/dist/schemas.d.ts.map +1 -0
- package/dist/schemas.js +39 -0
- package/dist/schemas.js.map +1 -0
- package/dist/types.d.ts +70 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +23 -0
- package/dist/types.js.map +1 -0
- package/dist/utils.d.ts +25 -0
- package/dist/utils.d.ts.map +1 -0
- package/dist/utils.js +81 -0
- package/dist/utils.js.map +1 -0
- package/jest.config.cjs +2 -2
- package/package.json +5 -4
- package/tsconfig.json +1 -0
- package/coverage/AudioContentTypeManager.ts.html +0 -799
- package/coverage/base.css +0 -224
- package/coverage/block-navigation.js +0 -87
- package/coverage/favicon.png +0 -0
- package/coverage/index.html +0 -161
- package/coverage/lcov-report/AudioContentTypeManager.ts.html +0 -799
- package/coverage/lcov-report/base.css +0 -224
- package/coverage/lcov-report/block-navigation.js +0 -87
- package/coverage/lcov-report/favicon.png +0 -0
- package/coverage/lcov-report/index.html +0 -161
- package/coverage/lcov-report/prettify.css +0 -1
- package/coverage/lcov-report/prettify.js +0 -2
- package/coverage/lcov-report/schemas.ts.html +0 -211
- package/coverage/lcov-report/sort-arrow-sprite.png +0 -0
- package/coverage/lcov-report/sorter.js +0 -210
- package/coverage/lcov-report/types.ts.html +0 -331
- package/coverage/lcov-report/utils.ts.html +0 -325
- package/coverage/lcov.info +0 -200
- package/coverage/prettify.css +0 -1
- package/coverage/prettify.js +0 -2
- package/coverage/schemas.ts.html +0 -211
- package/coverage/sort-arrow-sprite.png +0 -0
- package/coverage/sorter.js +0 -210
- package/coverage/types.ts.html +0 -331
- package/coverage/utils.ts.html +0 -325
package/dist/utils.js
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
Copyright (c) 2025 Bernier LLC
|
|
4
|
+
|
|
5
|
+
This file is licensed to the client under a limited-use license.
|
|
6
|
+
The client may use and modify this code *only within the scope of the project it was delivered for*.
|
|
7
|
+
Redistribution or use in other products or commercial offerings is not permitted without written consent from Bernier LLC.
|
|
8
|
+
*/
|
|
9
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
+
exports.parseDuration = parseDuration;
|
|
11
|
+
exports.formatDuration = formatDuration;
|
|
12
|
+
exports.calculateBitrate = calculateBitrate;
|
|
13
|
+
exports.generateAudioId = generateAudioId;
|
|
14
|
+
/**
|
|
15
|
+
* Parse audio duration from various formats
|
|
16
|
+
* @param duration - Duration as string ("1:23:45", "23:45", "123") or number
|
|
17
|
+
* @returns Duration in seconds
|
|
18
|
+
*/
|
|
19
|
+
function parseDuration(duration) {
|
|
20
|
+
if (typeof duration === 'number') {
|
|
21
|
+
return duration;
|
|
22
|
+
}
|
|
23
|
+
// Parse formats: "1:23:45", "23:45", "123"
|
|
24
|
+
const parts = duration.split(':').map(Number);
|
|
25
|
+
// Check if all parts are valid numbers
|
|
26
|
+
if (parts.some(part => isNaN(part))) {
|
|
27
|
+
return 0;
|
|
28
|
+
}
|
|
29
|
+
if (parts.length === 1) {
|
|
30
|
+
const part = parts[0];
|
|
31
|
+
return part !== undefined ? part : 0; // seconds
|
|
32
|
+
}
|
|
33
|
+
else if (parts.length === 2) {
|
|
34
|
+
const part0 = parts[0];
|
|
35
|
+
const part1 = parts[1];
|
|
36
|
+
return (part0 !== undefined && part1 !== undefined) ? part0 * 60 + part1 : 0; // mm:ss
|
|
37
|
+
}
|
|
38
|
+
else if (parts.length === 3) {
|
|
39
|
+
const part0 = parts[0];
|
|
40
|
+
const part1 = parts[1];
|
|
41
|
+
const part2 = parts[2];
|
|
42
|
+
return (part0 !== undefined && part1 !== undefined && part2 !== undefined)
|
|
43
|
+
? part0 * 3600 + part1 * 60 + part2
|
|
44
|
+
: 0; // hh:mm:ss
|
|
45
|
+
}
|
|
46
|
+
return 0;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Format duration to human-readable string
|
|
50
|
+
* @param seconds - Duration in seconds
|
|
51
|
+
* @returns Formatted string (e.g., "1:23:45" or "23:45")
|
|
52
|
+
*/
|
|
53
|
+
function formatDuration(seconds) {
|
|
54
|
+
const hours = Math.floor(seconds / 3600);
|
|
55
|
+
const minutes = Math.floor((seconds % 3600) / 60);
|
|
56
|
+
const secs = Math.floor(seconds % 60);
|
|
57
|
+
if (hours > 0) {
|
|
58
|
+
return `${hours}:${String(minutes).padStart(2, '0')}:${String(secs).padStart(2, '0')}`;
|
|
59
|
+
}
|
|
60
|
+
return `${minutes}:${String(secs).padStart(2, '0')}`;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Calculate bitrate from file size and duration
|
|
64
|
+
* @param fileSize - File size in bytes
|
|
65
|
+
* @param duration - Duration in seconds
|
|
66
|
+
* @returns Bitrate in kbps
|
|
67
|
+
*/
|
|
68
|
+
function calculateBitrate(fileSize, duration) {
|
|
69
|
+
if (duration === 0)
|
|
70
|
+
return 0;
|
|
71
|
+
// (fileSize in bytes * 8 bits/byte) / (duration in seconds) / 1000 = kbps
|
|
72
|
+
return Math.round((fileSize * 8) / duration / 1000);
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Generate unique ID for audio content
|
|
76
|
+
* @returns Unique identifier
|
|
77
|
+
*/
|
|
78
|
+
function generateAudioId() {
|
|
79
|
+
return `audio_${Date.now()}_${Math.random().toString(36).substring(2, 9)}`;
|
|
80
|
+
}
|
|
81
|
+
//# sourceMappingURL=utils.js.map
|
|
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I,CAAC,CAAC;AACtD,CAAC;AAED;;;GAGG;AACH,SAAgB,eAAe;IAC7B,OAAO,SAAS,IAAI,CAAC,GAAG,EAAE,IAAI,IAAI,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,SAAS,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC;AAC7E,CAAC"}
|
package/jest.config.cjs
CHANGED
|
@@ -8,7 +8,8 @@ Redistribution or use in other products or commercial offerings is not permitted
|
|
|
8
8
|
|
|
9
9
|
module.exports = {
|
|
10
10
|
preset: 'ts-jest',
|
|
11
|
-
|
|
11
|
+
// Use fixed environment to handle Node.js v25+ localStorage issue
|
|
12
|
+
testEnvironment: '<rootDir>/../../../jest-environment-node-fixed.cjs',
|
|
12
13
|
roots: ['<rootDir>/__tests__'],
|
|
13
14
|
testMatch: ['**/__tests__/**/*.test.ts'],
|
|
14
15
|
collectCoverageFrom: [
|
|
@@ -24,7 +25,6 @@ module.exports = {
|
|
|
24
25
|
statements: 90
|
|
25
26
|
}
|
|
26
27
|
},
|
|
27
|
-
coverageReporters: ['text', 'lcov', 'html'],
|
|
28
28
|
moduleFileExtensions: ['ts', 'js', 'json'],
|
|
29
29
|
transform: {
|
|
30
30
|
'^.+\\.ts$': 'ts-jest'
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bernierllc/content-type-audio",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.2",
|
|
4
4
|
"description": "Base audio content type with file upload, local storage, and streaming URL capabilities",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -17,8 +17,8 @@
|
|
|
17
17
|
"author": "Bernier LLC",
|
|
18
18
|
"license": "SEE LICENSE IN LICENSE",
|
|
19
19
|
"dependencies": {
|
|
20
|
-
"
|
|
21
|
-
"
|
|
20
|
+
"zod": "^3.22.4",
|
|
21
|
+
"@bernierllc/content-type-registry": "1.1.0"
|
|
22
22
|
},
|
|
23
23
|
"devDependencies": {
|
|
24
24
|
"@types/jest": "^29.5.0",
|
|
@@ -31,7 +31,8 @@
|
|
|
31
31
|
"typescript": "^5.0.0"
|
|
32
32
|
},
|
|
33
33
|
"publishConfig": {
|
|
34
|
-
"access": "public"
|
|
34
|
+
"access": "public",
|
|
35
|
+
"registry": "https://registry.npmjs.org/"
|
|
35
36
|
},
|
|
36
37
|
"bernierllc": {
|
|
37
38
|
"integration": {
|