@dynamic-labs/utils 1.4.12 → 1.4.13
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/package.json +3 -3
- package/src/index.cjs +2 -0
- package/src/index.d.ts +1 -0
- package/src/index.js +1 -0
- package/src/template/index.d.ts +1 -0
- package/src/template/template.cjs +24 -0
- package/src/template/template.d.ts +18 -0
- package/src/template/template.js +20 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,4 +1,12 @@
|
|
|
1
1
|
|
|
2
|
+
### [1.4.13](https://github.com/dynamic-labs/DynamicAuth/compare/v1.4.12...v1.4.13) (2024-06-05)
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
### Bug Fixes
|
|
6
|
+
|
|
7
|
+
* bump @solana/web3.js containing new version of rpc-websockets ([#5864](https://github.com/dynamic-labs/DynamicAuth/issues/5864)) ([562ff9b](https://github.com/dynamic-labs/DynamicAuth/commit/562ff9b706c8be62812ace08bcaef96e26dcd841))
|
|
8
|
+
* wallet improvements
|
|
9
|
+
|
|
2
10
|
### [1.4.12](https://github.com/dynamic-labs/DynamicAuth/compare/v1.4.11...v1.4.12) (2024-05-22)
|
|
3
11
|
|
|
4
12
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dynamic-labs/utils",
|
|
3
|
-
"version": "1.4.
|
|
3
|
+
"version": "1.4.13",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "https://github.com/dynamic-labs/DynamicAuth.git",
|
|
@@ -27,8 +27,8 @@
|
|
|
27
27
|
},
|
|
28
28
|
"dependencies": {
|
|
29
29
|
"tldts": "^6.0.16",
|
|
30
|
-
"@dynamic-labs/logger": "1.4.
|
|
31
|
-
"@dynamic-labs/types": "1.4.
|
|
30
|
+
"@dynamic-labs/logger": "1.4.13",
|
|
31
|
+
"@dynamic-labs/types": "1.4.13"
|
|
32
32
|
},
|
|
33
33
|
"peerDependencies": {
|
|
34
34
|
"viem": "^1.19.13 || ^2.2.0"
|
package/src/index.cjs
CHANGED
|
@@ -40,6 +40,7 @@ var handleMobileWalletRedirect = require('./handleMobileWalletRedirect/handleMob
|
|
|
40
40
|
var uniq = require('./uniq/uniq.cjs');
|
|
41
41
|
var getTLD = require('./getTLD/getTLD.cjs');
|
|
42
42
|
var pipe = require('./pipe/pipe.cjs');
|
|
43
|
+
var template = require('./template/template.cjs');
|
|
43
44
|
|
|
44
45
|
|
|
45
46
|
|
|
@@ -95,3 +96,4 @@ exports.handleMobileWalletRedirect = handleMobileWalletRedirect.handleMobileWall
|
|
|
95
96
|
exports.uniq = uniq.uniq;
|
|
96
97
|
exports.getTLD = getTLD.getTLD;
|
|
97
98
|
exports.pipe = pipe.pipe;
|
|
99
|
+
exports.template = template.template;
|
package/src/index.d.ts
CHANGED
package/src/index.js
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { template } from './template';
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Creates a template function that replaces placeholders with corresponding values from a data object.
|
|
7
|
+
* @param {string} templateText - The template string containing placeholders in the form {{placeholder}}.
|
|
8
|
+
* @returns {(data) => string} - A function that replaces the placeholders with the values from the data object.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* // Basic usage
|
|
12
|
+
* const compiled = template('Test text {{placeholder}} value');
|
|
13
|
+
* console.log(compiled({ placeholder: 'test' })); // Output: 'Test text test value'
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* // Multiple placeholders
|
|
17
|
+
* const compiled = template('Test text {{placeholder}} value {{placeholder2}}');
|
|
18
|
+
* console.log(compiled({ placeholder: 'test', placeholder2: 'test2' })); // Output: 'Test text test value test2'
|
|
19
|
+
*/
|
|
20
|
+
const template = (templateText) => {
|
|
21
|
+
return (data) => templateText.replace(/{{(\w+?)}}/g, (match, key) => key in data ? data[key] : match);
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
exports.template = template;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
type ExtractPlaceholders<T extends string> = T extends `${infer _Start}{{${infer Placeholder}}}${infer Rest}` ? Placeholder | ExtractPlaceholders<Rest> : never;
|
|
2
|
+
/**
|
|
3
|
+
* Creates a template function that replaces placeholders with corresponding values from a data object.
|
|
4
|
+
* @param {string} templateText - The template string containing placeholders in the form {{placeholder}}.
|
|
5
|
+
* @returns {(data) => string} - A function that replaces the placeholders with the values from the data object.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* // Basic usage
|
|
9
|
+
* const compiled = template('Test text {{placeholder}} value');
|
|
10
|
+
* console.log(compiled({ placeholder: 'test' })); // Output: 'Test text test value'
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* // Multiple placeholders
|
|
14
|
+
* const compiled = template('Test text {{placeholder}} value {{placeholder2}}');
|
|
15
|
+
* console.log(compiled({ placeholder: 'test', placeholder2: 'test2' })); // Output: 'Test text test value test2'
|
|
16
|
+
*/
|
|
17
|
+
export declare const template: <T extends string>(templateText: T) => (data: { [key in ExtractPlaceholders<T>]: string; }) => string;
|
|
18
|
+
export {};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Creates a template function that replaces placeholders with corresponding values from a data object.
|
|
3
|
+
* @param {string} templateText - The template string containing placeholders in the form {{placeholder}}.
|
|
4
|
+
* @returns {(data) => string} - A function that replaces the placeholders with the values from the data object.
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* // Basic usage
|
|
8
|
+
* const compiled = template('Test text {{placeholder}} value');
|
|
9
|
+
* console.log(compiled({ placeholder: 'test' })); // Output: 'Test text test value'
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* // Multiple placeholders
|
|
13
|
+
* const compiled = template('Test text {{placeholder}} value {{placeholder2}}');
|
|
14
|
+
* console.log(compiled({ placeholder: 'test', placeholder2: 'test2' })); // Output: 'Test text test value test2'
|
|
15
|
+
*/
|
|
16
|
+
const template = (templateText) => {
|
|
17
|
+
return (data) => templateText.replace(/{{(\w+?)}}/g, (match, key) => key in data ? data[key] : match);
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
export { template };
|