Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@memberjunction/global

Package Overview
Dependencies
Maintainers
4
Versions
204
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@memberjunction/global - npm Package Compare versions

Comparing version 1.0.1 to 1.0.2

13

dist/util.d.ts

@@ -13,2 +13,15 @@ /**

export declare function CopyScalarsAndArrays<T extends object>(input: T): Partial<T>;
/**
* This function takes in an input string and attempts to clean it up to return a valid JSON string. This function will attempt to extract JSON from a Markdown code block if it exists,
* otherwise it will attempt to extract JSON from the input string itself. If the input string is not valid JSON, this function will return null.
* @param inputString
* @returns
*/
export declare function CleanJSON(inputString: string | null): string | null;
/**
* This function takes in a string that may contain JavaScript code in a markdown code block and returns the JavaScript code without the code block.
* @param javaScriptCode
* @returns
*/
export declare function CleanJavaScript(javaScriptCode: string): string;
//# sourceMappingURL=util.d.ts.map

78

dist/util.js
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.CopyScalarsAndArrays = exports.GetGlobalObjectStore = void 0;
exports.CleanJavaScript = exports.CleanJSON = exports.CopyScalarsAndArrays = exports.GetGlobalObjectStore = void 0;
/**

@@ -65,2 +65,78 @@ * The Global Object Store is a place to store global objects that need to be shared across the application. Depending on the execution environment, this could be the window object in a browser, or the global object in a node environment.

exports.CopyScalarsAndArrays = CopyScalarsAndArrays;
/**
* This function takes in an input string and attempts to clean it up to return a valid JSON string. This function will attempt to extract JSON from a Markdown code block if it exists,
* otherwise it will attempt to extract JSON from the input string itself. If the input string is not valid JSON, this function will return null.
* @param inputString
* @returns
*/
function CleanJSON(inputString) {
if (!inputString)
return null;
// replace all \n and \t with nothing
const jsonString = inputString.trim().replace(/\n/g, "").replace(/\t/g, "");
// Regular expression to match JavaScript code blocks within Markdown fences
// This regex looks for ``` optionally followed by js or javascript (case-insensitive), then captures until the closing ```
const markdownRegex = /```(?:json|JSON)?\s*([\s\S]*?)```/gi;
// Check if the input contains Markdown code fences for JavaScript
const matches = Array.from(jsonString.matchAll(markdownRegex));
if (matches.length > 0) {
// If there are matches, concatenate all captured groups (in case there are multiple code blocks)
return matches.map(match => match[1].trim()).join('\n');
}
else {
// If there are no Markdown code fences, we could have a string that contains JSON, or is JUST JSON
// Attempt to extract JSON from a mixed string
const firstBracketIndex = jsonString.indexOf('[');
const firstBraceIndex = jsonString.indexOf('{');
let startIndex = -1;
let endIndex = -1;
// Determine the starting index based on the position of the first '[' and '{'
if ((firstBracketIndex !== -1 && firstBracketIndex < firstBraceIndex) || firstBraceIndex === -1) {
startIndex = firstBracketIndex;
endIndex = jsonString.lastIndexOf(']');
}
else if (firstBraceIndex !== -1) {
startIndex = firstBraceIndex;
endIndex = jsonString.lastIndexOf('}');
}
if (startIndex === -1 || endIndex === -1 || endIndex < startIndex) {
console.warn("No JSON found in the input.");
return jsonString.trim();
}
const potentialJSON = jsonString.substring(startIndex, endIndex + 1);
try {
// Parse and stringify to format the JSON nicely
// and to validate it's indeed a valid JSON.
const jsonObject = JSON.parse(potentialJSON);
return JSON.stringify(jsonObject, null, 2);
}
catch (error) {
console.error("Failed to parse extracted string as JSON:", error);
// Return null or potentially invalid JSON text as a fallback
return null;
}
}
}
exports.CleanJSON = CleanJSON;
/**
* This function takes in a string that may contain JavaScript code in a markdown code block and returns the JavaScript code without the code block.
* @param javaScriptCode
* @returns
*/
function CleanJavaScript(javaScriptCode) {
// Regular expression to match JavaScript code blocks within Markdown fences
// This regex looks for ``` optionally followed by js or javascript (case-insensitive), then captures until the closing ```
const markdownRegex = /```(?:js|javascript)?\s*([\s\S]*?)```/gi;
// Check if the input contains Markdown code fences for JavaScript
const matches = Array.from(javaScriptCode.matchAll(markdownRegex));
if (matches.length > 0) {
// If there are matches, concatenate all captured groups (in case there are multiple code blocks)
return matches.map(match => match[1].trim()).join('\n');
}
else {
// If there are no Markdown code fences, assume the input is plain JavaScript code
return javaScriptCode.trim();
}
}
exports.CleanJavaScript = CleanJavaScript;
//# sourceMappingURL=util.js.map

2

package.json
{
"name": "@memberjunction/global",
"version": "1.0.1",
"version": "1.0.2",
"description": "MemberJunction: Global Object - Needed for ALL other MJ components",

@@ -5,0 +5,0 @@ "main": "dist/index.js",

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