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

@graphql-markdown/utils

Package Overview
Dependencies
Maintainers
1
Versions
23
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@graphql-markdown/utils - npm Package Compare versions

Comparing version 1.6.0-next.0 to 1.6.0

4

dist/array.d.ts

@@ -32,3 +32,3 @@ /**

*/
export declare function toArray(recordMap: Maybe<Record<string, unknown>>): Maybe<unknown[]>;
export declare const toArray: (recordMap: Maybe<Record<string, unknown>>) => Maybe<unknown[]>;
/**

@@ -64,2 +64,2 @@ * Returns a k/v object from an array of objects with a `name` property.

*/
export declare function convertArrayToMapObject<T>(list: Maybe<T[]>): Maybe<Record<string, T>>;
export declare const convertArrayToMapObject: <T>(list: Maybe<T[]>) => Maybe<Record<string, T>>;

@@ -34,8 +34,10 @@ "use strict";

*/
function toArray(recordMap) {
const toArray = (recordMap) => {
if (typeof recordMap !== "object" || recordMap === null) {
return undefined;
}
return Object.keys(recordMap).map((key) => recordMap[key]);
}
return Object.keys(recordMap).map((key) => {
return recordMap[key];
});
};
exports.toArray = toArray;

@@ -72,3 +74,3 @@ /**

*/
function convertArrayToMapObject(list) {
const convertArrayToMapObject = (list) => {
if (!Array.isArray(list)) {

@@ -87,3 +89,3 @@ return undefined;

}, {});
}
};
exports.convertArrayToMapObject = convertArrayToMapObject;

@@ -9,37 +9,37 @@ /**

/**
* Asynchronously create a folder structure if it does not exist.
* Asynchronously check if a file or folder exists at the path location.
*
*
* @param location - folder structure in path format.
* @param location - file or folder location.
*
* @example
* ```js
* import { ensureDir } from '@graphql-markdown/utils/fs';
* import { fileExists } from '@graphql-markdown/utils/fs';
*
* await ensureDir("./.temp/local")
* await fileExists("./.temp/local")
*
* // Creates both folders if they do not exists.
* // Expected true if path is valid, false if not
* ```
*
* @returns `true` if the path is valid, else `false` if not.
*
*/
export declare function ensureDir(location: string): Promise<void>;
export declare const fileExists: (location: string) => Promise<boolean>;
/**
* Asynchronously check if a file or folder exists at the path location.
* Asynchronously create a folder structure if it does not exist.
*
*
* @param location - file or folder location.
* @param location - folder structure in path format.
*
* @example
* ```js
* import { fileExists } from '@graphql-markdown/utils/fs';
* import { ensureDir } from '@graphql-markdown/utils/fs';
*
* await fileExists("./.temp/local")
* await ensureDir("./.temp/local")
*
* // Expected true if path is valid, false if not
* // Creates both folders if they do not exists.
* ```
*
* @returns `true` if the path is valid, else `false` if not.
*
*/
export declare function fileExists(location: string): Promise<boolean>;
export declare const ensureDir: (location: string) => Promise<void>;
/**

@@ -67,2 +67,2 @@ * Asynchronously save a file with a string content at specified location in local FS.

*/
export declare function saveFile(location: string, content: string, prettify?: PrettifyCallbackFunction): Promise<void>;
export declare const saveFile: (location: string, content: string, prettify?: PrettifyCallbackFunction) => Promise<void>;

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

Object.defineProperty(exports, "__esModule", { value: true });
exports.saveFile = exports.fileExists = exports.ensureDir = exports.copyFile = exports.readFile = void 0;
exports.saveFile = exports.ensureDir = exports.fileExists = exports.copyFile = exports.readFile = void 0;
const promises_1 = require("node:fs/promises");

@@ -16,24 +16,2 @@ const node_path_1 = require("node:path");

/**
* Asynchronously create a folder structure if it does not exist.
*
*
* @param location - folder structure in path format.
*
* @example
* ```js
* import { ensureDir } from '@graphql-markdown/utils/fs';
*
* await ensureDir("./.temp/local")
*
* // Creates both folders if they do not exists.
* ```
*
*/
async function ensureDir(location) {
if (!(await fileExists(location))) {
await (0, promises_1.mkdir)(location, { recursive: true });
}
}
exports.ensureDir = ensureDir;
/**
* Asynchronously check if a file or folder exists at the path location.

@@ -56,3 +34,3 @@ *

*/
async function fileExists(location) {
const fileExists = async (location) => {
try {

@@ -65,5 +43,27 @@ const stats = await (0, promises_1.stat)(location);

}
}
};
exports.fileExists = fileExists;
/**
* Asynchronously create a folder structure if it does not exist.
*
*
* @param location - folder structure in path format.
*
* @example
* ```js
* import { ensureDir } from '@graphql-markdown/utils/fs';
*
* await ensureDir("./.temp/local")
*
* // Creates both folders if they do not exists.
* ```
*
*/
const ensureDir = async (location) => {
if (!(await (0, exports.fileExists)(location))) {
await (0, promises_1.mkdir)(location, { recursive: true });
}
};
exports.ensureDir = ensureDir;
/**
* Asynchronously save a file with a string content at specified location in local FS.

@@ -90,9 +90,9 @@ * Override the file content if the file already exists.

*/
async function saveFile(location, content, prettify) {
const saveFile = async (location, content, prettify) => {
if (typeof prettify === "function") {
content = (await prettify(content)) ?? content;
}
await ensureDir((0, node_path_1.dirname)(location));
await (0, exports.ensureDir)((0, node_path_1.dirname)(location));
await (0, promises_1.writeFile)(location, content, "utf8");
}
};
exports.saveFile = saveFile;

@@ -33,2 +33,2 @@ /**

*/
export declare function isEmpty(obj: unknown): boolean;
export declare const isEmpty: (obj: unknown) => boolean;

@@ -36,7 +36,7 @@ "use strict";

*/
function isEmpty(obj) {
const isEmpty = (obj) => {
return !(typeof obj === "object" &&
obj !== null &&
Object.keys(obj).length > 0);
}
};
exports.isEmpty = isEmpty;

@@ -22,3 +22,3 @@ /**

*/
export declare function prettify(content: string, parser: string): Promise<string | undefined>;
export declare const prettify: (content: string, parser: string) => Promise<string | undefined>;
/**

@@ -39,3 +39,3 @@ * Prettify a Markdown string using {@link prettify} and `markdown` parser.

*/
export declare function prettifyMarkdown(content: string): Promise<string | undefined>;
export declare const prettifyMarkdown: (content: string) => Promise<string | undefined>;
/**

@@ -56,2 +56,2 @@ * Prettify a Javascript string using {@link prettify} and `babel` parser.

*/
export declare function prettifyJavascript(content: string): Promise<string | undefined>;
export declare const prettifyJavascript: (content: string) => Promise<string | undefined>;

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

*/
async function prettify(content, parser) {
const prettify = async (content, parser) => {
try {

@@ -57,3 +57,3 @@ const { format } = await Promise.resolve().then(() => __importStar(require("prettier")));

if ("logger" in global) {
global.logger.warn("Prettier is not found");
global.logger._log("Prettier is not found");
}

@@ -65,3 +65,3 @@ else {

}
}
};
exports.prettify = prettify;

@@ -83,5 +83,5 @@ /**

*/
async function prettifyMarkdown(content) {
return prettify(content, "markdown");
}
const prettifyMarkdown = async (content) => {
return (0, exports.prettify)(content, "markdown");
};
exports.prettifyMarkdown = prettifyMarkdown;

@@ -103,5 +103,5 @@ /**

*/
async function prettifyJavascript(content) {
return prettify(content, "babel");
}
const prettifyJavascript = async (content) => {
return (0, exports.prettify)(content, "babel");
};
exports.prettifyJavascript = prettifyJavascript;

@@ -8,29 +8,20 @@ /**

/**
* Returns a string after applying a transformation function.
* By default `splitter` expression will split the string into words, where non-alphanum chars are considered as word separators.
* `separator` will be used for joining the words back together.
* {@link prune} using `separator` is applied to the result of the transformation.
* Replaces diacritics by non-diacritic equivalent characters.
*
* @internal
*
* @param str - the string to be transformed.
* @param transformation - optional transformation callback function.
* @param separator - optional character separator for word-based transformation.
* @param splitter - optional regex or string rule for splitting string into word.
*
* @returns a transformed string, or an empty string if `str` is not a valid string.
* @returns a string with diacritic characters replaced, or an empty string if `str` is not a valid string.
*
* @example
* * @example
* ```js
* import { stringCaseBuilder } from "@graphql-markdown/utils/string";
* import { replaceDiacritics } from "@graphql-markdown/utils/string";
*
* const text = "The quick brown fox jumps over the lazy dog.";
* const transformation = (word: string): string => `*${word}*`
*
* stringCaseBuilder(text, transformation, " ");
* // Expected result: "*The* *quick* *brown* *fox* *jumps* *over* *the* *lazy* *dog*"
* replaceDiacritics("Âéêś"); // Expected result: "Aees"
* ```
*
* @see {@link https://stackoverflow.com/a/37511463 | StackOverflow source}.
*
*/
export declare function stringCaseBuilder(str: Maybe<string>, transformation?: Maybe<(word: string) => string>, separator?: string, splitter?: RegExp | string): string;
export declare const replaceDiacritics: (str: Maybe<string>) => string;
/**

@@ -57,4 +48,32 @@ * Returns a string pruned on both start and end, similar to `trim()` but with any substring.

*/
export declare function prune(str: Maybe<string>, substr?: string): string;
export declare const prune: (str: Maybe<string>, substr?: string) => string;
/**
* Returns a string after applying a transformation function.
* By default `splitter` expression will split the string into words, where non-alphanum chars are considered as word separators.
* `separator` will be used for joining the words back together.
* {@link prune} using `separator` is applied to the result of the transformation.
*
* @internal
*
* @param str - the string to be transformed.
* @param transformation - optional transformation callback function.
* @param separator - optional character separator for word-based transformation.
* @param splitter - optional regex or string rule for splitting string into word.
*
* @returns a transformed string, or an empty string if `str` is not a valid string.
*
* @example
* ```js
* import { stringCaseBuilder } from "@graphql-markdown/utils/string";
*
* const text = "The quick brown fox jumps over the lazy dog.";
* const transformation = (word: string): string => `*${word}*`
*
* stringCaseBuilder(text, transformation, " ");
* // Expected result: "*The* *quick* *brown* *fox* *jumps* *over* *the* *lazy* *dog*"
* ```
*
*/
export declare const stringCaseBuilder: (str: Maybe<string>, transformation?: Maybe<(word: string) => string>, separator?: string, splitter?: RegExp | string) => string;
/**
* Converts a character to its equivalent HTML unicode representation `&#x0000`.

@@ -76,3 +95,3 @@ *

*/
export declare function toHTMLUnicode(char: Maybe<string>): string;
export declare const toHTMLUnicode: (char: Maybe<string>) => string;
/**

@@ -96,3 +115,3 @@ * Returns a string with MDX special characters converted to HTML unicode using {@link toHTMLUnicode}.

*/
export declare function escapeMDX(str: unknown): string;
export declare const escapeMDX: (str: unknown) => string;
/**

@@ -114,3 +133,3 @@ * Returns a string with the 1st character in uppercase.

*/
export declare function firstUppercase(str: Maybe<string>): string;
export declare const firstUppercase: (str: Maybe<string>) => string;
/**

@@ -131,23 +150,4 @@ * Returns a string in lowercase excepted for the 1st character capitalized using {@link firstUppercase}.

*/
export declare function capitalize(str: Maybe<string>): string;
export declare const capitalize: (str: Maybe<string>) => string;
/**
* Replaces diacritics by non-diacritic equivalent characters.
*
*
* @param str - the string to be transformed.
*
* @returns a string with diacritic characters replaced, or an empty string if `str` is not a valid string.
*
* * @example
* ```js
* import { replaceDiacritics } from "@graphql-markdown/utils/string";
*
* replaceDiacritics("Âéêś"); // Expected result: "Aees"
* ```
*
* @see {@link https://stackoverflow.com/a/37511463 | StackOverflow source}.
*
*/
export declare function replaceDiacritics(str: Maybe<string>): string;
/**
* Applies {@link firstUppercase} using {@link stringCaseBuilder} to every word of a string with `space` character as separator.

@@ -167,3 +167,3 @@ *

*/
export declare function startCase(str: Maybe<string>): string;
export declare const startCase: (str: Maybe<string>) => string;
/**

@@ -186,3 +186,3 @@ * Returns a lowercase string with `-` as replacement for non alphanum characters using {@link stringCaseBuilder}.

*/
export declare function kebabCase(str: Maybe<string>): string;
export declare const kebabCase: (str: Maybe<string>) => string;
/**

@@ -192,2 +192,2 @@ * Alias of {@link kebabCase}.

*/
export declare const slugify: typeof kebabCase;
export declare const slugify: (str: Maybe<string>) => string;

@@ -8,48 +8,31 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
exports.slugify = exports.kebabCase = exports.startCase = exports.replaceDiacritics = exports.capitalize = exports.firstUppercase = exports.escapeMDX = exports.toHTMLUnicode = exports.prune = exports.stringCaseBuilder = void 0;
exports.slugify = exports.kebabCase = exports.startCase = exports.capitalize = exports.firstUppercase = exports.escapeMDX = exports.toHTMLUnicode = exports.stringCaseBuilder = exports.prune = exports.replaceDiacritics = void 0;
/**
* Returns a string after applying a transformation function.
* By default `splitter` expression will split the string into words, where non-alphanum chars are considered as word separators.
* `separator` will be used for joining the words back together.
* {@link prune} using `separator` is applied to the result of the transformation.
* Replaces diacritics by non-diacritic equivalent characters.
*
* @internal
*
* @param str - the string to be transformed.
* @param transformation - optional transformation callback function.
* @param separator - optional character separator for word-based transformation.
* @param splitter - optional regex or string rule for splitting string into word.
*
* @returns a transformed string, or an empty string if `str` is not a valid string.
* @returns a string with diacritic characters replaced, or an empty string if `str` is not a valid string.
*
* @example
* * @example
* ```js
* import { stringCaseBuilder } from "@graphql-markdown/utils/string";
* import { replaceDiacritics } from "@graphql-markdown/utils/string";
*
* const text = "The quick brown fox jumps over the lazy dog.";
* const transformation = (word: string): string => `*${word}*`
*
* stringCaseBuilder(text, transformation, " ");
* // Expected result: "*The* *quick* *brown* *fox* *jumps* *over* *the* *lazy* *dog*"
* replaceDiacritics("Âéêś"); // Expected result: "Aees"
* ```
*
* @see {@link https://stackoverflow.com/a/37511463 | StackOverflow source}.
*
*/
function stringCaseBuilder(str, transformation, separator, splitter = /[^0-9A-Za-z]+/g) {
const replaceDiacritics = (str) => {
if (typeof str !== "string") {
return "";
}
if (typeof transformation !== "function") {
return str;
}
const stringCase = replaceDiacritics(str)
.replace(/([a-z]+|\d+)([A-Z])/g, "$1 $2")
.replace(/([a-z]+)(\d)/g, "$1 $2")
.replace(/(\d+)([a-z])/g, "$1 $2")
.split(splitter)
.filter((word) => word.length > 0)
.map((word) => transformation(word))
.join(separator);
return prune(stringCase, separator);
}
exports.stringCaseBuilder = stringCaseBuilder;
return str
.toString()
.normalize("NFD")
.replace(/[\u0300-\u036f]/g, "");
};
exports.replaceDiacritics = replaceDiacritics;
/**

@@ -76,3 +59,3 @@ * Returns a string pruned on both start and end, similar to `trim()` but with any substring.

*/
function prune(str, substr = "") {
const prune = (str, substr = "") => {
if (typeof str !== "string") {

@@ -88,5 +71,54 @@ return "";

return res;
}
};
exports.prune = prune;
/**
* Returns a string after applying a transformation function.
* By default `splitter` expression will split the string into words, where non-alphanum chars are considered as word separators.
* `separator` will be used for joining the words back together.
* {@link prune} using `separator` is applied to the result of the transformation.
*
* @internal
*
* @param str - the string to be transformed.
* @param transformation - optional transformation callback function.
* @param separator - optional character separator for word-based transformation.
* @param splitter - optional regex or string rule for splitting string into word.
*
* @returns a transformed string, or an empty string if `str` is not a valid string.
*
* @example
* ```js
* import { stringCaseBuilder } from "@graphql-markdown/utils/string";
*
* const text = "The quick brown fox jumps over the lazy dog.";
* const transformation = (word: string): string => `*${word}*`
*
* stringCaseBuilder(text, transformation, " ");
* // Expected result: "*The* *quick* *brown* *fox* *jumps* *over* *the* *lazy* *dog*"
* ```
*
*/
const stringCaseBuilder = (str, transformation, separator, splitter = /[^0-9A-Za-z]+/g) => {
if (typeof str !== "string") {
return "";
}
if (typeof transformation !== "function") {
return str;
}
const stringCase = (0, exports.replaceDiacritics)(str)
.replace(/([a-z]+|\d+)([A-Z])/g, "$1 $2")
.replace(/([a-z]+)(\d)/g, "$1 $2")
.replace(/(\d+)([a-z])/g, "$1 $2")
.split(splitter)
.filter((word) => {
return word.length > 0;
})
.map((word) => {
return transformation(word);
})
.join(separator);
return (0, exports.prune)(stringCase, separator);
};
exports.stringCaseBuilder = stringCaseBuilder;
/**
* Converts a character to its equivalent HTML unicode representation `&#x0000`.

@@ -108,3 +140,3 @@ *

*/
function toHTMLUnicode(char) {
const toHTMLUnicode = (char) => {
if (typeof char !== "string") {

@@ -115,3 +147,3 @@ return "";

return `&#x${unicodeChar.toUpperCase()};`;
}
};
exports.toHTMLUnicode = toHTMLUnicode;

@@ -136,5 +168,5 @@ /**

*/
function escapeMDX(str) {
return `${String(str)}`.replace(/[<>{}]/g, toHTMLUnicode);
}
const escapeMDX = (str) => {
return `${String(str)}`.replace(/[<>{}]/g, exports.toHTMLUnicode);
};
exports.escapeMDX = escapeMDX;

@@ -157,3 +189,3 @@ /**

*/
function firstUppercase(str) {
const firstUppercase = (str) => {
if (typeof str !== "string") {

@@ -165,3 +197,3 @@ return "";

return `${sliceUppercase}${sliceDefaultCase}`;
}
};
exports.firstUppercase = firstUppercase;

@@ -183,38 +215,10 @@ /**

*/
function capitalize(str) {
const capitalize = (str) => {
if (typeof str !== "string") {
return "";
}
return firstUppercase(str.toLowerCase());
}
return (0, exports.firstUppercase)(str.toLowerCase());
};
exports.capitalize = capitalize;
/**
* Replaces diacritics by non-diacritic equivalent characters.
*
*
* @param str - the string to be transformed.
*
* @returns a string with diacritic characters replaced, or an empty string if `str` is not a valid string.
*
* * @example
* ```js
* import { replaceDiacritics } from "@graphql-markdown/utils/string";
*
* replaceDiacritics("Âéêś"); // Expected result: "Aees"
* ```
*
* @see {@link https://stackoverflow.com/a/37511463 | StackOverflow source}.
*
*/
function replaceDiacritics(str) {
if (typeof str !== "string") {
return "";
}
return str
.toString()
.normalize("NFD")
.replace(/[\u0300-\u036f]/g, "");
}
exports.replaceDiacritics = replaceDiacritics;
/**
* Applies {@link firstUppercase} using {@link stringCaseBuilder} to every word of a string with `space` character as separator.

@@ -234,8 +238,5 @@ *

*/
function startCase(str) {
if (typeof str !== "string") {
return "";
}
return stringCaseBuilder(str, firstUppercase, " ");
}
const startCase = (str) => {
return (0, exports.stringCaseBuilder)(str, exports.firstUppercase, " ");
};
exports.startCase = startCase;

@@ -259,8 +260,7 @@ /**

*/
function kebabCase(str) {
if (typeof str !== "string") {
return "";
}
return stringCaseBuilder(str, (word) => word.toLowerCase(), "-");
}
const kebabCase = (str) => {
return (0, exports.stringCaseBuilder)(str, (word) => {
return word.toLowerCase();
}, "-");
};
exports.kebabCase = kebabCase;

@@ -271,2 +271,2 @@ /**

*/
exports.slugify = kebabCase;
exports.slugify = exports.kebabCase;

@@ -8,7 +8,7 @@ {

},
"version": "1.6.0-next.0",
"version": "1.6.0",
"license": "MIT",
"repository": {
"type": "git",
"url": "graphql-markdown/graphql-markdown",
"url": "git+https://github.com/graphql-markdown/graphql-markdown.git",
"directory": "packages/utils"

@@ -63,3 +63,3 @@ },

"devDependencies": {
"@graphql-markdown/types": "^1.0.0-next.0"
"@graphql-markdown/types": "^1.0.0"
},

@@ -66,0 +66,0 @@ "peerDependencies": {

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