How to use the dottie.set function in dottie

To help you get started, we’ve selected a few dottie 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 ozum / sequelize-pg-generator / node_modules / sequelize / lib / instance.js View on Github external
if (!options.raw && this._customSetters[key]) {
        this._customSetters[key].call(this, value, key);
      } else {
        // Check if we have included models, and if this key matches the include model names/aliases

        if (this.options && this.options.include && this.options.includeNames.indexOf(key) !== -1 && value) {
          // Pass it on to the include handler
          this._setInclude(key, value, options);
          return;
        } else {
          // Bunch of stuff we won't do when its raw
          if (!options.raw) {
            // If attribute is not in model definition, return
            if (!this._isAttribute(key)) {
              if (key.indexOf('.') > -1 && this.Model._isJsonAttribute(key.split('.')[0])) {
                Dottie.set(this.dataValues, key, value);
                this.changed(key, true);
              }
              return;
            }

            // If attempting to set primary key and primary key is already defined, return
            if (this.Model._hasPrimaryKeys && originalValue && this.Model._isPrimaryKey(key)) {
              return;
            }

            // If attempting to set read only attributes, return
            if (!this.isNewRecord && this.Model._hasReadOnlyAttributes && this.Model._isReadOnlyAttribute(key)) {
              return;
            }

            // Convert date fields to real date objects
github sequelize / sequelize / lib / instance.js View on Github external
} else {
      // Check if we have included models, and if this key matches the include model names/aliases

      if (this.$options && this.$options.include && this.$options.includeNames.indexOf(key) !== -1) {
        // Pass it on to the include handler
        this._setInclude(key, value, options);
        return this;
      } else {
        // Bunch of stuff we won't do when its raw
        if (!options.raw) {
          // If attribute is not in model definition, return
          if (!this._isAttribute(key)) {
            if (key.indexOf('.') > -1 && this.Model._isJsonAttribute(key.split('.')[0])) {
              var previousDottieValue = Dottie.get(this.dataValues, key);
              if (!_.isEqual(previousDottieValue, value)) {
                Dottie.set(this.dataValues, key, value);
                this.changed(key.split('.')[0], true);
              }
            }
            return this;
          }

          // If attempting to set primary key and primary key is already defined, return
          if (this.Model._hasPrimaryKeys && originalValue && this.Model._isPrimaryKey(key)) {
            return this;
          }

          // If attempting to set read only attributes, return
          if (!this.isNewRecord && this.Model._hasReadOnlyAttributes && this.Model._isReadOnlyAttribute(key)) {
            return this;
          }
github ozum / sequelize-pg-generator / node_modules / sequelize / lib / dialects / abstract / query-generator.js View on Github external
, outerBinding
        , comparatorMap
        , aliasMap
        , comparator = '='
        , field = options.field || options.model && options.model.rawAttributes && options.model.rawAttributes[key] || options.model && options.model.fieldRawAttributesMap && options.model.fieldRawAttributesMap[key]
        , fieldType = options.type || (field && field.type)
        , tmp;

      if (key && typeof key === 'string' && key.indexOf('.') !== -1 && options.model) {
        if (options.model.rawAttributes[key.split('.')[0]] && options.model.rawAttributes[key.split('.')[0]].type instanceof DataTypes.JSON) {
          field = options.model.rawAttributes[key.split('.')[0]];
          fieldType = field.type;
          tmp = value;
          value = {};

          Dottie.set(value, key.split('.').slice(1), tmp);
          key = key.split('.')[0];
        }
      }

      comparatorMap = {
        $eq: '=',
        $ne: '!=',
        $gte: '>=',
        $gt: '>',
        $lte: '<=',
        $lt: '<',
        $not: 'IS NOT',
        $is: 'IS',
        $like: 'LIKE',
        $notLike: 'NOT LIKE',
        $iLike: 'ILIKE',
github CleverStack / node-seed / lib / utils / magicModule.js View on Github external
listing.forEach(function(filePath) {
      var actualPath = path.join(folderPath, filePath)
        , stats      = fs.statSync(actualPath)
        , dotted
        , fullPath;

      dotted = folderPath.replace(appRoot, '').replace(modulesPath.replace(appRoot, ''), '').split(path.sep);
      if (dotted[dotted.length-1] === '') {
        dotted.pop();
      }
      dotted = dotted.slice(2, dotted.length).join('.');
      
      if (dottie.get(cache, dotted) === undefined) {
        dottie.set(cache, dotted, {});
      }

      if (stats.isFile()) {
        if ((filePath.match(/.+\.js$/g) !== null || filePath.match(/.+\.es6$/g) !== null) && filePath !== 'index.js' && filePath !== 'module.js') {
          filePath = filePath.replace('.js', '').replace('.es6', '');
          fullPath = [dotted, filePath].join('.');

          if (dottie.get(cache, fullPath) === undefined) {
            Object.defineProperty(dottie.get(cache, dotted), filePath, {
              get: function() {
                if (dottie.get(loaded, fullPath) === undefined) {
                  if (debug.enabled) {
                    debug('Loading %s into magic module from %s...', fullPath, actualPath);
                  }

                  dottie.set(loaded, fullPath, require(actualPath));
github zalando / zappr / server / model / Repository.js View on Github external
setJson: function (path, value) {
      if (db.getDialect() === 'postgres') {
        this.set(path, value)
      } else {
        const json = this.get('json')
        dottie.set(json, path.replace('json.', ''), value)
        this.set('json', json)
      }
    }
  },
github CleverStack / node-seed / lib / utils / magicModule.js View on Github external
get: function() {
                if (dottie.get(loaded, fullPath) === undefined) {
                  if (debug.enabled) {
                    debug('Loading %s into magic module from %s...', fullPath, actualPath);
                  }

                  dottie.set(loaded, fullPath, require(actualPath));
                }

                return dottie.get(loaded, fullPath);
              },
              enumerable: true

dottie

Fast and safe nested object access and manipulation in JavaScript

MIT
Latest version published 1 year ago

Package Health Score

70 / 100
Full package analysis

Popular dottie functions

Similar packages