How to use the is-what.isObject 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-access / test / helpers / makeSetters.cjs.js View on Github external
return defaultSetter(MODULE_PROP_SUBPROP + '.splice', payload, store, conf);
                };
            }
            // =================================================>
            //   WILDCARDS SETTER
            // =================================================>
            // if (isObject(propValue) && !Object.keys(propValue).length) {
            //   carry[PROP_SUBPROP + '.*'] = (context, payload) => {
            //     return defaultSetter(MODULE_PROP_SUBPROP + '.*', payload, store, conf)
            //   }
            // }
            // =================================================>
            //   CHILDREN SETTERS
            // =================================================>
            // let's do it's children as well!
            if (isWhat.isObject(propValue) && Object.keys(propValue).length) {
                var childrenSetters = getSetters(propValue, PROP_SUBPROP);
                Object.assign(carry, childrenSetters);
            }
            return carry;
        }, {});
    }
github mesqueeb / vuex-easy-access / dist / index.cjs.js View on Github external
function makeMutationsForAllProps(propParent, path, conf, infoNS) {
    if (!isWhat.isObject(propParent))
        return {};
    return Object.keys(propParent)
        .reduce(function (mutations, prop) {
        // Get the path info up until this point
        var PROP_SUBPROP = (!path)
            ? prop
            : path + '.' + prop;
        // Avoid making setters for private props
        if (conf.ignorePrivateProps && prop[0] === '_')
            return mutations;
        if (conf.ignoreProps.some(function (ignPropFull) {
            var separatePropFromNS = /(.*?)\/([^\/]*?)$/.exec(ignPropFull);
            var ignPropNS = (separatePropFromNS) ? separatePropFromNS[1] + '/' : '';
            var ignProp = (separatePropFromNS) ? separatePropFromNS[2] : ignPropFull;
            return ((!infoNS && ignProp === PROP_SUBPROP) ||
                (infoNS && infoNS.moduleNamespace === ignPropNS && ignProp === PROP_SUBPROP));
github mesqueeb / vuex-easy-access / dist / index.es.js View on Github external
if (path.includes('*')) {
    // only work with arrays
    if (!isArray(payload)) payload = [payload];
    var lastPayloadPiece = payload.pop();
    var ids = payload; // CASE: 'dex/pokemonById.*.tags'

    if (!path.endsWith('*')) {
      newValue = lastPayloadPiece;
    } // CASE: 'dex/pokemonById.*.tags.*'


    if (path.endsWith('*')) {
      var lastId = getId(lastPayloadPiece, conf, path);
      ids.push(lastId);
      newValue = getValueFromPayloadPiece(lastPayloadPiece);
      if (isObject(newValue)) newValue.id = lastId;
    }

    ids = ids.map(function (_id) {
      _id = _id.replace('.', '_____dot_____');
      _id = _id.replace('/', '_____slash_____');
      return _id;
    });
    if (!checkIdWildcardRatio(ids, path, conf)) return;
    var pathWithIds = fillinPathWildcards(ids, path, state, conf);
    path = pathWithIds;
  } // important to set the result here and not return the reduce directly!


  var result = {};
  path.match(/[^\/^\.]+/g).reduce(function (carry, _prop, index, array) {
    _prop = _prop.replace('_____dot_____', '.');
github mesqueeb / vuex-easy-access / dist / index.es.js View on Github external
function makeMutationsForAllProps(propParent, path) {
  var conf = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
  var infoNS = arguments.length > 3 ? arguments[3] : undefined;
  conf = Object.assign({}, defaultConfig, conf);
  if (!isObject(propParent)) return {};
  return Object.keys(propParent).reduce(function (mutations, prop) {
    // Get the path info up until this point
    var PROP_SUBPROP = !path ? prop : path + '.' + prop; // Avoid making setters for private props

    if (conf.ignorePrivateProps && prop[0] === '_') return mutations;

    if (conf.ignoreProps.some(function (ignPropFull) {
      var separatePropFromNS = /(.*?)\/([^\/]*?)$/.exec(ignPropFull);
      var ignPropNS = separatePropFromNS ? separatePropFromNS[1] + '/' : '';
      var ignProp = separatePropFromNS ? separatePropFromNS[2] : ignPropFull;
      return !infoNS && ignProp === PROP_SUBPROP || infoNS && infoNS.moduleNamespace === ignPropNS && ignProp === PROP_SUBPROP;
    })) {
      return mutations;
    } // Get the value of the prop
github mesqueeb / vuex-easy-firestore / dist / index.es.js View on Github external
function convertTimestamps(originVal, targetVal) {
  if (originVal === '%convertTimestamp%') {
    // firestore timestamps
    if (isObject(targetVal) && isFunction(targetVal.toDate)) {
      return targetVal.toDate();
    } // strings


    if (isString(targetVal) && isDate(new Date(targetVal))) {
      return new Date(targetVal);
    }
  }

  return targetVal;
}
/**
github mesqueeb / vuex-easy-firestore / dist / index.es.js View on Github external
function checkFillables (obj) {
  var fillables = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
  var guard = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : [];
  if (!isObject(obj)) return obj;
  return Object.keys(obj).reduce(function (carry, key) {
    // check fillables
    if (fillables.length && !fillables.includes(key)) {
      return carry;
    } // check guard


    guard.push('_conf');
    guard.push('_sync');

    if (guard.includes(key)) {
      return carry;
    }

    carry[key] = obj[key];
    return carry;
github mesqueeb / vuex-easy-access / test / helpers / makeSetters.cjs.js View on Github external
function getId(payloadPiece, conf, path, fullPayload) {
    if (isWhat.isObject(payloadPiece)) {
        if ('id' in payloadPiece)
            return payloadPiece.id;
        if (Object.keys(payloadPiece).length === 1)
            return Object.keys(payloadPiece)[0];
    }
    if (isWhat.isString(payloadPiece))
        return payloadPiece;
    error('wildcardFormatWrong', conf, path);
    return '';
}
/**
github mesqueeb / vuex-easy-access / src / pathUtils.ts View on Github external
export function getValueFromPayloadPiece (payloadPiece: object | string): any {
  if (
    isObject(payloadPiece) &&
    !('id' in payloadPiece) &&
    Object.keys(payloadPiece).length === 1
  ) {
    return Object.values(payloadPiece)[0]
  }
  return payloadPiece
}
github mesqueeb / vuex-easy-access / src / pathUtils.ts View on Github external
function getId (
  payloadPiece: object | ({ id: string } & object) | string,
  conf?: object,
  path?: string,
  fullPayload?: any[] | object | string
): string {
  if (isObject(payloadPiece)) {
    if ('id' in payloadPiece) return payloadPiece.id
    if (Object.keys(payloadPiece).length === 1) return Object.keys(payloadPiece)[0]
  }
  if (isString(payloadPiece)) return payloadPiece
  error('wildcardFormatWrong', conf, path)
  return ''
}
github mesqueeb / vuex-easy-access / dist / index.es.js View on Github external
function getId(payloadPiece, conf, path, fullPayload) {
  if (isObject(payloadPiece)) {
    if (payloadPiece.id) return payloadPiece.id;
    if (Object.keys(payloadPiece).length === 1) return Object.keys(payloadPiece)[0];
  }

  if (isString(payloadPiece)) return payloadPiece;
  error('wildcardFormatWrong', conf, path, payloadPiece);
  return false;
}
/**

is-what

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

MIT
Latest version published 7 months ago

Package Health Score

78 / 100
Full package analysis