2.4.0 • Published 2 years ago

hfs-utilities v2.4.0

Weekly downloads
-
License
ISC
Repository
github
Last release
2 years ago

semantic-release: angular License: ISC Dependabot GitHub Actions Gulp Azure Visual Studio Code TypeScript ESLint Mocha GitHub TS-Standard - Typescript Standard Style Guide

hfs-utilities

Utilities library for Health Fund Solutions Typescript projects.

BlockBlobService examples:

// Import the library
import { BlockBlobService } from 'hfs-utilities'

// Create a new instance of the service. Optionally provide connection string and container name.
const blockBlobService: BlockBlobService = new BlockBlobService('INSERT PRIMARY CONNECTION STRING HERE')
// Reads the blob contents, will attempt to parse to JSON if possible
const blobContents: any = await blockBlobService.read('blobFile.txt', 'containerName')

// Write the blob contents
await blockBlobService.write('blobFile.txt', 'containerName', 'Hello World!')
// Delete the blob
await blockBlobService.delete('blobFile.txt', 'containerName')
// Delete the container
await blockBlobService.deleteContainer('containerName')
// Create the container
await blockBlobService.createContainer('containerName')

// Lists the blobs in the container
const blobs: string[] = await blockBlobService.listBlobs('containerName')
// Checks if the container exists
const containerExists: boolean = await blockBlobService.containerExists('containerName')
// Checks if the blob exists
const blobExists = await blockBlobService.blobExists('blobFile.txt', 'containerName')
// Lists the containers in a storage account
const containers: string[] = await blockBlobService.listContainers()

NOTE: If working within one container, it is more convenient to pass the container name into the constructor right away, and then you do not need to pass it to any of the other methods.

AzureDataTables examples:

// Import the library
import { AzureDataTables } from 'hfs-utilities'

const azureDataTables: AzureDataTables = new AzureDataTables('INSERT PRIMARY CONNECTION STRING HERE', 'tableName')

// toTableRow converts any object to a table row by stringifying it's values
const tableRow: TableRow = azureDataTables.toTableRow({
  primaryKey: 'primaryKey',
  rowKey: 'rowKey',
  data: {
    column1: 'value1',
    column2: ['value2'],
    }
  id: 1
  })

  // isTableRecord checks if the object is a valid table record, i.e. has a partitionKey & rowKey that are strings with
  // length > 0 and all properties are valid data types
   // will return true
  const isTableRecord: boolean = azureDataTables.isTableRecord(tableRow)
   // will return false
  const isNotTableRecord: boolean = azureDataTables.isTableRecord({})

  // returns an array of one or more responses from the azure data tables service
  const response: TableTransactionResponse[] = await azureDataTables.upsert(tableRow)
  console.log(response) // would expect
    // [{
    // status: 202,
    // subResponses: [ [Object], [Object] ],
    // getResponseForEntity: [Function: getResponseForEntity]
    // }]

  // delete a table row
  const response: TableTransactionResponse[] = await azureDataTables.delete(tableRow)

  // create a table row
  const response: TableTransactionResponse[] = await azureDataTables.create(tableRow)
  const results = await azureDataTables.query('SELECT * FROM tableName')
  console.log(results) // would expect
  // [{
  //   etag: `W/"datetime'2022-06-17T13%3A18%3A17.1793353Z'"`,
  //   partitionKey: 'P2',
  //   rowKey: 'R178',
  //   timestamp: '2022-06-17T13:18:17.1793353Z'
  // },
  // {
  //   etag: `W/"datetime'2022-06-17T13%3A18%3A17.2303059Z'"`,
  //   partitionKey: 'P2',
  //   rowKey: 'R179',
  //   timestamp: '2022-06-17T13:18:17.2303059Z'
  // }]

Utilities examples:

// Import the library
import {
  isEmpty,
  isNullOrUndefined,
  isNotNullAndNotUndefined,
  asArray,
  is,
  isEmptyString,
  isNotEmptyString,
  isString,
} from 'hfs-utilities'

// isEmpty checks if the value is empty
const isEmpty: boolean = isEmpty('') // true
const isNotEmpty: boolean = isNotEmpty('test') // false

// isNullOrUndefined checks if the value is null or undefined
const isNullOrUndefined: boolean = isNullOrUndefined(null) // true
const isNotNullOrUndefined: boolean = isNotNullOrUndefined('test') // false

// isNotNullAndNotUndefined checks if the value is not null or undefined
const isNotNullAndNotUndefined: boolean = isNotNullAndNotUndefined('test') // true
const isNullAndNotUndefined: boolean = isNullAndNotUndefined(null) // false

// asArray converts a value to an array if it is not already an array
const asArray: string[] = asArray('test') // returns ['test']
const asArray: string[] = asArray(['test']) // returns ['test']

// is checks if the value is of the specified type
const isString: boolean = is('string', 'string') // true
const isNotString: boolean = is('string', 2) // false

// isEmptyString checks if the value when trimmed is an empty string
const isEmptyString: boolean = isEmptyString('      ') // true
const isNotEmptyString: boolean = isEmptyString('test') // false

// isNotEmptyString checks if the value when trimmed is not an empty string
const isEmptyString: boolean = isNotEmptyString('      ') // false
const isNotEmptyString: boolean = isNotEmptyString('test') // true

// isString checks if the value is a string
const isString: boolean = isString('string') // true
const isNotString: boolean = isString(2) // false

interfaces

import { AzureFunctionSchema } from 'hfs-utilities'
2.4.0

2 years ago

2.3.0

2 years ago

2.2.0

2 years ago

2.1.7

2 years ago

2.1.6

2 years ago

2.1.51

2 years ago

2.1.5

2 years ago

2.1.4

2 years ago

2.1.3

2 years ago

2.1.2

2 years ago

2.1.1

2 years ago

2.1.0

2 years ago

2.0.20

2 years ago

2.0.19

2 years ago

2.0.17

2 years ago

2.0.16

2 years ago

2.0.15

2 years ago

2.0.14

2 years ago

2.0.13

2 years ago

2.0.12

2 years ago

2.0.1111

2 years ago

2.0.111

2 years ago

2.0.11

2 years ago

2.0.1

2 years ago

2.0.0

2 years ago

1.0.9600012

2 years ago

1.0.9600011

2 years ago

1.0.960001

2 years ago

1.0.96

2 years ago

1.0.95

2 years ago

1.0.94

2 years ago

1.0.93

2 years ago

1.0.92

2 years ago

1.0.91

2 years ago

1.0.9

2 years ago

1.0.8

2 years ago

1.0.7

2 years ago

1.0.6

2 years ago

1.0.5

2 years ago

1.0.4

2 years ago

1.0.3

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago