@gradientedge/commercetools-utils 1.54.1 → 1.55.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.
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Format a string for use as a key.
3
+ *
4
+ * Keys may only contain alphanumeric characters, underscores and hyphens
5
+ * and must have a minimum length of 2 characters and maximum length of
6
+ * 256 characters.
7
+ *
8
+ * @param {string} input The string that you want to format as a key
9
+ */
10
+ export declare function formatAsKey(input: unknown): string;
11
+ //# sourceMappingURL=format.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"format.d.ts","sourceRoot":"","sources":["../../src/lib/utils/format.ts"],"names":[],"mappings":"AAEA;;;;;;;;GAQG;AACH,wBAAgB,WAAW,CAAC,KAAK,EAAE,OAAO,UAoCzC"}
@@ -0,0 +1,48 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.formatAsKey = void 0;
4
+ var error_1 = require("../error");
5
+ /**
6
+ * Format a string for use as a key.
7
+ *
8
+ * Keys may only contain alphanumeric characters, underscores and hyphens
9
+ * and must have a minimum length of 2 characters and maximum length of
10
+ * 256 characters.
11
+ *
12
+ * @param {string} input The string that you want to format as a key
13
+ */
14
+ function formatAsKey(input) {
15
+ var output = '';
16
+ if (typeof input !== 'string') {
17
+ throw new error_1.CommercetoolsError("The [input] parameter must be a string");
18
+ }
19
+ // Trim and make lowercase
20
+ output = input.trim().toLowerCase();
21
+ // Replace any instance of more than one space, with a single space
22
+ output = output.replace(/ {2,}/g, '');
23
+ // Replacing '&' for 'and'
24
+ output = output.replace(/&/g, 'and');
25
+ // Replace spaces for hyphen or underscore
26
+ output = output.replace(/[ _]/g, '-');
27
+ // Remove any non-alphanumeric characters (except for hyphens)
28
+ output = output.replace(/[^0-9a-z-]+/g, '');
29
+ // Replace any instance of more than one hyphen, with a single hyphen
30
+ output = output.replace(/-{2,}/g, '-');
31
+ // Remove any leading hyphen
32
+ if (output.length && output[0] === '-') {
33
+ output = output.slice(1);
34
+ }
35
+ // Remove any trailing hyphen
36
+ if (output.length && output[output.length - 1] === '-') {
37
+ output = output.slice(0, -1);
38
+ }
39
+ if (output.length < 2) {
40
+ throw new error_1.CommercetoolsError("Formatted key did not meet minimum length of 2 characters: " + output);
41
+ }
42
+ if (output.length > 256) {
43
+ throw new error_1.CommercetoolsError("Formatted key exceeds the maximum length of 256 characters: " + output);
44
+ }
45
+ return output;
46
+ }
47
+ exports.formatAsKey = formatAsKey;
48
+ //# sourceMappingURL=format.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"format.js","sourceRoot":"","sources":["../../src/lib/utils/format.ts"],"names":[],"mappings":";;;AAAA,kCAA6C;AAE7C;;;;;;;;GAQG;AACH,SAAgB,WAAW,CAAC,KAAc;IACxC,IAAI,MAAM,GAAG,EAAE,CAAA;IAEf,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE;QAC7B,MAAM,IAAI,0BAAkB,CAAC,wCAAwC,CAAC,CAAA;KACvE;IAED,0BAA0B;IAC1B,MAAM,GAAG,KAAK,CAAC,IAAI,EAAE,CAAC,WAAW,EAAE,CAAA;IACnC,mEAAmE;IACnE,MAAM,GAAG,MAAM,CAAC,OAAO,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAA;IACrC,0BAA0B;IAC1B,MAAM,GAAG,MAAM,CAAC,OAAO,CAAC,IAAI,EAAE,KAAK,CAAC,CAAA;IACpC,0CAA0C;IAC1C,MAAM,GAAG,MAAM,CAAC,OAAO,CAAC,OAAO,EAAE,GAAG,CAAC,CAAA;IACrC,8DAA8D;IAC9D,MAAM,GAAG,MAAM,CAAC,OAAO,CAAC,cAAc,EAAE,EAAE,CAAC,CAAA;IAC3C,qEAAqE;IACrE,MAAM,GAAG,MAAM,CAAC,OAAO,CAAC,QAAQ,EAAE,GAAG,CAAC,CAAA;IACtC,4BAA4B;IAC5B,IAAI,MAAM,CAAC,MAAM,IAAI,MAAM,CAAC,CAAC,CAAC,KAAK,GAAG,EAAE;QACtC,MAAM,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAA;KACzB;IACD,6BAA6B;IAC7B,IAAI,MAAM,CAAC,MAAM,IAAI,MAAM,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC,CAAC,KAAK,GAAG,EAAE;QACtD,MAAM,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAA;KAC7B;IAED,IAAI,MAAM,CAAC,MAAM,GAAG,CAAC,EAAE;QACrB,MAAM,IAAI,0BAAkB,CAAC,gEAA8D,MAAQ,CAAC,CAAA;KACrG;IACD,IAAI,MAAM,CAAC,MAAM,GAAG,GAAG,EAAE;QACvB,MAAM,IAAI,0BAAkB,CAAC,iEAA+D,MAAQ,CAAC,CAAA;KACtG;IAED,OAAO,MAAM,CAAA;AACf,CAAC;AApCD,kCAoCC"}
@@ -1,12 +1,4 @@
1
- export declare function buildUserAgent(systemIdentifier?: string): string;
2
- /**
3
- * Format a string for use as a key.
4
- *
5
- * Keys may only contain alphanumeric characters, underscores and hyphens
6
- * and must have a minimum length of 2 characters and maximum length of
7
- * 256 characters.
8
- *
9
- * @param {string} input The string that you want to format as a key
10
- */
11
- export declare function formatAsKey(input: string): string;
1
+ export * from './format';
2
+ export * from './useragent';
3
+ export * from './mask';
12
4
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/lib/utils/index.ts"],"names":[],"mappings":"AAUA,wBAAgB,cAAc,CAAC,gBAAgB,CAAC,EAAE,MAAM,UAMvD;AAED;;;;;;;;GAQG;AACH,wBAAgB,WAAW,CAAC,KAAK,EAAE,MAAM,UAoCxC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/lib/utils/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAA;AACxB,cAAc,aAAa,CAAA;AAC3B,cAAc,QAAQ,CAAA"}
@@ -1,64 +1,16 @@
1
1
  "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
+ }) : (function(o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ o[k2] = m[k];
8
+ }));
9
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
10
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
11
+ };
2
12
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.formatAsKey = exports.buildUserAgent = void 0;
4
- /**
5
- * Build a string suitable for sending as the `User-Agent` HTTP header.
6
- * This should contain information that allows commercetools to easily
7
- * identify the source of the request. The `systemIdentifier` comes from
8
- * {@see CommercetoolsApiConfig.systemIdentifier} and should be a string
9
- * that uniquely identifies the application where this package is being
10
- * used.
11
- */
12
- var error_1 = require("../error");
13
- function buildUserAgent(systemIdentifier) {
14
- var userAgent = "@gradientedge/commercetools-utils";
15
- if (systemIdentifier) {
16
- userAgent = userAgent + " (" + systemIdentifier + ")";
17
- }
18
- return userAgent;
19
- }
20
- exports.buildUserAgent = buildUserAgent;
21
- /**
22
- * Format a string for use as a key.
23
- *
24
- * Keys may only contain alphanumeric characters, underscores and hyphens
25
- * and must have a minimum length of 2 characters and maximum length of
26
- * 256 characters.
27
- *
28
- * @param {string} input The string that you want to format as a key
29
- */
30
- function formatAsKey(input) {
31
- var output = '';
32
- if (typeof input !== 'string') {
33
- throw new error_1.CommercetoolsError("The [input] parameter must be a string");
34
- }
35
- // Trim and make lowercase
36
- output = input.trim().toLowerCase();
37
- // Replace any instance of more than one space, with a single space
38
- output = output.replace(/ {2,}/g, '');
39
- // Replacing '&' for 'and'
40
- output = output.replace(/&/g, 'and');
41
- // Replace spaces for hyphen or underscore
42
- output = output.replace(/[ _]/g, '-');
43
- // Remove any non-alphanumeric characters (except for hyphens)
44
- output = output.replace(/[^0-9a-z-]+/g, '');
45
- // Replace any instance of more than one hyphen, with a single hyphen
46
- output = output.replace(/-{2,}/g, '-');
47
- // Remove any leading hyphen
48
- if (output.length && output[0] === '-') {
49
- output = output.slice(1);
50
- }
51
- // Remove any trailing hyphen
52
- if (output.length && output[output.length - 1] === '-') {
53
- output = output.slice(0, -1);
54
- }
55
- if (output.length < 2) {
56
- throw new error_1.CommercetoolsError("Formatted key did not meet minimum length of 2 characters: " + output);
57
- }
58
- if (output.length > 256) {
59
- throw new error_1.CommercetoolsError("Formatted key exceeds the maximum length of 256 characters: " + output);
60
- }
61
- return output;
62
- }
63
- exports.formatAsKey = formatAsKey;
13
+ __exportStar(require("./format"), exports);
14
+ __exportStar(require("./useragent"), exports);
15
+ __exportStar(require("./mask"), exports);
64
16
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/lib/utils/index.ts"],"names":[],"mappings":";;;AAAA;;;;;;;GAOG;AACH,kCAA6C;AAE7C,SAAgB,cAAc,CAAC,gBAAyB;IACtD,IAAI,SAAS,GAAG,mCAAmC,CAAA;IACnD,IAAI,gBAAgB,EAAE;QACpB,SAAS,GAAM,SAAS,UAAK,gBAAgB,MAAG,CAAA;KACjD;IACD,OAAO,SAAS,CAAA;AAClB,CAAC;AAND,wCAMC;AAED;;;;;;;;GAQG;AACH,SAAgB,WAAW,CAAC,KAAa;IACvC,IAAI,MAAM,GAAG,EAAE,CAAA;IAEf,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE;QAC7B,MAAM,IAAI,0BAAkB,CAAC,wCAAwC,CAAC,CAAA;KACvE;IAED,0BAA0B;IAC1B,MAAM,GAAG,KAAK,CAAC,IAAI,EAAE,CAAC,WAAW,EAAE,CAAA;IACnC,mEAAmE;IACnE,MAAM,GAAG,MAAM,CAAC,OAAO,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAA;IACrC,0BAA0B;IAC1B,MAAM,GAAG,MAAM,CAAC,OAAO,CAAC,IAAI,EAAE,KAAK,CAAC,CAAA;IACpC,0CAA0C;IAC1C,MAAM,GAAG,MAAM,CAAC,OAAO,CAAC,OAAO,EAAE,GAAG,CAAC,CAAA;IACrC,8DAA8D;IAC9D,MAAM,GAAG,MAAM,CAAC,OAAO,CAAC,cAAc,EAAE,EAAE,CAAC,CAAA;IAC3C,qEAAqE;IACrE,MAAM,GAAG,MAAM,CAAC,OAAO,CAAC,QAAQ,EAAE,GAAG,CAAC,CAAA;IACtC,4BAA4B;IAC5B,IAAI,MAAM,CAAC,MAAM,IAAI,MAAM,CAAC,CAAC,CAAC,KAAK,GAAG,EAAE;QACtC,MAAM,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAA;KACzB;IACD,6BAA6B;IAC7B,IAAI,MAAM,CAAC,MAAM,IAAI,MAAM,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC,CAAC,KAAK,GAAG,EAAE;QACtD,MAAM,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAA;KAC7B;IAED,IAAI,MAAM,CAAC,MAAM,GAAG,CAAC,EAAE;QACrB,MAAM,IAAI,0BAAkB,CAAC,gEAA8D,MAAQ,CAAC,CAAA;KACrG;IACD,IAAI,MAAM,CAAC,MAAM,GAAG,GAAG,EAAE;QACvB,MAAM,IAAI,0BAAkB,CAAC,iEAA+D,MAAQ,CAAC,CAAA;KACtG;IAED,OAAO,MAAM,CAAA;AACf,CAAC;AApCD,kCAoCC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/lib/utils/index.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,2CAAwB;AACxB,8CAA2B;AAC3B,yCAAsB"}
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Build a string suitable for sending as the `User-Agent` HTTP header.
3
+ * This should contain information that allows commercetools to easily
4
+ * identify the source of the request. The `systemIdentifier` comes from
5
+ * {@see CommercetoolsApiConfig.systemIdentifier} and should be a string
6
+ * that uniquely identifies the application where this package is being
7
+ * used.
8
+ */
9
+ export declare function buildUserAgent(systemIdentifier?: string): string;
10
+ //# sourceMappingURL=useragent.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useragent.d.ts","sourceRoot":"","sources":["../../src/lib/utils/useragent.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,wBAAgB,cAAc,CAAC,gBAAgB,CAAC,EAAE,MAAM,UAMvD"}
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.buildUserAgent = void 0;
4
+ /**
5
+ * Build a string suitable for sending as the `User-Agent` HTTP header.
6
+ * This should contain information that allows commercetools to easily
7
+ * identify the source of the request. The `systemIdentifier` comes from
8
+ * {@see CommercetoolsApiConfig.systemIdentifier} and should be a string
9
+ * that uniquely identifies the application where this package is being
10
+ * used.
11
+ */
12
+ function buildUserAgent(systemIdentifier) {
13
+ var userAgent = "@gradientedge/commercetools-utils";
14
+ if (systemIdentifier) {
15
+ userAgent = userAgent + " (" + systemIdentifier + ")";
16
+ }
17
+ return userAgent;
18
+ }
19
+ exports.buildUserAgent = buildUserAgent;
20
+ //# sourceMappingURL=useragent.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useragent.js","sourceRoot":"","sources":["../../src/lib/utils/useragent.ts"],"names":[],"mappings":";;;AAAA;;;;;;;GAOG;AACH,SAAgB,cAAc,CAAC,gBAAyB;IACtD,IAAI,SAAS,GAAG,mCAAmC,CAAA;IACnD,IAAI,gBAAgB,EAAE;QACpB,SAAS,GAAM,SAAS,UAAK,gBAAgB,MAAG,CAAA;KACjD;IACD,OAAO,SAAS,CAAA;AAClB,CAAC;AAND,wCAMC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gradientedge/commercetools-utils",
3
- "version": "1.54.1",
3
+ "version": "1.55.0",
4
4
  "description": "Provide utility classes and functions for interacting with the commercetools API",
5
5
  "main": "build/index.js",
6
6
  "scripts": {