Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
NPM Packages
js-db
Commits
0d4e11b3
Commit
0d4e11b3
authored
Feb 06, 2020
by
Milan Wikarski
Browse files
Added @creanet/js-type
parent
e1bf84e3
Changes
8
Show whitespace changes
Inline
Side-by-side
package.json
View file @
0d4e11b3
...
...
@@ -19,7 +19,8 @@
"author"
:
"Milan Wikarski,Marcel Odumorek"
,
"license"
:
"
ISC
"
,
"dependencies"
:
{
"
pg
"
:
"
^7.8.2
"
"
pg
"
:
"
^7.8.2
"
,
"
@creanet/js-type
"
:
"
1.0.0
"
},
"devDependencies"
:
{
"
dotenv
"
:
"
^8.2.0
"
...
...
src/mixins/columns.mixin.js
View file @
0d4e11b3
const
is
=
require
(
'
../utils/
type
s
'
);
const
is
=
require
(
'
@creanet/js-
type
'
);
const
ColumnsMixin
=
C
=>
class
ColumnsMixin
extends
C
{
...
...
src/mixins/limit.mixin.js
View file @
0d4e11b3
const
is
=
require
(
'
../utils/
type
s
'
);
const
is
=
require
(
'
@creanet/js-
type
'
);
const
LimitMixin
=
C
=>
class
LimitMixin
extends
C
{
...
...
src/mixins/offset.mixin.js
View file @
0d4e11b3
const
is
=
require
(
'
../utils/
type
s
'
);
const
is
=
require
(
'
@creanet/js-
type
'
);
const
OffsetMixin
=
C
=>
class
OffsetMixin
extends
C
{
...
...
src/mixins/values.mixin.js
View file @
0d4e11b3
const
is
=
require
(
'
../utils/
type
s
'
);
const
is
=
require
(
'
@creanet/js-
type
'
);
const
ValuesMixin
=
C
=>
class
ValuesMixin
extends
C
{
...
...
src/mixins/where.mixin.js
View file @
0d4e11b3
const
is
=
require
(
'
../utils/
type
s
'
);
const
is
=
require
(
'
@creanet/js-
type
'
);
const
WhereMixin
=
C
=>
class
WhereMixin
extends
C
{
...
...
src/utils/case.js
deleted
100644 → 0
View file @
e1bf84e3
const
snake2camel
=
obj
=>
{
if
(
typeof
obj
===
'
string
'
)
{
return
obj
.
split
(
'
_
'
)
.
map
((
word
,
i
)
=>
i
===
0
?
word
.
toLowerCase
()
:
word
.
split
(
''
)
.
map
((
char
,
i
)
=>
i
===
0
?
char
.
toUpperCase
()
:
char
.
toLowerCase
()
)
.
join
(
''
)
)
.
join
(
''
);
}
else
{
Object
.
keys
(
obj
).
forEach
(
key
=>
{
const
camelCase
=
snake2camel
(
key
);
if
(
key
!==
camelCase
)
{
obj
[
camelCase
]
=
obj
[
key
];
delete
obj
[
key
];
}
});
return
obj
;
}
};
exports
.
snake2camel
=
snake2camel
;
src/utils/types.js
deleted
100644 → 0
View file @
e1bf84e3
/**
* Returns `true` if val is a string; `false` otherwise
*
* @param {*} val
* @returns {boolean}
*/
function
isString
(
val
)
{
return
typeof
val
==
'
string
'
;
}
/**
* Returns `true` if val is an array; `false` otherwise
*
* @param {*} val
* @returns {boolean}
*/
function
isArray
(
val
)
{
return
Array
.
isArray
(
val
);
}
/**
* Returns `true` if val is numeric; `false` otherwise
*
* @param {*} val
* @returns {boolean}
*/
function
isNumeric
(
val
)
{
return
!
isNaN
(
Number
(
val
));
}
/**
* Returns `true` is val is instanceof prototype
*
* @param {*} val
* @param {*} prototype
* @returns {Boolean}
*/
function
isInstance
(
val
,
prototype
)
{
return
val
instanceof
prototype
;
}
/**
* Returns `true` is val is Object; `false` otherwise
*
* @param {*} val
* @returns {Boolean}
*/
function
isObject
(
val
)
{
return
isInstance
(
val
,
Object
);
}
const
_is
=
{
string
:
isString
,
array
:
isArray
,
numeric
:
isNumeric
,
instance
:
isInstance
,
object
:
isObject
};
/**
* Checks if value is of one of valid types specified by `types` array.
* valid items in `types` are:
* - `{string}`: type name (eg. 'numeric') - checks type
* - `{Object}`: instance (eg. Regex) - checks instanceof
*
* @param {*} val
* @param {Array.<string|Object>} types
* @returns
*/
function
is
(
val
,
types
)
{
if
(
!
_is
.
array
(
types
))
throw
TypeError
(
'
Types is not an array
'
);
for
(
let
i
=
0
;
i
<
types
.
length
;
i
++
)
{
const
type
=
types
[
i
];
if
(
isString
(
type
))
{
if
(
_is
[
type
](
val
))
{
return
true
;
}
}
else
if
(
isObject
(
type
))
{
if
(
isInstance
(
val
,
type
))
{
return
true
;
}
}
}
return
false
;
}
is
.
string
=
isString
;
is
.
array
=
isArray
;
is
.
numeric
=
isNumeric
;
is
.
instance
=
isInstance
;
is
.
object
=
isObject
;
module
.
exports
=
is
;
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment