Skip to content

Commit

Permalink
Merge pull request #104 from pelias/remove-check-types
Browse files Browse the repository at this point in the history
feat(deps): Remove check-types in favor of lodash
  • Loading branch information
orangejulius authored Jul 19, 2019
2 parents 32089ce + 0910125 commit 9a85233
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 12 deletions.
4 changes: 2 additions & 2 deletions lib/Variable.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@
*always* yield true; regardless of the underlying value; because js.
**/

var check = require('check-types');
const _ = require('lodash');

function Variable(){
this.$ = '';
}

Variable.prototype.set = function( val ){
if( !check.nonEmptyString(val) && !check.number(val) && !check.boolean(val) && !check.array(val) && !check.object(val)){
if( val === '' || val === null || val === undefined ){
throw new Error( 'invalid value, value must be valid js Variable' );
}
this.$ = val;
Expand Down
21 changes: 12 additions & 9 deletions lib/VariableStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@
note: you may inject your own variables when calling the constructor
**/

var check = require('check-types'),
Variable = require('./Variable');
const _ = require('lodash');

const Variable = require('./Variable');

function VariableStore( vars ){
this._vars = {};
if( check.assigned( vars ) ){
if( !_.isEmpty( vars ) ){
this.set( vars );
}
}
Expand All @@ -31,17 +32,19 @@ function VariableStore( vars ){
vs.var('foo').set('bar');
**/
VariableStore.prototype.var = function( key, val ){
if( !check.nonEmptyString( key ) ){
if( _.isEmpty( key ) || !_.isString( key) ) {
throw new Error( 'invalid query variable, key must be valid string' );
}
// init variable
if( !this._vars.hasOwnProperty( key ) ){
this._vars[ key ] = new Variable();
}
// setter
if( check.assigned( val ) ){

// set value if val parameter passed
if (val !== undefined) {
this._vars[ key ].set( val );
}

// getter
return this._vars[ key ];
};
Expand All @@ -50,7 +53,7 @@ VariableStore.prototype.var = function( key, val ){
check if a key has been set (has a value)
**/
VariableStore.prototype.isset = function( key ){
if( !check.nonEmptyString( key ) ){
if( _.isEmpty( key ) || !_.isString( key) ) {
throw new Error( 'invalid key, must be valid string' );
}
// key not set
Expand All @@ -65,7 +68,7 @@ VariableStore.prototype.isset = function( key ){
delete a variable by key
**/
VariableStore.prototype.unset = function( key ){
if( !check.nonEmptyString( key ) ){
if( _.isEmpty( key ) || !_.isString( key) ) {
throw new Error( 'invalid key, must be valid string' );
}
// key not set
Expand All @@ -81,7 +84,7 @@ VariableStore.prototype.unset = function( key ){
import variables from a plain-old-javascript-object
**/
VariableStore.prototype.set = function( pojo ){
if( !check.object( pojo ) ){
if( !_.isPlainObject( pojo ) ){
throw new Error( 'invalid object' );
}
for( var attr in pojo ){
Expand Down
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
},
"homepage": "https://github.com/pelias/query#readme",
"dependencies": {
"check-types": "^8.0.0",
"lodash": "^4.17.14"
},
"devDependencies": {
Expand Down

0 comments on commit 9a85233

Please sign in to comment.