Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

check-if

Package Overview
Dependencies
Maintainers
1
Versions
18
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

check-if - npm Package Compare versions

Comparing version 0.6.0 to 1.0.0

coverage/clover.xml

10

index.js

@@ -1,7 +0,4 @@

const areInSync = require('./lib/areInSync')
const areInSyncFirestoreTimestamps = require('./lib/areInSyncFirestoreTimestamps')
const containsExactProperties = require('./lib/containsExactProperties')
const containsProperties = require('./lib/containsProperties')
const containsUpdatedProperties = require('./lib/containsUpdatedProperties')
const isDateInMs = require('./lib/isDateInMs')
const isFirestoreId = require('./lib/isFirestoreId')

@@ -11,4 +8,2 @@ const isFirestoreTimestamp = require('./lib/isFirestoreTimestamp')

const isNonEmptyFirestoreDocumentSnapshot = require('./lib/isNonEmptyFirestoreDocumentSnapshot')
const isNonEmptyFirestoreQuerySnapshot = require('./lib/isNonEmptyFirestoreQuerySnapshot')
const isNonEmptyObject = require('./lib/isNonEmptyObject')
const isShortDate = require('./lib/isShortDate')

@@ -18,8 +13,5 @@ const isTrimmedNonEmptyString = require('./lib/isTrimmedNonEmptyString')

module.exports = {
areInSync,
areInSyncFirestoreTimestamps,
containsExactProperties,
containsProperties,
containsUpdatedProperties,
isDateInMs,
isFirestoreId,

@@ -29,6 +21,4 @@ isFirestoreTimestamp,

isNonEmptyFirestoreDocumentSnapshot,
isNonEmptyFirestoreQuerySnapshot,
isNonEmptyObject,
isShortDate,
isTrimmedNonEmptyString
}

14

lib/areInSyncFirestoreTimestamps.js
const _isFirestoreTimestamp = require('./_isFirestoreTimestamp')
module.exports = (localLastUpdated, serverLastUpdated) =>
_isFirestoreTimestamp(localLastUpdated) &&
_isFirestoreTimestamp(serverLastUpdated) &&
localLastUpdated.isEqual(serverLastUpdated)
/**
* Returns false if any of the inputs is not a valid `firebase.firestore.Timestamp` or if the times don't match.
* @param {firebase.firestore.Timestamp} timeA
* @param {firebase.firestore.Timestamp} timeB
* @returns {Boolean}
*/
module.exports = (timeA, timeB) =>
_isFirestoreTimestamp(timeA) &&
_isFirestoreTimestamp(timeB) &&
timeA.isEqual(timeB)
/**
* Returns false if the provided object does not contain exactly theproperties listed in properties.
* @param {object} object
* @param {string[]} properties A list of property names
* Returns false if the properties listed in 'properties' do not match the properties contained in 'object'.
* @param {Object} object
* @param {String[]} properties A list of property names (e.g. ['id', 'data'])
* @returns {Boolean}
*/

@@ -18,3 +19,3 @@ module.exports = (object, properties) => {

for (let propertyName of properties) {
if (object[propertyName] == null) {
if (object[propertyName] === undefined) {
return false

@@ -21,0 +22,0 @@ }

/**
* Returns false if any of the properties in the objectUpdates has the same value in the originalObject. Change validation uses `==` as opposed to `===` and only works for objects that does not contain nested objects.
* @param {object} objectUpdates
* @param {object} originalObject A list of property names
* Returns false if any of the properties in the 'objectUpdates' has the same value in 'originalObject'. Only does a shallow comparison (does not works for objects that does not contain nested objects/properties).
* @param {Object} objectUpdates
* @param {Object} originalObject A list of property names
* @returns {Boolean}
*/
module.exports = (objectUpdates, originalObject) => {
for (let key in objectUpdates) {
if (objectUpdates[key] == originalObject[key]) {
if (objectUpdates[key] === originalObject[key]) {
return false

@@ -10,0 +11,0 @@ }

const _isString = require('./_isString')
/**
* Returns false if not a valid Firestore id (20 characters a-z, A-Z, and 0-9).
* @param {String} id
* @returns {Boolean}
*/
module.exports = id => _isString(id) && /^[A-Za-z0-9]{20}$/.test(id)
const _isFirestoreTimestamp = require('./_isFirestoreTimestamp')
/**
* Returns false if not a valid firebase.firestore.Timestamp (contains 'toDate' and 'toMillis' functions).
* @param {firebase.firestore.Timestamp} timestamp
* @returns {Boolean}
*/
module.exports = timestamp => _isFirestoreTimestamp(timestamp)
const _isObject = require('./_isObject')
/**
* Returns false if 'object' is not of type 'object' or 'object.deleted' or 'object.del' is defined and set to true.
* @param {Object} object
* @returns {Boolean}
*/
module.exports = object => _isObject(object) && !object.deleted && !object.del
const _isObject = require('./_isObject')
module.exports = object =>
_isObject(object) && object.exists !== undefined && object.exists
/**
* Returns false if 'documentSnapshot' is not of type 'object' or 'documentSnapshot.exists' is 'undefined' or 'false'.
* @param {firebase.firestore.DocumentSnapshot} documentSnapshot
* @returns {Boolean}
*/
module.exports = documentSnapshot =>
_isObject(documentSnapshot) &&
documentSnapshot.exists !== undefined &&
documentSnapshot.exists

@@ -5,3 +5,8 @@ const _hasLength = require('./_hasLength')

/**
* Expects a date with the format (YYYY-MM-DD). Returns false if 'value' is not a 'string' with exactly 10 characters or 'value' can not be parsed by 'new Date(value)'.
* @param {String} value
* @returns {Boolean}
*/
module.exports = value =>
_isString(value) && _hasLength(value, 10) && _isDate(value)
const _isString = require('./_isString')
const _isTrimmed = require('./_isTrimmed')
/**
* Returns false if 'value' is not a 'string' or 'value' is not trimmed or 'string' is empty
* @param {String} value
* @returns {Boolean}
*/
module.exports = value => !!value && _isString(value) && _isTrimmed(value)
{
"name": "check-if",
"version": "0.6.0",
"version": "1.0.0",
"description": "Input validation for Apollo Server.",

@@ -10,6 +10,2 @@ "main": "index.js",

"firebase",
"graphql",
"apollo",
"cloud functions",
"apollo-server",
"validate",

@@ -25,6 +21,6 @@ "validation"

"firebase-admin": "^6.0.0",
"jest": "^23.4.2"
"jest": "^23.6.0"
},
"scripts": {
"test": "jest"
"test": "jest --coverage"
},

@@ -31,0 +27,0 @@ "prettier": {

@@ -15,2 +15,4 @@ # check-if

`yarn add check-if`
## Sample

@@ -23,3 +25,3 @@

if (!checkIf.isDateInMs('2043-01-01')) {
if (!checkIf.isShortDate('2043-01-01')) {
// Logic to handle invalid input goes here

@@ -31,13 +33,12 @@ }

| Functions | Description |
| ---------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `areInSync(localLastUpdated, serverLastUpdated)` | Returns false if:</br>- any of the inputs is not a valid Date</br>- The times don't match |
| `containsProperties(object, properties)` | Returns false if any of the property names listed in `properties` are not in `object` |
| `containsUpdatedProperties(objectUpdates, originalObject)` | Returns false if any of the properties in the `objectUpdates` has the same value in `originalObject`. Change validation uses `==` as opposed to `===` and only works for objects that does not contain nested objects. |
| `isDateInMs(value)` | Returns false if:</br>- value is not a number</br>- value can not be parsed by `new Date(value)` |
| `isFirestoreId(id)` | Returns false if:</br>- not a valid Firestore id (20 characters a-z, A-Z, and 0-9) |
| `isFirestoreTimestamp(timestamp)` | Returns false if:</br>- not a valid Firestore Timestamp (contains `toDate` and `toMillis` functions) |
| `isNonDeletedObject(object)` | Returns false if:</br>- `object` is not of type object</br>- `object.deleted` is defined and set to `true` |
| `isNonEmptyObject(object)` | Returns false if:</br>- `object` is not of type object</br>- `object` is empty |
| `isShortDate(value)` | Expects a date with the format (YYYY-MM-DD). Returns false if:</br>- value is not a string with exactly 10 characters</br>- value can not be parsed by `new Date(value)` |
| `isTrimmedNonEmptyString(value)` | Returns false if:</br>- value is not a string</br>- value is not trimmed</br>- string is empty |
| Function | Description |
| ---------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| `areInSyncFirestoreTimestamps(timeA, timeB)` | Returns false if:</br>- any of the inputs is not a valid `firebase.Firestore.Timestamp`</br>- the times don't match |
| `containsExactProperties(object, properties)` | Returns false if the properties listed in `properties` do not match the properties contained in `object`. |
| `containsUpdatedProperties(objectUpdates, originalObject)` | Returns false if any of the properties in the `objectUpdates` has the same value in `originalObject`. Only does a shallow comparison (does not works for objects that does not contain nested objects/properties). |
| `isFirestoreId(id)` | Returns false if:</br>- not a valid Firestore id (20 characters a-z, A-Z, and 0-9) |
| `isFirestoreTimestamp(timestamp)` | Returns false if:</br>- not a valid `firebase.firestore.Timestamp` (contains `toDate` and `toMillis` functions) |
| `isNonDeletedObject(object)` | Returns false if:</br>- `object` is not of type `object`</br>- `object.deleted` or `object.del` is defined and set to `true` |
| `isNonEmptyFirestoreDocumentSnapshot(documentSnapshot)` | Returns false if:</br>- `documentSnapshot` is not of type `object`</br>- `documentSnapshot.exists` is `undefined` or `false` |
| `isShortDate(value)` | Expects a date with the format (YYYY-MM-DD). Returns false if:</br>- value is not a string with exactly 10 characters</br>- value can not be parsed by `new Date(value)` |
| `isTrimmedNonEmptyString(value)` | Returns false if:</br>- value is not a string</br>- value is not trimmed</br>- string is empty |
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc