@smartive/datocms-utils 1.5.0 → 1.6.0

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 CHANGED
@@ -1,6 +1,6 @@
1
- # [1.5.0](https://github.com/smartive/datocms-utils/compare/v1.4.1...v1.5.0) (2025-01-07)
1
+ # [1.6.0](https://github.com/smartive/datocms-utils/compare/v1.5.0...v1.6.0) (2025-02-07)
2
2
 
3
3
 
4
4
  ### Features
5
5
 
6
- * add truncate method ([#49](https://github.com/smartive/datocms-utils/issues/49)) ([94f4214](https://github.com/smartive/datocms-utils/commit/94f4214cd926621063b4b5de4a010c6f7839b907))
6
+ * add getTelLink utility ([#61](https://github.com/smartive/datocms-utils/issues/61)) ([31044d9](https://github.com/smartive/datocms-utils/commit/31044d91f9d47736a2ca254501eb5d11dc6998a8))
package/README.md CHANGED
@@ -37,6 +37,7 @@ CREATE TABLE IF NOT EXISTS query_cache_tags (
37
37
  ### Other Utilities
38
38
 
39
39
  - `classNames`: Cleans and joins an array of inputs with possible undefined or boolean values. Useful for tailwind classnames.
40
+ - `getTelLink`: Formats a phone number to a tel link.
40
41
 
41
42
  ### Types
42
43
 
package/dist/index.d.ts CHANGED
@@ -1,3 +1,4 @@
1
1
  export * from './cache-tags';
2
2
  export * from './classnames';
3
+ export * from './links';
3
4
  export * from './types';
package/dist/index.js CHANGED
@@ -1,4 +1,5 @@
1
1
  export * from './cache-tags';
2
2
  export * from './classnames';
3
+ export * from './links';
3
4
  export * from './types';
4
5
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC;AAC7B,cAAc,cAAc,CAAC;AAC7B,cAAc,SAAS,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC;AAC7B,cAAc,cAAc,CAAC;AAC7B,cAAc,SAAS,CAAC;AACxB,cAAc,SAAS,CAAC"}
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Converts a phone number into a `tel:` link.
3
+ *
4
+ * @param phoneNumber Phone number
5
+ * @returns `tel:` link for the phone number
6
+ */
7
+ export declare const getTelLink: (phoneNumber: string) => string;
package/dist/links.js ADDED
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Converts a phone number into a `tel:` link.
3
+ *
4
+ * @param phoneNumber Phone number
5
+ * @returns `tel:` link for the phone number
6
+ */
7
+ export const getTelLink = (phoneNumber) => {
8
+ if (typeof phoneNumber !== 'string') {
9
+ throw new Error('Phone number must be a string.');
10
+ }
11
+ // Remove non-digit characters except for '+' which is used for international numbers
12
+ const cleanedPhoneNumber = phoneNumber.replace(/[^\d+]/g, '');
13
+ return `tel:${cleanedPhoneNumber}`;
14
+ };
15
+ //# sourceMappingURL=links.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"links.js","sourceRoot":"","sources":["../src/links.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,MAAM,CAAC,MAAM,UAAU,GAAG,CAAC,WAAmB,EAAU,EAAE;IACxD,IAAI,OAAO,WAAW,KAAK,QAAQ,EAAE,CAAC;QACpC,MAAM,IAAI,KAAK,CAAC,gCAAgC,CAAC,CAAC;IACpD,CAAC;IAED,qFAAqF;IACrF,MAAM,kBAAkB,GAAG,WAAW,CAAC,OAAO,CAAC,SAAS,EAAE,EAAE,CAAC,CAAC;IAE9D,OAAO,OAAO,kBAAkB,EAAE,CAAC;AACrC,CAAC,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@smartive/datocms-utils",
3
- "version": "1.5.0",
3
+ "version": "1.6.0",
4
4
  "description": "A set of utilities and helpers to work with DatoCMS in a Next.js project.",
5
5
  "source": "src/index.ts",
6
6
  "main": "dist/index.js",
package/src/index.ts CHANGED
@@ -1,3 +1,4 @@
1
1
  export * from './cache-tags';
2
2
  export * from './classnames';
3
+ export * from './links';
3
4
  export * from './types';
package/src/links.ts ADDED
@@ -0,0 +1,17 @@
1
+ /**
2
+ * Converts a phone number into a `tel:` link.
3
+ *
4
+ * @param phoneNumber Phone number
5
+ * @returns `tel:` link for the phone number
6
+ */
7
+
8
+ export const getTelLink = (phoneNumber: string): string => {
9
+ if (typeof phoneNumber !== 'string') {
10
+ throw new Error('Phone number must be a string.');
11
+ }
12
+
13
+ // Remove non-digit characters except for '+' which is used for international numbers
14
+ const cleanedPhoneNumber = phoneNumber.replace(/[^\d+]/g, '');
15
+
16
+ return `tel:${cleanedPhoneNumber}`;
17
+ };