How to use the is-what.isPlainObject function in is-what

To help you get started, we’ve selected a few is-what examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github mesqueeb / vuex-easy-firestore / test / helpers / index.cjs.js View on Github external
return params.map(function (param) {
        if (isWhat.isAnyObject(param) && !isWhat.isPlainObject(param)) {
            // @ts-ignore
            return String(param.constructor.name) + String(param.id);
        }
        return String(param);
    }).join();
}
github mesqueeb / vuex-easy-firestore / test / helpers / index.cjs.js View on Github external
function convertTimestamps(originVal, targetVal) {
    if (originVal === '%convertTimestamp%') {
        // firestore timestamps
        // @ts-ignore
        if (isWhat.isAnyObject(targetVal) && !isWhat.isPlainObject(targetVal) && isWhat.isFunction(targetVal.toDate)) {
            // @ts-ignore
            return targetVal.toDate();
        }
        // strings
        if (isWhat.isString(targetVal) && isWhat.isDate(new Date(targetVal))) {
            return new Date(targetVal);
        }
    }
    return targetVal;
}
/**
github mesqueeb / vuex-easy-firestore / test / helpers / index.cjs.js View on Github external
function isArrayHelper(value) {
    // this is bugged in vuex actions, I DONT KNOW WHY
    // return (
    //   value instanceof ArrayUnion ||
    //   value instanceof ArrayRemove
    // )
    return (isWhat.isAnyObject(value) &&
        !isWhat.isPlainObject(value) &&
        // @ts-ignore
        value.isArrayHelper === true);
}
github mesqueeb / vuex-easy-firestore / dist / index.cjs.js View on Github external
function isArrayHelper(value) {
    // this is bugged in vuex actions, I DONT KNOW WHY
    // return (
    //   value instanceof ArrayUnion ||
    //   value instanceof ArrayRemove
    // )
    return (isWhat.isAnyObject(value) &&
        !isWhat.isPlainObject(value) &&
        // @ts-ignore
        value.isArrayHelper === true);
}
github mesqueeb / vuex-easy-firestore / src / utils / apiHelpers.ts View on Github external
export function grabUntilApiLimit (
  syncStackProp: string,
  count: number,
  maxCount: number,
  state: IPluginState
): any[] {
  let targets = state._sync.syncStack[syncStackProp]
  // Check if there are more than maxCount batch items already
  if (count >= maxCount) {
    // already at maxCount or more, leave items in syncstack, and don't add anything to batch
    targets = []
  } else {
    // Convert to array if targets is an object (eg. updates)
    const targetIsObject = isPlainObject(targets)
    if (targetIsObject) {
      targets = Object.values(targets)
    }
    // Batch supports only until maxCount items
    const grabCount = maxCount - count
    const targetsOK = targets.slice(0, grabCount)
    let targetsLeft = targets.slice(grabCount)
    // Put back the remaining items over maxCount
    if (targetIsObject) {
      targetsLeft = Object.values(targetsLeft)
        .reduce((carry, update: AnyObject) => {
          const id = update.id
          carry[id] = update
          return carry
        }, {})
    }
github mesqueeb / vuex-easy-firestore / test / actionsCollection.js View on Github external
test('store set up', async t => {
  t.true(isPlainObject(box.pokemon))
})
github mesqueeb / vuex-easy-firestore / test / helpers / utils / setDefaultValues.js View on Github external
function setDefaultValues (obj, defaultValues) {
    if (!isWhat.isPlainObject(defaultValues))
        console.error('[vuex-easy-firestore] Trying to merge target:', obj, 'onto a non-object (defaultValues):', defaultValues);
    if (!isWhat.isPlainObject(obj))
        console.error('[vuex-easy-firestore] Trying to merge a non-object:', obj, 'onto the defaultValues:', defaultValues);
    var result = merge({ extensions: [convertTimestamps] }, defaultValues, obj);
    return findAndReplaceAnything.findAndReplace(result, '%convertTimestamp%', null, { onlyPlainObjects: true });
}
github mesqueeb / vuex-easy-firestore / test / helpers / index.cjs.js View on Github external
function getValueFromPayloadPiece(payloadPiece) {
    if (isWhat.isPlainObject(payloadPiece) &&
        !payloadPiece.id &&
        Object.keys(payloadPiece).length === 1 &&
        isWhat.isPlainObject(payloadPiece[Object.keys(payloadPiece)[0]])) {
        return Object.values(payloadPiece)[0];
    }
    return payloadPiece;
}
github mesqueeb / vuex-easy-firestore / dist / index.cjs.js View on Github external
function getId(payloadPiece, conf, path, fullPayload) {
    if (isWhat.isString(payloadPiece))
        return payloadPiece;
    if (isWhat.isPlainObject(payloadPiece)) {
        if ('id' in payloadPiece)
            return payloadPiece.id;
        var keys = Object.keys(payloadPiece);
        if (keys.length === 1)
            return keys[0];
    }
    return '';
}
/**
github mesqueeb / vuex-easy-firestore / dist / index.esm.js View on Github external
objectProps.forEach(function (prop) {
        var _prop = (prop === 'defaultValues')
            ? config.sync[prop]
            : config[prop];
        if (!isPlainObject(_prop))
            errors.push("`" + prop + "` should be an Object, but is not.");
    });
    var stringProps = ['firestorePath', 'firestoreRefType', 'moduleName'];

is-what

JS type check (TypeScript supported) functions like `isPlainObject() isArray()` etc. A simple & small integration.

MIT
Latest version published 6 months ago

Package Health Score

76 / 100
Full package analysis