0.3.3 • Published 5 years ago

@zionappsupport/core v0.3.3

Weekly downloads
-
License
ISC
Repository
-
Last release
5 years ago

@zionappsupport/core

Helper Methods for Angular, Ionic, NgRx or any TypeScript projects. This library is designed to prevent bugs from null and undefined variables and properties. Key areas of use include, but are not limited to:

  • NgRx selectors
  • Utility functions
npm install @zionappsupport/core --save

Methods

Item

1. Strings

a. Case-Insensitive Equals

Do two strings match with case-insensitivity?

caseInsensitiveEquals: (s1: string, s2: string) => boolean;
b. Case-Insensitive Includes

Find if a substring of a string value exists with case insensitive matching

caseInsensitiveIncludes: (value: string, query: string) => boolean;

2. Objects

a. getPropertyValue

Get a property of an object specifying a default value.

getPropertyValue: (item: any, key: string, defaultValue: any) => any;

b. getBooleanPropertyValue, getNumericPropertyValue, getStringPropertyValue

Get a property of an object expecting a specific type

getBooleanPropertyValue: (item: any, key: string) => boolean;
/ Default is false
getGuidPropertyValue: (item: any, key: string) => string;
// Default is null
getIdPropertyValue: (item: any, key: string) => number;
// Default is null
getNumericPropertyValue: (item: any, key: string) => number;
// Default is 0
getStringPropertyValue: (item: any, key: string) => string; 
// Default is ''
c. isPropertyDefined

Does an object exist and is a specific property truthy?

isPropertyDefined: (item: any, key: string) => boolean;

3. Any Type

a. isItemDefined

Is a variable is falsy?

isItemDefined: (item: any) => boolean;
b. isItemNotDefined

Is a variable truthy?

isItemNotDefined: (item: any) => boolean;

List

1. hasAnyItems

Is your list truthy and does it have any items?

hasAnyItems: (list: any[]) => boolean;

2. hasNoItems

Is your list falsy or does it have no items?

hasNoItems: (list: any[]) => boolean;

3. hasAllItemsInList

Do all ids match the ids of items a list?

hasAllItemsInList: (list: string[], idProperty: string, idValues: any[]) => boolean;

Example

const list = [{ id: 1, name: 'Apples'}, { id: 2, name: 'Oranges')];

console.log(hasAllItemsInList(list, 'id', [1, 2])); // Outputs 'true'
console.log(hasAllItemsInList(list, 'id', [1, 3])); // Outputs 'false'

4. hasAllQueryValuesInList

Do all query strings match as a substring of at least 1 string in a list?

hasAllQueryValuesInList: (list: string[], queries: string[]) => boolean;

Example

const list = ['Apples', 'Oranges'];

console.log(hasAllQueryValuesInList(list, ['Apples'])); // Outputs 'true'
console.log(hasAllQueryValuesInList(list, ['Apples', 'Oranges'])); // Outputs 'false'

5. hasItemInList

Does an id match the ids of at least 1 item a list?

hasItemInList: (list: any[], idProperty: string, idValue: any) => boolean;

Example

const list = [{ id: 1, name: 'Apples'}, { id: 2, name: 'Oranges')];
const list = [{ id: 1, name: 'Apples'}, { id: 2, name: 'Oranges')];

console.log(hasItemInList(list, 'id', 1)); // Outputs 'true'
console.log(hasItemInList(list, 'id', 3)); // Outputs 'false'

6. hasQueryValueInList

Does a query match as a substring of at least 1 string in a list?

hasQueryValueInList: (list: string[], query: string) => boolean;

Example

const list = ['Apples', 'Oranges'];

console.log(hasQueryValueInList(list, 'Apples')); // Outputs 'true'
console.log(hasQueryValueInList(list, 'Pears')); // Outputs 'false'
  • compareKeyFunctionAsc: Sort ascending helper function.
  • compareKeyFunctionDesc: Sort descending helper function.
  • getSortedItemsByKeyAsc: Get a new sorted ascending list by any property.
  • getSortedItemsByKeyDesc: Get a new sorted descending list by any property.
  • sanitizeList: Get a list ensuring if it is null or undefined, it will return an empty array.

Time

  • getISOTimestamp: Get an ISO timestamp string. Format: YYYY-MM-DDTHH:MM:SS.sssZ
0.3.3

5 years ago

0.3.2

5 years ago

0.3.1

5 years ago

0.3.0

5 years ago

0.2.4

6 years ago

0.0.24

6 years ago

0.2.1

6 years ago

0.2.0

6 years ago

0.1.1

6 years ago

0.0.23

6 years ago

0.0.21

6 years ago

0.0.20

6 years ago

0.0.19

6 years ago

0.0.18

6 years ago

0.0.17

6 years ago

0.0.15

6 years ago

0.0.14

6 years ago

0.0.13

6 years ago

0.0.12

6 years ago

0.0.11

6 years ago

0.0.10

6 years ago

0.0.8

6 years ago

0.0.7

6 years ago

0.0.6

6 years ago

0.0.5

6 years ago

0.0.4

6 years ago

0.0.3

6 years ago

0.0.2

6 years ago

0.0.1

6 years ago