How to use the ejson.addType function in ejson

To help you get started, we’ve selected a few ejson 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 ZevenFang / react-meteor / lib / mongo-id.js View on Github external
MongoID.ObjectID.prototype.typeName = function() {
  return "oid";
};

MongoID.ObjectID.prototype.getTimestamp = function() {
  var self = this;
  return parseInt(self._str.substr(0, 8), 16);
};

MongoID.ObjectID.prototype.valueOf =
  MongoID.ObjectID.prototype.toJSONValue =
    MongoID.ObjectID.prototype.toHexString =
      function () { return this._str; };

EJSON.addType("oid",  function (str) {
  return new MongoID.ObjectID(str);
});

MongoID.idStringify = function (id) {
  if (id instanceof MongoID.ObjectID) {
    return id.valueOf();
  } else if (typeof id === 'string') {
    if (id === "") {
      return id;
    } else if (id.substr(0, 1) === "-" || // escape previously dashed strings
      id.substr(0, 1) === "~" || // escape escaped numbers, true, false
      MongoID._looksLikeObjectID(id) || // escape object-id-form strings
      id.substr(0, 1) === '{') { // escape object-form strings, for maybe implementing later
      return "-" + id;
    } else {
      return id; // other strings go through unchanged.
github inProgress-team / react-native-meteor / lib / mongo-id.js View on Github external
};

MongoID.ObjectID.prototype.typeName = function() {
  return 'oid';
};

MongoID.ObjectID.prototype.getTimestamp = function() {
  var self = this;
  return parseInt(self._str.substr(0, 8), 16);
};

MongoID.ObjectID.prototype.valueOf = MongoID.ObjectID.prototype.toJSONValue = MongoID.ObjectID.prototype.toHexString = function() {
  return this._str;
};

EJSON.addType('oid', function(str) {
  return new MongoID.ObjectID(str);
});

MongoID.idStringify = function(id) {
  if (id instanceof MongoID.ObjectID) {
    return id.valueOf();
  } else if (typeof id === 'string') {
    if (id === '') {
      return id;
    } else if (
      id.substr(0, 1) === '-' || // escape previously dashed strings
      id.substr(0, 1) === '~' || // escape escaped numbers, true, false
      MongoID._looksLikeObjectID(id) || // escape object-id-form strings
      id.substr(0, 1) === '{'
    ) {
      // escape object-form strings, for maybe implementing later
github inProgress-team / react-native-meteor / src / CollectionFS / FSCollection.js View on Github external
import EJSON from 'ejson';

import Collection from '../Collection';
import Data from '../Data';
import setProperties from './setProperties';

if (!EJSON._getTypes()['FS.File']) {
  EJSON.addType('FS.File', function(value) {
    return {
      getFileRecord() {
        const collection =
          Data.db['cfs.' + value.collectionName + '.filerecord'];

        const item = collection && collection.get(value._id);

        if (!item) return value;

        return setProperties(value.collectionName, item);
      },
    };
  });
}

export default function(name) {

ejson

EJSON - Extended and Extensible JSON library from Meteor made compatible for Nodejs and Browserify

MIT
Latest version published 2 years ago

Package Health Score

54 / 100
Full package analysis