From 85d493a0ea0f78b75dc2fd391fce162d6435df84 Mon Sep 17 00:00:00 2001 From: Joe Clark Date: Tue, 28 Jan 2025 12:11:50 +0000 Subject: [PATCH] Fix encode, decode and uuid docs examples (#929) --- packages/common/src/util/base64.js | 18 ++++++++++-------- packages/common/src/util/uuid.js | 6 +++--- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/packages/common/src/util/base64.js b/packages/common/src/util/base64.js index a90ca403b..fd4132a61 100644 --- a/packages/common/src/util/base64.js +++ b/packages/common/src/util/base64.js @@ -6,16 +6,17 @@ import _ from 'lodash'; * @public * @namespace util * @param {string | object} data - The string or object to be encoded. - * @param {object} options - Options. + * @param {object} options - Options + * @param {boolean} [options.parseJson=true] - If false, no attempt will be made to stringiy the data before encoding it. * @returns {string} - The Base64 encoded string. * @example Encode a string - * const encodedString = encode('Hello World'); + * const encodedString = util.encode('Hello World'); * console.log(encoded); // Output: SGVsbG8gV29ybGQ= * @example Encode an object - * const encodedObject = encode({name: 'Jane Doe'}) + * const encodedObject = util.encode({name: 'Jane Doe' }) * console.log(encodedObject); //output eyJuYW1lIjoiSmFuZSBEb2UifQ== * @example To skip the JSON stringification step - * const encodedObject = encode('Hello World', {parseJson: false}) + * const encodedObject = util.encode('Hello World', { parseJson: false }) */ export const encode = (data, options = { parseJson: true }) => { let str = data; @@ -38,14 +39,15 @@ export const encode = (data, options = { parseJson: true }) => { * @namespace util * @param {string} base64Data - The Base64 encoded string. * @param {object} options - Options. + * @param {boolean} [options.parseJson=true] - If false, no attempt will be made to parse the decoded data into a JSON object. * @returns {string | object} - The decoded string or JavaScript Object. * @example Decode a Base64 string - * const decoded = decode('SGVsbG8gV29ybGQ='); + * const decoded = util.decode('SGVsbG8gV29ybGQ='); * @example Decode a Base64 JSON object to a standard JavaScript object - * const decoded = decode('eyJuYW1lIjoiSmFuZSBEb2UifQ=='); - * console.log(decoded); // Output: {name: 'Jane Doe'} + * const decoded = util.decode('eyJuYW1lIjoiSmFuZSBEb2UifQ=='); + * console.log(decoded); // Output: {name: 'Jane Doe' } * @example To skip the JSON stringification step - * const decodedString = decode('Hello World', {parseJson: false}) + * const decodedString = util.decode('Hello World', { parseJson: false }) */ export const decode = (base64Data, options = { parseJson: true }) => { let decodedValue = Buffer.from(base64Data, 'base64').toString('utf-8'); diff --git a/packages/common/src/util/uuid.js b/packages/common/src/util/uuid.js index 779d5639b..68c7ed7ff 100644 --- a/packages/common/src/util/uuid.js +++ b/packages/common/src/util/uuid.js @@ -1,13 +1,13 @@ import { randomUUID } from 'node:crypto'; /** - * Generates a UUID (Universally Unique Identifier). + * Generates a UUID (Universally Unique Identifier) * @function * @public * @namespace util - * @returns {string} - A newly generated UUID. + * @returns {string} - A newly generated UUID * @example Generate a UUID - * const id = uuid(); + * const id = util.uuid(); * console.log(id); // Output:'3f4e254e-8f6f-4f8b-9651-1c1c262cc83f' */ export const uuid = () => randomUUID();