How to use the is-what.isDate 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 / setDefaultValues.cjs.js View on Github external
function convertTimestamps(originVal, targetVal) {
    if (originVal === '%convertTimestamp%') {
        // firestore timestamps
        // @ts-ignore
        if (isWhat.isAnyObject(targetVal) && !isWhat.isObject(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 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 / utils / setDefaultValues.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 / getters.js View on Github external
let res
  box._sync.userId = 'charlie'
  box._conf.sync.fillables = ['body', 'del', 'pathdel']
  box._conf.sync.guard = []
  // prepareForPatch
  res = store.getters['pokemonBox/prepareForPatch'](['1', '2'], {body: 'new', del: Firebase.firestore.FieldValue.delete()})
  t.deepEqual(Object.keys(res), ['1', '2'])
  t.is(res['1'].body, 'new')
  t.is(res['2'].body, 'new')
  t.is(res['1'].del._methodName, 'FieldValue.delete')
  t.is(res['2'].del._methodName, 'FieldValue.delete')
  t.is(res['1'].id, '1')
  t.is(res['2'].id, '2')
  t.is(res['1'].updated_by, 'charlie')
  t.is(res['2'].updated_by, 'charlie')
  t.is(isDate(res['1'].updated_at), true)
  t.is(isDate(res['2'].updated_at), true)
  // prepareForPropDeletion
  res = store.getters['pokemonBox/prepareForPropDeletion']('1.pathdel.a')
  t.is(res['1'].id, '1')
  t.is(res['1']['pathdel.a']._methodName, 'FieldValue.delete')
  t.is(res['1'].updated_by, 'charlie')
  t.is(isDate(res['1'].updated_at), true)
  // deeper delete
  res = store.getters['pokemonBox/prepareForPropDeletion']('1.a.met.de.aba')
  t.is(res['1']['a.met.de.aba']._methodName, 'FieldValue.delete')
  // different fillables & guard
  box._conf.sync.guard = ['updated_at', 'updated_by', 'id']
  res = store.getters['pokemonBox/prepareForPropDeletion']('1.pathdel.a')
  t.is(res['1'].id, '1') // id stays even if it's added to guard
  t.is(res['1']['pathdel.a']._methodName, 'FieldValue.delete')
  t.is(res['1'].updated_by, undefined)
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.esm.js View on Github external
function convertTimestamps(originVal, targetVal) {
    if (originVal === '%convertTimestamp%') {
        // firestore timestamps
        // @ts-ignore
        if (isAnyObject(targetVal) && !isPlainObject(targetVal) && isFunction(targetVal.toDate)) {
            // @ts-ignore
            return targetVal.toDate();
        }
        // strings
        if (isString(targetVal) && isDate(new Date(targetVal))) {
            return new Date(targetVal);
        }
    }
    return targetVal;
}
/**
github mesqueeb / vuex-easy-firestore / dist / 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 / src / utils / setDefaultValues.ts View on Github external
function convertTimestamps (originVal: any, targetVal: any): Date {
  if (originVal === '%convertTimestamp%') {
    // firestore timestamps
    // @ts-ignore
    if (isAnyObject(targetVal) && !isPlainObject(targetVal) && isFunction(targetVal.toDate)) {
      // @ts-ignore
      return targetVal.toDate()
    }
    // strings
    if (isString(targetVal) && isDate(new Date(targetVal))) {
      return new Date(targetVal)
    }
  }
  return targetVal
}
github mesqueeb / vuex-easy-firestore / test / setDefaultValues.js View on Github external
test('my recursive object assign', async t => {
  let res, defaultValues, target
  const nd = new Date()
  defaultValues = {body: 'a'}
  target = {dueDate: nd}
  res = setDefaultValues(target, defaultValues)
  t.true(isDate(res.dueDate))
  t.is(res.body, 'a')
  t.deepEqual(defaultValues, {body: 'a'})
  t.deepEqual(target, {dueDate: nd})

  defaultValues = {
    body: '',
    head: null,
    toes: {big: true},
    fingers: {'12': false}
  }
  target = {body: {}, head: {}, toes: {}, fingers: null}
  res = setDefaultValues(target, defaultValues)
  t.deepEqual(res, {body: {}, head: {}, toes: {big: true}, fingers: null})

  defaultValues = {body: 'a'}
  target = {body: 'b'}
github mesqueeb / vuex-easy-firestore / test / setDefaultValues.js View on Github external
time: 'now',
      newDate,
      very: {
        deep: {prop: false}
      }
    }
  })
  t.deepEqual(target, {
    info: {
      date: 'tomorrow',
      very: {
        deep: {prop: true}
      }
    }
  })
  t.true(isDate(res.info.newDate))

  defaultValues = {
    info: {
      time: {when: 'now'},
      very: {
        deep: {prop: false}
      }
    }
  }
  target = {
    info: {
      time: {},
      very: {whole: 1}
    }
  }
  res = setDefaultValues(target, defaultValues)

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