@cntrl-site/sdk-nextjs 1.5.0 → 1.5.1

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.
@@ -8,18 +8,27 @@ var Allowed;
8
8
  })(Allowed || (Allowed = {}));
9
9
  function getYoutubeId({ hostname, pathname, search }) {
10
10
  if (hostname !== Allowed.Full && hostname !== Allowed.Tiny) {
11
- throw new Error(`Cannot get valid youtube ID from "${hostname}" - address is not whitelisted`);
11
+ throw new Error(`Cannot get valid YouTube ID from "${hostname}" - address is not whitelisted`);
12
12
  }
13
13
  switch (hostname) {
14
14
  case Allowed.Tiny:
15
15
  return pathname.replace('/', '');
16
16
  case Allowed.Full:
17
- const searchParams = new URLSearchParams(search);
18
- const id = searchParams.get('v');
19
- if (!id) {
20
- throw new Error("Cannot get valid youtube ID from search params.");
17
+ if (pathname.startsWith('/shorts/')) {
18
+ const shortsId = pathname.split('/shorts/')[1];
19
+ if (!shortsId) {
20
+ throw new Error('Cannot get valid YouTube Shorts ID from the pathname.');
21
+ }
22
+ return shortsId;
23
+ }
24
+ else {
25
+ const searchParams = new URLSearchParams(search);
26
+ const id = searchParams.get('v');
27
+ if (!id) {
28
+ throw new Error('Cannot get valid YouTube ID from search params.');
29
+ }
30
+ return id;
21
31
  }
22
- return id;
23
32
  }
24
33
  }
25
34
  exports.getYoutubeId = getYoutubeId;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cntrl-site/sdk-nextjs",
3
- "version": "1.5.0",
3
+ "version": "1.5.1",
4
4
  "description": "SDK for Next.js",
5
5
  "author": "arsen@momdesign.nyc",
6
6
  "license": "MIT",
@@ -5,17 +5,25 @@ enum Allowed {
5
5
 
6
6
  export function getYoutubeId({ hostname, pathname, search }: URL): string {
7
7
  if (hostname !== Allowed.Full && hostname !== Allowed.Tiny) {
8
- throw new Error(`Cannot get valid youtube ID from "${hostname}" - address is not whitelisted`);
8
+ throw new Error(`Cannot get valid YouTube ID from "${hostname}" - address is not whitelisted`);
9
9
  }
10
10
  switch (hostname) {
11
11
  case Allowed.Tiny:
12
12
  return pathname.replace('/', '');
13
13
  case Allowed.Full:
14
- const searchParams = new URLSearchParams(search);
15
- const id = searchParams.get('v');
16
- if (!id) {
17
- throw new Error("Cannot get valid youtube ID from search params.");
14
+ if (pathname.startsWith('/shorts/')) {
15
+ const shortsId = pathname.split('/shorts/')[1];
16
+ if (!shortsId) {
17
+ throw new Error('Cannot get valid YouTube Shorts ID from the pathname.');
18
+ }
19
+ return shortsId;
20
+ } else {
21
+ const searchParams = new URLSearchParams(search);
22
+ const id = searchParams.get('v');
23
+ if (!id) {
24
+ throw new Error('Cannot get valid YouTube ID from search params.');
25
+ }
26
+ return id;
18
27
  }
19
- return id;
20
28
  }
21
29
  }
@@ -1,5 +0,0 @@
1
- <component name="ProjectCodeStyleConfiguration">
2
- <state>
3
- <option name="PREFERRED_PROJECT_CODE_STYLE" value="Default" />
4
- </state>
5
- </component>
package/.idea/modules.xml DELETED
@@ -1,8 +0,0 @@
1
- <?xml version="1.0" encoding="UTF-8"?>
2
- <project version="4">
3
- <component name="ProjectModuleManager">
4
- <modules>
5
- <module fileurl="file://$PROJECT_DIR$/.idea/sdk-nextjs.iml" filepath="$PROJECT_DIR$/.idea/sdk-nextjs.iml" />
6
- </modules>
7
- </component>
8
- </project>
@@ -1,12 +0,0 @@
1
- <?xml version="1.0" encoding="UTF-8"?>
2
- <module type="WEB_MODULE" version="4">
3
- <component name="NewModuleRootManager">
4
- <content url="file://$MODULE_DIR$">
5
- <excludeFolder url="file://$MODULE_DIR$/temp" />
6
- <excludeFolder url="file://$MODULE_DIR$/.tmp" />
7
- <excludeFolder url="file://$MODULE_DIR$/tmp" />
8
- </content>
9
- <orderEntry type="inheritedJdk" />
10
- <orderEntry type="sourceFolder" forTests="false" />
11
- </component>
12
- </module>
package/.idea/vcs.xml DELETED
@@ -1,6 +0,0 @@
1
- <?xml version="1.0" encoding="UTF-8"?>
2
- <project version="4">
3
- <component name="VcsDirectoryMappings">
4
- <mapping directory="$PROJECT_DIR$" vcs="Git" />
5
- </component>
6
- </project>