1.0.7 • Published 1 year ago

codenode-js-library v1.0.7

Weekly downloads
-
License
ISC
Repository
gitlab
Last release
1 year ago

Library for JB Console development

The one-stop solution for handling multiple libraries frequently used in JB projects development.

NPM version CI status NPM

  • Support for v4 google-spreadsheets library
  • Support for google-auth-library based on latest JWT access
  • Support for gDrive library functions - fileUpload to particular folder
  • Support for date functions - addDaysToDate, addMinsToDate, formatDate, differenceInDaysBetweenTwoDates etc.

🌈 Installation - npm i codenode-js-library


Examples

The following examples are meant to give you an idea of just some of the things you can do

IMPORTANT NOTE - To keep the examples concise, I'm calling await at the top level which is not allowed in some older versions of node. If you need to call await in a script at the root level and your environment does not support it, you must instead wrap it in an async function like so:

(async function () {
  await someAsyncFunction();
})();

The Basics

You can use the pre-defined methods in the library as below.

import { addRow } from 'codenode-js-library';

// Initialize the required service account credentials and mandatory details like sheetId, sheetTitle
const cred = "{Google service account credentials}";
const sheetId = "{Google gSheetId}";
const sheetTitle = "Google gSheet title";

// Initialize method specific required params
const rowData = ["row data array to be added in gsheet"];

// Call the required function
(async function () {
	try {
		await addRow(sheetId, cred, sheetTitle, rowData);
	} catch (error) {
		console.log(error);
	}
})();

GDrive File Upload

import { uploadFileToGdriveFolder } from 'codenode-js-library';

// Initialize the required service account credentials
const cred = "{Google service account credentials}";

// Initialize method specific required params
const parentFolderId = "{Google drive folder id in which you want to upload file}";
const fileUrl = "Public file url or file url from Gupshup File Manager";
const fileType = "Specify file type. Ex - image/jpeg, image/png, text/csv etc.";

// Call the required function
(async function () {
	try {
		const resp = await uploadFileToGdriveFolder(cred, parentFolderId, fileUrl, fileType);
		console.log(resp);
	} catch (error) {
		console.log(error);
	}
})();

Date Functions Usage

import { addDaysToDate, formatDate } from 'codenode-js-library';

let date = new Date();

console.log(addDaysToDate(date, 2));
console.log(formatDate(date, 'dd-MM-yyyy HH:mm:ss'));

Contributing

Contributions are welcome, but please follow the existing conventions, use the linter, add relevant tests, and add relevant documentation.

1.0.7

1 year ago

1.0.6

1 year ago

1.0.5

1 year ago

1.0.4

1 year ago

1.0.3

1 year ago

1.0.2

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago