How to use the is-what.isArray 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 / dist / index.esm.js View on Github external
function createObjectFromPath(path, payload, state, conf) {
    var _a;
    // edge cases
    if (path === '*')
        return payload;
    if (!path.includes('.') && !path.includes('/'))
        return _a = {}, _a[path] = payload, _a;
    // start
    var newValue = payload;
    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) {
github mesqueeb / vuex-easy-firestore / dist / index.es.js View on Github external
insertDoc: function insertDoc(_ref5) {
    var state = _ref5.state,
        getters = _ref5.getters,
        commit = _ref5.commit,
        dispatch = _ref5.dispatch;
    var docs = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
    // 0. payload correction (only arrays)
    if (!isArray(docs)) docs = [docs]; // 1. Prepare for patching

    var syncStack = getters.prepareForInsert(docs); // 2. Push to syncStack

    var inserts = state._sync.syncStack.inserts.concat(syncStack);

    state._sync.syncStack.inserts = inserts; // 3. Create or refresh debounce

    return dispatch('handleSyncStackDebounce');
  },
  insertInitialDoc: function insertInitialDoc(_ref6) {
github mesqueeb / vuex-easy-access / dist / index.esm.js View on Github external
function MUTATE_PROP_x_SUBPROP(state, payload, PROP_SUBPROP, conf) {
    if (!isArray(payload))
        payload = [payload];
    var newValue = payload.pop();
    var ids = getIdsFromPayload(payload, conf, PROP_SUBPROP);
    if (!checkIdWildcardRatio(ids, PROP_SUBPROP, conf))
        return;
    var pathWithIds = fillinPathWildcards(ids, PROP_SUBPROP, state, conf);
    return setDeepValue(state, pathWithIds, newValue);
}
// eslint-disable-next-line
github mesqueeb / vuex-easy-firestore / dist / index.esm.js View on Github external
insertDoc: function (_a, payload) {
            var state = _a.state, getters = _a.getters, commit = _a.commit, dispatch = _a.dispatch;
            if (payload === void 0) { payload = []; }
            // 0. payload correction (only arrays)
            var docs = !isArray(payload) ? [payload] : payload;
            // 1. Prepare for patching
            var syncStack = getters.prepareForInsert(docs);
            // 2. Push to syncStack
            var inserts = state._sync.syncStack.inserts.concat(syncStack);
            state._sync.syncStack.inserts = inserts;
            // 3. Create or refresh debounce & pass id to resolve
            var payloadToResolve = isArray(payload)
                ? payload.map(function (doc) { return doc.id; })
                : payload.id;
            return dispatch('handleSyncStackDebounce', payloadToResolve);
        },
        insertInitialDoc: function (_a) {
github mesqueeb / vuex-easy-firestore / test / actions_arrays.js View on Github external
test('store set up', async t => {
  t.true(isPlainObject(box.pokemon))
  t.true(isArray(char.items))
})
github mesqueeb / vuex-easy-access / src / objectDeepValueUtils.js View on Github external
function shiftDeepValue (target, path) {
  const deepRef = getDeepRef(target, path)
  if (!isArray(deepRef)) return
  return deepRef.shift()
}
github mesqueeb / vuex-easy-access / dist / index.cjs.js View on Github external
function checkIdWildcardRatio(ids, path, conf) {
    var match = path.match(/\*/g);
    var idCount = (isWhat.isArray(match))
        ? match.length
        : 0;
    if (ids.length === idCount)
        return true;
    error('mutationSetterPropPathWildcardIdCount', conf);
    return false;
}
/**
github mesqueeb / vuex-easy-firestore / src / module / mutations.ts View on Github external
SET_SYNCCLAUSES (state, {where, orderBy}) {
      if (where && isArray(where)) state._conf.sync.where = where
      if (orderBy && isArray(orderBy)) state._conf.sync.orderBy = orderBy
    },
    SET_USER_ID (state, userId) {
github mesqueeb / vuex-easy-access / dist / index.cjs.js View on Github external
function spliceDeepValue(target, path, index, deleteCount, value) {
    if (index === void 0) { index = 0; }
    if (deleteCount === void 0) { deleteCount = 0; }
    var deepRef = getDeepRef(target, path);
    if (!isWhat.isArray(deepRef))
        return;
    if (value === undefined)
        return deepRef.splice(index, deleteCount);
    return deepRef.splice(index, deleteCount, value);
}
github mesqueeb / vuex-easy-access / src / pathUtils.ts View on Github external
export function spliceDeepValue (
  target: object,
  path: string,
  index: number = 0,
  deleteCount: number = 0,
  value: any
): any[] {
  const deepRef = getDeepRef(target, path)
  if (!isArray(deepRef)) return
  if (value === undefined) return deepRef.splice(index, deleteCount)
  return deepRef.splice(index, deleteCount, value)
}

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

76 / 100
Full package analysis