@genfeedai/helpers 2.2.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.
Files changed (45) hide show
  1. package/dist/aspect-ratio.helper.d.ts +18 -0
  2. package/dist/aspect-ratio.helper.d.ts.map +1 -0
  3. package/dist/aspect-ratio.helper.js +116 -0
  4. package/dist/aspect-ratio.helper.js.map +1 -0
  5. package/dist/business/pricing/pricing.helper.d.ts +231 -0
  6. package/dist/business/pricing/pricing.helper.d.ts.map +1 -0
  7. package/dist/business/pricing/pricing.helper.js +443 -0
  8. package/dist/business/pricing/pricing.helper.js.map +1 -0
  9. package/dist/business/tier-models/tier-models.helper.d.ts +16 -0
  10. package/dist/business/tier-models/tier-models.helper.d.ts.map +1 -0
  11. package/dist/business/tier-models/tier-models.helper.js +42 -0
  12. package/dist/business/tier-models/tier-models.helper.js.map +1 -0
  13. package/dist/deserializer.helper.d.ts +2 -0
  14. package/dist/deserializer.helper.d.ts.map +1 -0
  15. package/dist/deserializer.helper.js +3 -0
  16. package/dist/deserializer.helper.js.map +1 -0
  17. package/dist/index.d.ts +10 -0
  18. package/dist/index.d.ts.map +1 -0
  19. package/dist/index.js +10 -0
  20. package/dist/index.js.map +1 -0
  21. package/dist/model-capability.helper.d.ts +17 -0
  22. package/dist/model-capability.helper.d.ts.map +1 -0
  23. package/dist/model-capability.helper.js +184 -0
  24. package/dist/model-capability.helper.js.map +1 -0
  25. package/dist/quality-routing.helper.d.ts +29 -0
  26. package/dist/quality-routing.helper.d.ts.map +1 -0
  27. package/dist/quality-routing.helper.js +216 -0
  28. package/dist/quality-routing.helper.js.map +1 -0
  29. package/dist/serializer.helper.d.ts +25 -0
  30. package/dist/serializer.helper.d.ts.map +1 -0
  31. package/dist/serializer.helper.js +46 -0
  32. package/dist/serializer.helper.js.map +1 -0
  33. package/dist/social-url.helper.d.ts +8 -0
  34. package/dist/social-url.helper.d.ts.map +1 -0
  35. package/dist/social-url.helper.js +50 -0
  36. package/dist/social-url.helper.js.map +1 -0
  37. package/dist/types/model-like.type.d.ts +32 -0
  38. package/dist/types/model-like.type.d.ts.map +1 -0
  39. package/dist/types/model-like.type.js +3 -0
  40. package/dist/types/model-like.type.js.map +1 -0
  41. package/dist/video-duration.helper.d.ts +9 -0
  42. package/dist/video-duration.helper.d.ts.map +1 -0
  43. package/dist/video-duration.helper.js +43 -0
  44. package/dist/video-duration.helper.js.map +1 -0
  45. package/package.json +50 -0
@@ -0,0 +1,9 @@
1
+ import type { ModelKey } from '@genfeedai/enums';
2
+ export declare function formatDuration(seconds?: number | null): string;
3
+ export declare class DurationUtil {
4
+ static validateAndNormalize(requestedDuration: number | undefined, allowedDurations: number[], defaultDuration?: number): number;
5
+ static validateSoraDuration(requestedDuration?: number): number;
6
+ static validateVeoDuration(requestedDuration?: number, allowedDurations?: number[], defaultDuration?: number): number;
7
+ static validateDurationForModel(model: ModelKey, requestedDuration?: number): number;
8
+ }
9
+ //# sourceMappingURL=video-duration.helper.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"video-duration.helper.d.ts","sourceRoot":"","sources":["../src/video-duration.helper.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAEjD,wBAAgB,cAAc,CAAC,OAAO,CAAC,EAAE,MAAM,GAAG,IAAI,GAAG,MAAM,CAgB9D;AAED,qBAAa,YAAY;IACvB,MAAM,CAAC,oBAAoB,CACzB,iBAAiB,EAAE,MAAM,GAAG,SAAS,EACrC,gBAAgB,EAAE,MAAM,EAAE,EAC1B,eAAe,CAAC,EAAE,MAAM,GACvB,MAAM;IAgBT,MAAM,CAAC,oBAAoB,CAAC,iBAAiB,CAAC,EAAE,MAAM,GAAG,MAAM;IAI/D,MAAM,CAAC,mBAAmB,CACxB,iBAAiB,CAAC,EAAE,MAAM,EAC1B,gBAAgB,GAAE,MAAM,EAAW,EACnC,eAAe,GAAE,MAAU,GAC1B,MAAM;IAQT,MAAM,CAAC,wBAAwB,CAC7B,KAAK,EAAE,QAAQ,EACf,iBAAiB,CAAC,EAAE,MAAM,GACzB,MAAM;CAcV"}
@@ -0,0 +1,43 @@
1
+ import { getModelDefaultDuration, getModelDurations, } from '@genfeedai/constants';
2
+ export function formatDuration(seconds) {
3
+ if (!seconds) {
4
+ return '0:00';
5
+ }
6
+ const hours = Math.floor(seconds / 3600);
7
+ const minutes = Math.floor((seconds % 3600) / 60);
8
+ const secs = Math.floor(seconds % 60);
9
+ const paddedMinutes = minutes.toString().padStart(2, '0');
10
+ const paddedSecs = secs.toString().padStart(2, '0');
11
+ if (hours > 0) {
12
+ return `${hours}:${paddedMinutes}:${paddedSecs}`;
13
+ }
14
+ return `${minutes}:${paddedSecs}`;
15
+ }
16
+ export class DurationUtil {
17
+ static validateAndNormalize(requestedDuration, allowedDurations, defaultDuration) {
18
+ if (!requestedDuration) {
19
+ return defaultDuration ?? allowedDurations[0];
20
+ }
21
+ if (allowedDurations.includes(requestedDuration)) {
22
+ return requestedDuration;
23
+ }
24
+ return allowedDurations.reduce((prev, curr) => Math.abs(curr - requestedDuration) < Math.abs(prev - requestedDuration)
25
+ ? curr
26
+ : prev);
27
+ }
28
+ static validateSoraDuration(requestedDuration) {
29
+ return DurationUtil.validateAndNormalize(requestedDuration, [4, 8, 12], 4);
30
+ }
31
+ static validateVeoDuration(requestedDuration, allowedDurations = [5, 8], defaultDuration = 8) {
32
+ return DurationUtil.validateAndNormalize(requestedDuration, allowedDurations, defaultDuration);
33
+ }
34
+ static validateDurationForModel(model, requestedDuration) {
35
+ const allowedDurations = getModelDurations(model);
36
+ const defaultDuration = getModelDefaultDuration(model);
37
+ if (allowedDurations.length === 0) {
38
+ return requestedDuration || defaultDuration || 8;
39
+ }
40
+ return DurationUtil.validateAndNormalize(requestedDuration, [...allowedDurations], defaultDuration);
41
+ }
42
+ }
43
+ //# sourceMappingURL=video-duration.helper.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"video-duration.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AAE,CAC5C,IAAI,CAAC,GAAG,CAAC,IAAI,GAAG,iBAAiB,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,IAAI,GAAG,iBAAiB,CAAC;YACrE,CAAC,CAAC,IAAI;YACN,CAAC,CAAC,IAAI,CACT,CAAC;IACJ,CAAC;IAED,MAAM,CAAC,oBAAoB,CAAC,iBAA0B;QACpD,OAAO,YAAY,CAAC,oBAAoB,CAAC,iBAAiB,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;IAC7E,CAAC;IAED,MAAM,CAAC,mBAAmB,CACxB,iBAA0B,EAC1B,mBAA6B,CAAC,CAAC,EAAE,CAAC,CAAC,EACnC,kBAA0B,CAAC;QAE3B,OAAO,YAAY,CAAC,oBAAoB,CACtC,iBAAiB,EACjB,gBAAgB,EAChB,eAAe,CAChB,CAAC;IACJ,CAAC;IAED,MAAM,CAAC,wBAAwB,CAC7B,KAAe,EACf,iBAA0B;QAE1B,MAAM,gBAAgB,GAAG,iBAAiB,CAAC,KAAK,CAAC,CAAC;QAClD,MAAM,eAAe,GAAG,uBAAuB,CAAC,KAAK,CAAC,CAAC;QAEvD,IAAI,gBAAgB,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YAClC,OAAO,iBAAiB,IAAI,eAAe,IAAI,CAAC,CAAC;QACnD,CAAC;QAED,OAAO,YAAY,CAAC,oBAAoB,CACtC,iBAAiB,EACjB,CAAC,GAAG,gBAAgB,CAAC,EACrB,eAAe,CAChB,CAAC;IACJ,CAAC;CACF"}
package/package.json ADDED
@@ -0,0 +1,50 @@
1
+ {
2
+ "name": "@genfeedai/helpers",
3
+ "version": "2.2.2",
4
+ "description": "Shared helpers for Genfeed clients and services",
5
+ "license": "MIT",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "git+https://github.com/genfeedai/packages.git",
9
+ "directory": "helpers"
10
+ },
11
+ "publishConfig": {
12
+ "access": "public",
13
+ "registry": "https://registry.npmjs.org/"
14
+ },
15
+ "dependencies": {
16
+ "@genfeedai/constants": "2.2.3",
17
+ "@genfeedai/deserializer": "1.0.2",
18
+ "@genfeedai/enums": "2.2.4",
19
+ "@genfeedai/interfaces": "2.3.4",
20
+ "ts-jsonapi": "2.1.3"
21
+ },
22
+ "devDependencies": {
23
+ "typescript": "5.9.3"
24
+ },
25
+ "exports": {
26
+ ".": {
27
+ "import": "./dist/index.js",
28
+ "require": "./dist/index.js",
29
+ "types": "./dist/index.d.ts"
30
+ }
31
+ },
32
+ "files": [
33
+ "dist"
34
+ ],
35
+ "main": "./dist/index.js",
36
+ "scripts": {
37
+ "build": "tsc --build --force && if [ -d dist/src ]; then mv dist/src/* dist/ 2>/dev/null && rm -rf dist/src; fi",
38
+ "clean": "rm -rf dist tsconfig.tsbuildinfo",
39
+ "deps:update": "bunx npm-check-updates -u && bun install",
40
+ "dev": "tsc --watch",
41
+ "prepublishOnly": "bun run build",
42
+ "test": "vitest run --config vitest.config.ts",
43
+ "test:cov": "vitest run --coverage --config vitest.config.ts",
44
+ "test:coverage": "vitest run --coverage --config vitest.config.ts",
45
+ "test:watch": "vitest watch --config vitest.config.ts",
46
+ "typecheck": "tsc --noEmit"
47
+ },
48
+ "sideEffects": false,
49
+ "types": "./dist/index.d.ts"
50
+ }