index.js
function getDocWithDefault(db, id, defaultDoc) {
  return db.get(id).catch(function (err) {
    /* istanbul ignore if */
    if (err.status !== 404) {
      throw err;
    }
    defaultDoc._id = id;
    return db.put(defaultDoc).catch(function (err) {
      /* istanbul ignore if */
      if (err.status !== 409) { // conflict
        throw err;
      }
    }).then(function () {
      return db.get(id);
    });
  });
}
function getDocWithDefault(db, id, defaultDoc) {
  return db.get(id).catch(function (err) {
    /* istanbul ignore if */
    if (err.status !== 404) {
      throw err;
    }
    defaultDoc._id = id;
    return db.put(defaultDoc).catch(function (err) {
      /* istanbul ignore if */
      if (err.status !== 409) { // conflict
        throw err;
      }
    }).then(function () {
      return db.get(id);
    });
  });
}
function getDocWithDefault ( db , id , defaultDoc ) { return db . get ( id ) . catch ( function ( err ) { /* istanbul ignore if */ if ( err . status !== 404 ) { throw err ; } defaultDoc . _id = id ; return db . put ( defaultDoc ) . catch ( function ( err ) { /* istanbul ignore if */ if ( err . status !== 409 ) { // conflict throw err ; } } ) . then ( function ( ) { return db . get ( id ) ; } ) ; } ) ; }
Create the doc if it doesn't exist
Create the doc if it doesn t exist