Socket
Socket
Sign inDemoInstall

@oneblink/sdk-core

Package Overview
Dependencies
Maintainers
6
Versions
135
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@oneblink/sdk-core - npm Package Compare versions

Comparing version 0.4.6-beta.2 to 0.4.6-beta.3

21

dist/formElementsService.d.ts

@@ -89,6 +89,3 @@ import { FormTypes } from '@oneblink/types';

declare function flattenFormElements(elements: FormTypes.FormElement[]): FormTypes.FormElement[];
/**
* The regex used for matching `{ELEMENT:<elementName>}` tags in OneBlink
* Calculation and Info (HTML) elements.
*/
/** The regex used for matching `{ELEMENT:<elementName>}` tags in the OneBlink platform. */
declare const WYSIWYGRegex: RegExp;

@@ -103,6 +100,9 @@ /**

* ```js
* formElementsService.matchElementsTagRegex(myString, (elementName) => {
* const v = submission[elementName]
* myString = myString.replace(`{ELEMENT:${elementName}}`, v)
* })
* formElementsService.matchElementsTagRegex(
* myString,
* ({ elementName, elementMatch }) => {
* const v = submission[elementName]
* myString = myString.replace(elementMatch, v)
* },
* )
* ```

@@ -114,3 +114,6 @@ *

*/
declare const matchElementsTagRegex: (data: string, matchHandler: (elementName: string) => void) => void;
declare const matchElementsTagRegex: (data: string, matchHandler: (options: {
elementName: string;
elementMatch: string;
}) => void) => void;
export { forEachFormElement, forEachFormElementWithOptions, findFormElement, parseFormElementOptionsSet, flattenFormElements, WYSIWYGRegex, matchElementsTagRegex, };

@@ -175,6 +175,3 @@ "use strict";

exports.flattenFormElements = flattenFormElements;
/**
* The regex used for matching `{ELEMENT:<elementName>}` tags in OneBlink
* Calculation and Info (HTML) elements.
*/
/** The regex used for matching `{ELEMENT:<elementName>}` tags in the OneBlink platform. */
const WYSIWYGRegex = /({ELEMENT:)([^}]+)(})/g;

@@ -190,6 +187,9 @@ exports.WYSIWYGRegex = WYSIWYGRegex;

* ```js
* formElementsService.matchElementsTagRegex(myString, (elementName) => {
* const v = submission[elementName]
* myString = myString.replace(`{ELEMENT:${elementName}}`, v)
* })
* formElementsService.matchElementsTagRegex(
* myString,
* ({ elementName, elementMatch }) => {
* const v = submission[elementName]
* myString = myString.replace(elementMatch, v)
* },
* )
* ```

@@ -207,3 +207,3 @@ *

const elementName = matches[2];
matchHandler(elementName);
matchHandler({ elementName, elementMatch: matches[0] });
}

@@ -210,0 +210,0 @@ };

@@ -67,2 +67,48 @@ import { FormTypes, SubmissionTypes } from '@oneblink/types';

/**
* Takes a string and replaces the {ELEMENT:<elementName>} tags.
*
* #### Example
*
* ```js
* const result = submissionService.replaceElementValues(
* 'https://example.com/path?search{ELEMENT:search}',
* {
* formatDate: (value) => new Date(value).toDateString(),
* formatTime: (value) => new Date(value).toTimeString(),
* formatNumber: (value) => Number(value).toString(),
* formatCurrency: (value) => Number(value).toFixed(2),
* submission: {
* search: 'Entered By User',
* },
* elements: [
* {
* id: 'd4135b47-9004-4d75-aeb3-d2f6232da111',
* name: 'search',
* type: 'text',
* label: 'Search',
* readOnly: false,
* required: false,
* conditionallyShow: false,
* requiresAllConditionallyShowPredicates: false,
* isElementLookup: false,
* isDataLookup: false,
* },
* ],
* },
* )
* ```
*
* @param text
* @param options
* @returns
*/
export declare function replaceElementValues(text: string, { formElements, submission, formatDate, formatTime, formatNumber, formatCurrency, }: {
formElements: FormTypes.FormElement[];
submission: SubmissionTypes.S3SubmissionData['submission'];
formatDate: (value: string) => string;
formatTime: (value: string) => string;
formatNumber: (value: number) => string;
formatCurrency: (value: number) => string;
}): string;
/**
* Function to replace a custom values in text

@@ -69,0 +115,0 @@ *

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.replaceCustomValues = exports.getElementSubmissionValue = void 0;
exports.replaceCustomValues = exports.replaceElementValues = exports.getElementSubmissionValue = void 0;
const formElementsService_1 = require("./formElementsService");

@@ -201,12 +201,49 @@ const abnService_1 = require("./abnService");

exports.getElementSubmissionValue = getElementSubmissionValue;
function replaceElementValues(text, { form, submission, formatDate, formatTime, formatNumber, formatCurrency, }) {
const matches = text.match(/({ELEMENT:)([^}]+)(})/g);
/**
* Takes a string and replaces the {ELEMENT:<elementName>} tags.
*
* #### Example
*
* ```js
* const result = submissionService.replaceElementValues(
* 'https://example.com/path?search{ELEMENT:search}',
* {
* formatDate: (value) => new Date(value).toDateString(),
* formatTime: (value) => new Date(value).toTimeString(),
* formatNumber: (value) => Number(value).toString(),
* formatCurrency: (value) => Number(value).toFixed(2),
* submission: {
* search: 'Entered By User',
* },
* elements: [
* {
* id: 'd4135b47-9004-4d75-aeb3-d2f6232da111',
* name: 'search',
* type: 'text',
* label: 'Search',
* readOnly: false,
* required: false,
* conditionallyShow: false,
* requiresAllConditionallyShowPredicates: false,
* isElementLookup: false,
* isDataLookup: false,
* },
* ],
* },
* )
* ```
*
* @param text
* @param options
* @returns
*/
function replaceElementValues(text, { formElements, submission, formatDate, formatTime, formatNumber, formatCurrency, }) {
const matches = text.match(formElementsService_1.WYSIWYGRegex);
if (!matches) {
return text;
}
return matches.reduce((newString, match) => {
const propertyName = match.substring(match.indexOf(':') + 1, match.lastIndexOf('}'));
(0, formElementsService_1.matchElementsTagRegex)(text, ({ elementName, elementMatch }) => {
const value = getElementSubmissionValue({
propertyName,
formElements: form.elements,
propertyName: elementName,
formElements,
submission,

@@ -218,5 +255,7 @@ formatDate,

});
return newString.replace(match, value === undefined ? '' : value);
}, text);
text = text.replace(elementMatch, value === undefined ? '' : value);
});
return text;
}
exports.replaceElementValues = replaceElementValues;
/**

@@ -276,3 +315,3 @@ * Function to replace a custom values in text

const string = replaceElementValues(text, {
form,
formElements: form.elements,
submission,

@@ -279,0 +318,0 @@ formatDate,

@@ -23,20 +23,1 @@ import { FormTypes, SubmissionTypes } from '@oneblink/types';

export declare function getRootElementValueById(formElementId: string, formElements: FormTypes.FormElement[], submission: SubmissionTypes.S3SubmissionData['submission']): unknown;
/**
* Takes an element name and a submission object, and returns the provided
* element's value as a string. Used for replaceable values in OneBlink
* Calculation and Info (HTML) elements.
*
* #### Example
*
* ```js
* const nameElementValue = submissionService.getSubmissionValueAsString(
* 'Name_Element',
* submission,
* )
* ```
*
* @param elementName
* @param submission
* @returns
*/
export declare function getSubmissionValueAsString(elementName: string, submission: SubmissionTypes.S3SubmissionData['submission']): string;

@@ -17,3 +17,3 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
exports.getSubmissionValueAsString = exports.getRootElementValueById = void 0;
exports.getRootElementValueById = void 0;
__exportStar(require("./replaceCustomValues"), exports);

@@ -53,43 +53,2 @@ /**

exports.getRootElementValueById = getRootElementValueById;
/**
* Takes an element name and a submission object, and returns the provided
* element's value as a string. Used for replaceable values in OneBlink
* Calculation and Info (HTML) elements.
*
* #### Example
*
* ```js
* const nameElementValue = submissionService.getSubmissionValueAsString(
* 'Name_Element',
* submission,
* )
* ```
*
* @param elementName
* @param submission
* @returns
*/
function getSubmissionValueAsString(elementName, submission) {
const v = submission[elementName];
switch (typeof v) {
case 'function':
case 'undefined':
case 'symbol': {
return '';
}
case 'object': {
// Account for null
return (v === null || v === void 0 ? void 0 : v.toString()) || '';
}
case 'number':
case 'boolean':
case 'bigint': {
return v.toString();
}
default: {
return v;
}
}
}
exports.getSubmissionValueAsString = getSubmissionValueAsString;
//# sourceMappingURL=submissionService.js.map
{
"name": "@oneblink/sdk-core",
"description": "OneBlink SDK for JavaScript (works in Browsers and NodeJS)",
"version": "0.4.6-beta.2",
"version": "0.4.6-beta.3",
"author": "OneBlink <developers@oneblink.io> (https://oneblink.io)",

@@ -6,0 +6,0 @@ "bugs": {

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc