File tree Expand file tree Collapse file tree 3 files changed +68
-1
lines changed
Expand file tree Collapse file tree 3 files changed +68
-1
lines changed Original file line number Diff line number Diff line change 11# conditional-helpers
2- A collection of JS helper functions to be used in conditional logic within projects
2+
3+ A collection of JavaScript helper functions to be used in conditional logic within projects
Original file line number Diff line number Diff line change 1+ export const isArray = ( value ) => Array . isArray ( value ) ;
2+
3+ export const isString = ( value ) => typeof value === "string" ;
4+
5+ export const isFunction = ( value ) => typeof value === "function" ;
6+
7+ export const isObject = ( value ) =>
8+ Object . prototype . toString . call ( value ) === "[object Object]" ;
9+
10+ export const hasLength = ( arg ) => Boolean ( arg && arg . length > 0 ) ;
11+
12+ export const isBoolean = ( value ) => typeof value === "boolean" ;
13+
14+ export const isDate = ( value ) => value instanceof Date && ! isNaN ( value ) ;
15+
16+ export const isNumber = ( value ) => typeof value === "number" ;
17+
18+ export const isObjectEmpty = ( value ) => Object . keys ( value ) . length === 0 ;
19+
20+ export const isStringHasLength = ( value ) => isString ( value ) && hasLength ( value ) ;
21+
22+ export const isStringEmpty = ( value ) => isString ( value ) && ! hasLength ( value ) ;
23+
24+ export const isArrayHasLength = ( value ) => isArray ( value ) && hasLength ( value ) ;
25+
26+ export const isArrayEmpty = ( value ) => isArray ( value ) && ! hasLength ( value ) ;
27+
28+ export const isObjectHasProps = ( value ) =>
29+ isObject ( value ) && ! isObjectEmpty ( value ) ;
30+
31+ export const isBooleanTruthy = ( value ) => isBoolean ( value ) && value ;
32+
33+ export const isBooleanFalsey = ( value ) => isBoolean ( value ) && ! value ;
34+
35+ export const isHTML = ( value ) => {
36+ const htmlRegex = / < [ ^ > ] * > / g;
37+ return htmlRegex . test ( value ) ;
38+ } ;
Original file line number Diff line number Diff line change 1+ {
2+ "name" : " conditional-helpers" ,
3+ "version" : " 1.0.0" ,
4+ "description" : " A collection of JavaScript helper functions to be used in conditional logic within projects" ,
5+ "main" : " index.js" ,
6+ "scripts" : {
7+ "test" : " echo \" Error: no test specified\" && exit 1"
8+ },
9+ "repository" : {
10+ "type" : " git" ,
11+ "url" : " git+https://github.com/garydavisonos/conditional-helpers.git"
12+ },
13+ "keywords" : [
14+ " JS" ,
15+ " javaScript" ,
16+ " helper" ,
17+ " functions" ,
18+ " for" ,
19+ " conditional" ,
20+ " logic"
21+ ],
22+ "author" : " Gary Davison" ,
23+ "license" : " ISC" ,
24+ "bugs" : {
25+ "url" : " https://github.com/garydavisonos/conditional-helpers/issues"
26+ },
27+ "homepage" : " https://github.com/garydavisonos/conditional-helpers#readme"
28+ }
You can’t perform that action at this time.
0 commit comments