@careflair/common 1.0.24 → 1.0.26
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/dist/index.d.ts +1 -1
- package/dist/index.js +3 -1
- package/dist/utils/video.d.ts +9 -0
- package/dist/utils/video.js +47 -8
- package/dist/utils/videoValidation.d.ts +9 -9
- package/dist/utils/videoValidation.js +55 -68
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -4,5 +4,5 @@ export { WorkHistoryInputValidation, WorkHistorySchema, } from "./schemas/workHi
|
|
|
4
4
|
export { AvailabilitiesSchemaZod, AvailabilityZodInput, } from "./schemas/availabilitySchemaValidation";
|
|
5
5
|
export { HourlyRateInputZod, HourlyRateInputZodType, } from "./schemas/hourlyRateSchemaValidation";
|
|
6
6
|
export { ServicesSchema, validateServices, } from "./schemas/businessServicesValidation";
|
|
7
|
-
export { VideoProvider, VideoValidationResult, detectVideoProvider, isValidCommunityVideoUrl, isValidYouTubeOrVimeoUrl, validateVideoLink, } from "./utils/videoValidation";
|
|
7
|
+
export { VideoProvider, VideoValidationResult, detectVideoProvider, extractYouTubeVideoId, isValidCommunityVideoUrl, isValidYouTubeOrVimeoUrl, normalizeYouTubeUrl, validateVideoLink, } from "./utils/videoValidation";
|
|
8
8
|
export { ApplicationFormValues, applicationSchema, isValidVideoUrl, } from "./schemas/applicationSchema";
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.isValidVideoUrl = exports.applicationSchema = exports.validateVideoLink = exports.isValidYouTubeOrVimeoUrl = exports.isValidCommunityVideoUrl = exports.detectVideoProvider = exports.validateServices = exports.ServicesSchema = exports.HourlyRateInputZod = exports.AvailabilitiesSchemaZod = exports.WorkHistorySchema = exports.EducationAndTrainingSchema = exports.UserRegistrationSchema = void 0;
|
|
3
|
+
exports.isValidVideoUrl = exports.applicationSchema = exports.validateVideoLink = exports.normalizeYouTubeUrl = exports.isValidYouTubeOrVimeoUrl = exports.isValidCommunityVideoUrl = exports.extractYouTubeVideoId = exports.detectVideoProvider = exports.validateServices = exports.ServicesSchema = exports.HourlyRateInputZod = exports.AvailabilitiesSchemaZod = exports.WorkHistorySchema = exports.EducationAndTrainingSchema = exports.UserRegistrationSchema = void 0;
|
|
4
4
|
var userValiationSchema_1 = require("./schemas/userValiationSchema");
|
|
5
5
|
Object.defineProperty(exports, "UserRegistrationSchema", { enumerable: true, get: function () { return userValiationSchema_1.UserRegistrationSchema; } });
|
|
6
6
|
var educationSchemas_1 = require("./schemas/educationSchemas");
|
|
@@ -16,8 +16,10 @@ Object.defineProperty(exports, "ServicesSchema", { enumerable: true, get: functi
|
|
|
16
16
|
Object.defineProperty(exports, "validateServices", { enumerable: true, get: function () { return businessServicesValidation_1.validateServices; } });
|
|
17
17
|
var videoValidation_1 = require("./utils/videoValidation");
|
|
18
18
|
Object.defineProperty(exports, "detectVideoProvider", { enumerable: true, get: function () { return videoValidation_1.detectVideoProvider; } });
|
|
19
|
+
Object.defineProperty(exports, "extractYouTubeVideoId", { enumerable: true, get: function () { return videoValidation_1.extractYouTubeVideoId; } });
|
|
19
20
|
Object.defineProperty(exports, "isValidCommunityVideoUrl", { enumerable: true, get: function () { return videoValidation_1.isValidCommunityVideoUrl; } });
|
|
20
21
|
Object.defineProperty(exports, "isValidYouTubeOrVimeoUrl", { enumerable: true, get: function () { return videoValidation_1.isValidYouTubeOrVimeoUrl; } });
|
|
22
|
+
Object.defineProperty(exports, "normalizeYouTubeUrl", { enumerable: true, get: function () { return videoValidation_1.normalizeYouTubeUrl; } });
|
|
21
23
|
Object.defineProperty(exports, "validateVideoLink", { enumerable: true, get: function () { return videoValidation_1.validateVideoLink; } });
|
|
22
24
|
var applicationSchema_1 = require("./schemas/applicationSchema");
|
|
23
25
|
Object.defineProperty(exports, "applicationSchema", { enumerable: true, get: function () { return applicationSchema_1.applicationSchema; } });
|
package/dist/utils/video.d.ts
CHANGED
|
@@ -11,6 +11,15 @@ export interface VideoValidationResult {
|
|
|
11
11
|
* @returns VideoValidationResult object
|
|
12
12
|
*/
|
|
13
13
|
export declare function validateVideoLink(url: string, allowedProviders: VideoProvider[]): VideoValidationResult;
|
|
14
|
+
/**
|
|
15
|
+
* Extract YouTube video ID from various URL formats
|
|
16
|
+
* Handles: youtube.com, m.youtube.com, youtu.be, /embed, /v, etc.
|
|
17
|
+
*/
|
|
18
|
+
export declare function extractYouTubeVideoId(url: string): string | null;
|
|
19
|
+
/**
|
|
20
|
+
* Normalize YouTube URL to standard format
|
|
21
|
+
*/
|
|
22
|
+
export declare function normalizeYouTubeUrl(url: string): string | null;
|
|
14
23
|
/**
|
|
15
24
|
* Detect video provider from URL
|
|
16
25
|
*/
|
package/dist/utils/video.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.validateVideoLink = validateVideoLink;
|
|
4
|
+
exports.extractYouTubeVideoId = extractYouTubeVideoId;
|
|
5
|
+
exports.normalizeYouTubeUrl = normalizeYouTubeUrl;
|
|
4
6
|
exports.detectVideoProvider = detectVideoProvider;
|
|
5
7
|
exports.isValidYouTubeOrVimeoUrl = isValidYouTubeOrVimeoUrl;
|
|
6
8
|
exports.isValidCommunityVideoUrl = isValidCommunityVideoUrl;
|
|
@@ -34,23 +36,60 @@ function validateVideoLink(url, allowedProviders) {
|
|
|
34
36
|
}
|
|
35
37
|
return { isValid: true, provider };
|
|
36
38
|
}
|
|
39
|
+
/**
|
|
40
|
+
* Extract YouTube video ID from various URL formats
|
|
41
|
+
* Handles: youtube.com, m.youtube.com, youtu.be, /embed, /v, etc.
|
|
42
|
+
*/
|
|
43
|
+
function extractYouTubeVideoId(url) {
|
|
44
|
+
if (!url)
|
|
45
|
+
return null;
|
|
46
|
+
const trimmed = url.trim();
|
|
47
|
+
let videoId = null;
|
|
48
|
+
// Handle youtu.be/VIDEO_ID
|
|
49
|
+
if (trimmed.includes('youtu.be/')) {
|
|
50
|
+
const match = trimmed.match(/youtu\.be\/([a-zA-Z0-9_-]{11})/);
|
|
51
|
+
videoId = match ? match[1] : null;
|
|
52
|
+
}
|
|
53
|
+
// Handle youtube.com/watch?v=VIDEO_ID (works for www, m, etc.)
|
|
54
|
+
else if (trimmed.includes('youtube.com/watch')) {
|
|
55
|
+
const match = trimmed.match(/[?&]v=([a-zA-Z0-9_-]{11})/);
|
|
56
|
+
videoId = match ? match[1] : null;
|
|
57
|
+
}
|
|
58
|
+
// Handle youtube.com/embed/VIDEO_ID
|
|
59
|
+
else if (trimmed.includes('youtube.com/embed/')) {
|
|
60
|
+
const match = trimmed.match(/\/embed\/([a-zA-Z0-9_-]{11})/);
|
|
61
|
+
videoId = match ? match[1] : null;
|
|
62
|
+
}
|
|
63
|
+
// Handle youtube.com/v/VIDEO_ID
|
|
64
|
+
else if (trimmed.includes('youtube.com/v/')) {
|
|
65
|
+
const match = trimmed.match(/\/v\/([a-zA-Z0-9_-]{11})/);
|
|
66
|
+
videoId = match ? match[1] : null;
|
|
67
|
+
}
|
|
68
|
+
return videoId;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Normalize YouTube URL to standard format
|
|
72
|
+
*/
|
|
73
|
+
function normalizeYouTubeUrl(url) {
|
|
74
|
+
const videoId = extractYouTubeVideoId(url);
|
|
75
|
+
return videoId ? `https://www.youtube.com/watch?v=${videoId}` : null;
|
|
76
|
+
}
|
|
37
77
|
/**
|
|
38
78
|
* Detect video provider from URL
|
|
39
79
|
*/
|
|
40
80
|
function detectVideoProvider(url) {
|
|
41
|
-
|
|
42
|
-
|
|
81
|
+
if (!url)
|
|
82
|
+
return null;
|
|
83
|
+
const lower = url.toLowerCase();
|
|
84
|
+
if ((lower.includes("youtube.com") || lower.includes("youtu.be")) && extractYouTubeVideoId(url)) {
|
|
43
85
|
return "youtube";
|
|
44
86
|
}
|
|
45
|
-
if (
|
|
87
|
+
if (lower.includes("vimeo.com"))
|
|
46
88
|
return "vimeo";
|
|
47
|
-
|
|
48
|
-
if (trimmedUrl.includes("loom.com")) {
|
|
89
|
+
if (lower.includes("loom.com"))
|
|
49
90
|
return "loom";
|
|
50
|
-
|
|
51
|
-
if (trimmedUrl.includes("tiktok.com")) {
|
|
91
|
+
if (lower.includes("tiktok.com"))
|
|
52
92
|
return "tiktok";
|
|
53
|
-
}
|
|
54
93
|
return null;
|
|
55
94
|
}
|
|
56
95
|
/**
|
|
@@ -6,26 +6,26 @@ export interface VideoValidationResult {
|
|
|
6
6
|
}
|
|
7
7
|
/**
|
|
8
8
|
* Unified video link validation function
|
|
9
|
-
* @param url - The video URL to validate
|
|
10
|
-
* @param allowedProviders - Array of allowed video providers
|
|
11
|
-
* @returns VideoValidationResult object
|
|
12
9
|
*/
|
|
13
10
|
export declare function validateVideoLink(url: string, allowedProviders: VideoProvider[]): VideoValidationResult;
|
|
11
|
+
/**
|
|
12
|
+
* Extract YouTube video ID from various URL formats
|
|
13
|
+
* Handles: youtube.com, m.youtube.com, youtu.be, /embed, /v, /shorts, etc.
|
|
14
|
+
*/
|
|
15
|
+
export declare function extractYouTubeVideoId(url: string): string | null;
|
|
16
|
+
/**
|
|
17
|
+
* Normalize YouTube URL to standard format
|
|
18
|
+
*/
|
|
19
|
+
export declare function normalizeYouTubeUrl(url: string): string | null;
|
|
14
20
|
/**
|
|
15
21
|
* Detect video provider from URL
|
|
16
|
-
* @param url - The video URL
|
|
17
|
-
* @returns VideoProvider or null if not detected
|
|
18
22
|
*/
|
|
19
23
|
export declare function detectVideoProvider(url: string): VideoProvider | null;
|
|
20
24
|
/**
|
|
21
25
|
* Convenience function for YouTube and Vimeo only (commonly used)
|
|
22
|
-
* @param url - The video URL to validate
|
|
23
|
-
* @returns boolean
|
|
24
26
|
*/
|
|
25
27
|
export declare function isValidYouTubeOrVimeoUrl(url: string): boolean;
|
|
26
28
|
/**
|
|
27
29
|
* Convenience function for community posts (all providers)
|
|
28
|
-
* @param url - The video URL to validate
|
|
29
|
-
* @returns boolean
|
|
30
30
|
*/
|
|
31
31
|
export declare function isValidCommunityVideoUrl(url: string): boolean;
|
|
@@ -1,25 +1,19 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.validateVideoLink = validateVideoLink;
|
|
4
|
+
exports.extractYouTubeVideoId = extractYouTubeVideoId;
|
|
5
|
+
exports.normalizeYouTubeUrl = normalizeYouTubeUrl;
|
|
4
6
|
exports.detectVideoProvider = detectVideoProvider;
|
|
5
7
|
exports.isValidYouTubeOrVimeoUrl = isValidYouTubeOrVimeoUrl;
|
|
6
8
|
exports.isValidCommunityVideoUrl = isValidCommunityVideoUrl;
|
|
7
9
|
/**
|
|
8
10
|
* Unified video link validation function
|
|
9
|
-
* @param url - The video URL to validate
|
|
10
|
-
* @param allowedProviders - Array of allowed video providers
|
|
11
|
-
* @returns VideoValidationResult object
|
|
12
11
|
*/
|
|
13
12
|
function validateVideoLink(url, allowedProviders) {
|
|
14
13
|
if (!url || url.trim() === "") {
|
|
15
14
|
return { isValid: true }; // Empty URL is valid (optional field)
|
|
16
15
|
}
|
|
17
|
-
const
|
|
18
|
-
// Validate URL format
|
|
19
|
-
if (!isValidURL(trimmedUrl)) {
|
|
20
|
-
return { isValid: false, error: "Invalid URL format" };
|
|
21
|
-
}
|
|
22
|
-
const provider = detectVideoProvider(trimmedUrl);
|
|
16
|
+
const provider = detectVideoProvider(url);
|
|
23
17
|
if (!provider) {
|
|
24
18
|
return {
|
|
25
19
|
isValid: false,
|
|
@@ -35,69 +29,69 @@ function validateVideoLink(url, allowedProviders) {
|
|
|
35
29
|
return { isValid: true, provider };
|
|
36
30
|
}
|
|
37
31
|
/**
|
|
38
|
-
*
|
|
39
|
-
*
|
|
40
|
-
* @returns VideoProvider or null if not detected
|
|
32
|
+
* Extract YouTube video ID from various URL formats
|
|
33
|
+
* Handles: youtube.com, m.youtube.com, youtu.be, /embed, /v, /shorts, etc.
|
|
41
34
|
*/
|
|
42
|
-
function
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
35
|
+
function extractYouTubeVideoId(url) {
|
|
36
|
+
if (!url)
|
|
37
|
+
return null;
|
|
38
|
+
const trimmed = url.trim();
|
|
39
|
+
let videoId = null;
|
|
40
|
+
// Handle youtu.be/VIDEO_ID
|
|
41
|
+
if (trimmed.includes("youtu.be/")) {
|
|
42
|
+
const match = trimmed.match(/youtu\.be\/([a-zA-Z0-9_-]{11})/);
|
|
43
|
+
videoId = match ? match[1] : null;
|
|
51
44
|
}
|
|
52
|
-
//
|
|
53
|
-
if (
|
|
54
|
-
const
|
|
55
|
-
|
|
56
|
-
return "vimeo";
|
|
57
|
-
}
|
|
45
|
+
// Handle youtube.com/watch?v=VIDEO_ID (works for www, m, etc.)
|
|
46
|
+
else if (trimmed.includes("youtube.com/watch")) {
|
|
47
|
+
const match = trimmed.match(/[?&]v=([a-zA-Z0-9_-]{11})/);
|
|
48
|
+
videoId = match ? match[1] : null;
|
|
58
49
|
}
|
|
59
|
-
//
|
|
60
|
-
if (
|
|
61
|
-
const
|
|
62
|
-
|
|
63
|
-
return "loom";
|
|
64
|
-
}
|
|
50
|
+
// Handle youtube.com/shorts/VIDEO_ID
|
|
51
|
+
else if (trimmed.includes("youtube.com/shorts/")) {
|
|
52
|
+
const match = trimmed.match(/\/shorts\/([a-zA-Z0-9_-]{11})/);
|
|
53
|
+
videoId = match ? match[1] : null;
|
|
65
54
|
}
|
|
66
|
-
//
|
|
67
|
-
if (
|
|
68
|
-
const
|
|
69
|
-
|
|
70
|
-
if (tiktokRegex1.test(url) || tiktokRegex2.test(url)) {
|
|
71
|
-
return "tiktok";
|
|
72
|
-
}
|
|
55
|
+
// Handle youtube.com/embed/VIDEO_ID
|
|
56
|
+
else if (trimmed.includes("youtube.com/embed/")) {
|
|
57
|
+
const match = trimmed.match(/\/embed\/([a-zA-Z0-9_-]{11})/);
|
|
58
|
+
videoId = match ? match[1] : null;
|
|
73
59
|
}
|
|
74
|
-
|
|
60
|
+
// Handle youtube.com/v/VIDEO_ID
|
|
61
|
+
else if (trimmed.includes("youtube.com/v/")) {
|
|
62
|
+
const match = trimmed.match(/\/v\/([a-zA-Z0-9_-]{11})/);
|
|
63
|
+
videoId = match ? match[1] : null;
|
|
64
|
+
}
|
|
65
|
+
return videoId;
|
|
75
66
|
}
|
|
76
67
|
/**
|
|
77
|
-
*
|
|
78
|
-
* @param url - The URL to validate
|
|
79
|
-
* @returns boolean
|
|
68
|
+
* Normalize YouTube URL to standard format
|
|
80
69
|
*/
|
|
81
|
-
function
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
70
|
+
function normalizeYouTubeUrl(url) {
|
|
71
|
+
const videoId = extractYouTubeVideoId(url);
|
|
72
|
+
return videoId ? `https://www.youtube.com/watch?v=${videoId}` : null;
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Detect video provider from URL
|
|
76
|
+
*/
|
|
77
|
+
function detectVideoProvider(url) {
|
|
78
|
+
if (!url)
|
|
79
|
+
return null;
|
|
80
|
+
const lower = url.toLowerCase();
|
|
81
|
+
if ((lower.includes("youtube.com") || lower.includes("youtu.be")) &&
|
|
82
|
+
extractYouTubeVideoId(url)) {
|
|
83
|
+
return "youtube";
|
|
95
84
|
}
|
|
85
|
+
if (lower.includes("vimeo.com"))
|
|
86
|
+
return "vimeo";
|
|
87
|
+
if (lower.includes("loom.com"))
|
|
88
|
+
return "loom";
|
|
89
|
+
if (lower.includes("tiktok.com"))
|
|
90
|
+
return "tiktok";
|
|
91
|
+
return null;
|
|
96
92
|
}
|
|
97
93
|
/**
|
|
98
94
|
* Convenience function for YouTube and Vimeo only (commonly used)
|
|
99
|
-
* @param url - The video URL to validate
|
|
100
|
-
* @returns boolean
|
|
101
95
|
*/
|
|
102
96
|
function isValidYouTubeOrVimeoUrl(url) {
|
|
103
97
|
const result = validateVideoLink(url, ["youtube", "vimeo"]);
|
|
@@ -105,15 +99,8 @@ function isValidYouTubeOrVimeoUrl(url) {
|
|
|
105
99
|
}
|
|
106
100
|
/**
|
|
107
101
|
* Convenience function for community posts (all providers)
|
|
108
|
-
* @param url - The video URL to validate
|
|
109
|
-
* @returns boolean
|
|
110
102
|
*/
|
|
111
103
|
function isValidCommunityVideoUrl(url) {
|
|
112
|
-
const result = validateVideoLink(url, [
|
|
113
|
-
"youtube",
|
|
114
|
-
"vimeo",
|
|
115
|
-
"loom",
|
|
116
|
-
"tiktok",
|
|
117
|
-
]);
|
|
104
|
+
const result = validateVideoLink(url, ["youtube", "vimeo", "loom", "tiktok"]);
|
|
118
105
|
return result.isValid;
|
|
119
106
|
}
|