Generate another string that has the same prefix and length as another one
@param {string} base
@param {number} relation A number from 0 (not equal at all) to 1 (equal strings)
@param {string}
551961
function getSimiliarString(base, relation) {
	var length = Math.round(base.length * relation),
		r = '',
		i, str
	do {
		str = getRandomString(base.length - length)
	} while (str && str[0] === base[length])
	for (i = 0; i < length; i++) {
		r += base[i] // substr(...) seems to be optimized
	}
	return r + str
}
1305239
function baseConforms(source) {
      var props = keys(source);
      return function(object) {
        return baseConformsTo(object, source, props);
      };
    }
943995
function Relations(config) {
    
    var w = config.writer;
    
    $('#'+config.parentId).append('<div id="relations" class="tabWithLayout" style="height: 100% !important;">'+
            '<div id="relation_alter" class="ui-layout-center"><ul class="relationsList"></ul></div>'+
            '<div class="ui-layout-south tabButtons">'+
            '<button type="button">Add Relation</button><button type="button">Remove Relation</button>'+
            '</div>'+
        '</div>');
    $(document.body).append(''+
        '<div id="relationsMenu" class="contextMenu" style="display: none;"><ul>'+
        '<li id="removeRelation"><ins style="background:url(img/cross.png) center center no-repeat;" />Remove Relation</li>'+
        '</ul></div>'
    );
    
    $('#relations div.ui-layout-south button:eq(0)').button().click(function() {
        w.dialogManager.show('triple');
    });
    $('#relations div.ui-layout-south button:eq(1)').button().click(function() {
        var selected = $('#relations ul li.selected');
        if (selected.length == 1) {
            var i = selected.data('index');
            w.triples.splice(i, 1);
            pm.update();
        } else {
            w.dialogManager.show('message', {
                title: 'No Relation Selected',
                msg: 'You must first select a relation to remove.',
                type: 'error'
            });
        }
    });
    
    w.event('loadingDocument').subscribe(function() {
        pm.clear();
    });
    w.event('documentLoaded').subscribe(function() {
        pm.update();
    });
    w.event('schemaLoaded').subscribe(function() {
        pm.update();
    });
    
    /**
     * @lends Relations.prototype
     */
    var pm = {
        currentlySelectedNode: null
    };
    
    pm.layout = $('#relations').layout({
        defaults: {
            resizable: false,
            slidable: false,
            closable: false
        },
        south: {
            size: 'auto',
            spacing_open: 0
        }
    });
    
    /**
     * Update the list of relations.
     */
    pm.update = function() {
        pm.clear();
        
        var relationsString = '';
        
        for (var i = 0; i < w.triples.length; i++) {
            var triple = w.triples[i];
            relationsString += '<li>'+triple.subject.text+' '+triple.predicate.text+' '+triple.object.text+'</li>';
        }
        
        $('#relations ul').html(relationsString);
        
        $('#relations ul li').each(function(index, el) {
            $(this).data('index', index);
        }).click(function() {
            $(this).addClass('selected').siblings().removeClass('selected');
        }).contextMenu('relationsMenu', {
            bindings: {
                'removeRelation': function(r) {
                    var i = $(r).data('index');
                    w.triples.splice(i, 1);
                    pm.update();
                }
            },
            shadow: false,
            menuStyle: {
                backgroundColor: '#FFFFFF',
                border: '1px solid #D4D0C8',
                boxShadow: '1px 1px 2px #CCCCCC',
                padding: '0px',
                width: '105px'
            },
            itemStyle: {
                fontFamily: 'Tahoma,Verdana,Arial,Helvetica',
                fontSize: '11px',
                color: '#000',
                lineHeight: '20px',
                padding: '0px',
                cursor: 'pointer',
                textDecoration: 'none',
                border: 'none'
            },
            itemHoverStyle: {
                color: '#000',
                backgroundColor: '#DBECF3',
                border: 'none'
            }
        });
    };
    
    pm.clear = function() {
        $('#relations ul').empty();
    };
    
    // add to writer
    w.relations = pm;
    
    return pm;
}
1056645
function encodeBound(data, base) {
  var prefix = data.prefix
  var buffer = prefix ? base.encode(prefix, null) : new Buffer([ data.byte ])

  if (data.upper)
    buffer = Buffer.concat([ buffer, new Buffer([ 0xff ]) ])

  return util.encodedBound(data, buffer)
}
1046542
function equal (a, b) {
	return (a.id || stringify(a)) === (b.id || stringify(b))
}
173095
function supersede(target, source, force, deepStringMixin) {
    if (source) {
        eachProp(source, function (value, prop) {
            if (hasProp(target, prop)) {
                if (deepStringMixin && typeof value === 'object' && value && !isArray(value) && !isFunction(value) && !(value instanceof RegExp)) {

                    if (!target[prop]) {
                        target[prop] = {};
                    }
                    supersede(target[prop], value, force, deepStringMixin);
                } else {
                    target[prop] = value;
                }
            }
        });
    }
    return target;
}
674370
function calBase(a, b) {
  const e = Math.E;
  const value = Math.pow(e, Math.log(b) / a); // 使用换底公式求底
  return value;
}
311097
function forOwnDeep(object, callback, prefix) {
    prefix = prefix ? prefix + '.' : '';

    _.forOwn(object, function(value, key) {
        if (_.isString(value)) {
            callback(value, prefix + key);
        } else {
            forOwnDeep(value, callback, prefix + key);
        }
    });
}
339011
function BaseN(options) {

    var self = this;
    var opt = options || {};

    // assert
    if (opt.max && opt.length) {
        throw new Error('cannot specify both max and length');
    }

    // merge in default options
    for (var key in DEFAULT_OPTIONS) {
        if (!opt.hasOwnProperty(key)) {
            opt[key] = DEFAULT_OPTIONS[key];
        }
    }

    /**
     * a string of all allowed characters used for encoding/decoding.
     * @type {String}
     */
    self.characters = opt.characters;

    /**
     * number of unique characters used to encode ids.
     * @type {Number}
     */
    self.base = opt.base || opt.characters.length;

    /**
     * max length of id string.
     * @type {Number}
     */
    self.length = opt.length || self._findLength(opt.max);
}
44770
function leftJoin($relation, $expr = null)
    {
        return $this->join($relation, $expr, Join::LEFT);
    }
61094
function patternFor(self, basename) {
  if (!has(self.__patterns__, basename)) {
    var pattern;

    var extname = path.extname(basename);

    if (has(self.__aliases__, extname) && self.__aliases__[extname].length) {
      basename = path.basename(basename, extname);
      pattern  = escapeRegexp(basename) +
        '(?:' + [ extname ].concat(self.__aliases__[extname]).map(escapeRegexp).join('|') + ')';
    } else {
      pattern  = escapeRegexp(basename);
    }

    pattern += '(?:' + self.__extensions__.map(escapeRegexp).join('|') + ')*';
    self.__patterns__[basename] = new RegExp('^' + pattern + '$');
  }

  return self.__patterns__[basename];
}
959947
function prefixToBase(c)
{
	if (c === CP_b || c === CP_B) {
		/* 0b/0B (binary) */
		return (2);
	} else if (c === CP_o || c === CP_O) {
		/* 0o/0O (octal) */
		return (8);
	} else if (c === CP_t || c === CP_T) {
		/* 0t/0T (decimal) */
		return (10);
	} else if (c === CP_x || c === CP_X) {
		/* 0x/0X (hexadecimal) */
		return (16);
	} else {
		/* Not a meaningful character */
		return (-1);
	}
}
610141
private String formatRelation(Relation relation)
   {
      String result = null;

      if (relation != null)
      {
         StringBuilder sb = new StringBuilder(relation.getTargetTask().getID().toString());

         Duration duration = relation.getLag();
         RelationType type = relation.getType();
         double durationValue = duration.getDuration();

         if ((durationValue != 0) || (type != RelationType.FINISH_START))
         {
            String[] typeNames = LocaleData.getStringArray(m_locale, LocaleData.RELATION_TYPES);
            sb.append(typeNames[type.getValue()]);
         }

         if (durationValue != 0)
         {
            if (durationValue > 0)
            {
               sb.append('+');
            }

            sb.append(formatDuration(duration));
         }

         result = sb.toString();
      }

      m_eventManager.fireRelationWrittenEvent(relation);
      return (result);
   }
484027
function (base, p) {
		var r = "";
		if (p[1] === ":" || p[0] === "/") {
			r = path.normalize(p);
		} else {
			r = path.join(base, p);
		}
		return r;
	}
1075639
function padNumbersToEqualLength(arr) {
  var maxLen = 0;
  var strings = arr.map(function(n) {
    var str = n.toString();
    maxLen = Math.max(maxLen, str.length);
    return str;
  });
  return strings.map(function(s) { return common.padLeft(s, maxLen); });
}
1277395
function prepend(str, prefix) {
    if (!str && str !== 0) {
        str = '';
    } else {
        str = str.toString();
    }
    return prefix + str;
}
45568
function(records) {
    var self = this.chain()
    var relation = self.getInternal('relation')
    var parentRecord = self.getInternal('relation_to')

    if (!records) return self
    if (!Array.isArray(records)) records = [records]

    // build a map to check if existing records were added - via primary key
    const primaryKeys = self.definition.primaryKeys
    const map = {}
    self.forEach(function(record) {
      var mapKey = []
      primaryKeys.forEach(function(key) {
        if (record[key]) mapKey.push(record[key])
      })
      if (mapKey.length > 0) map[mapKey.join('|')] = record
    })

    records.forEach(function(record) {
      var fromKeys = false
      var mapKey = []

      if (record) {
        // check if `records` is a primitive, or an array of primitives with the same amount of elements as our primary keys
        if (
          typeof record !== 'object' ||
          (Array.isArray(record) &&
            record.length === primaryKeys.length &&
            typeof record[0] !== 'object')
        ) {
          // not a record/object... so it must be a primary key!
          if (self.options.polymorph)
            throw new Error('Polymorphic relations need to add a record!')

          var keys = record
          const tmpRecord = {}

          if (!Array.isArray(keys)) keys = [keys]

          primaryKeys.forEach(function(key, index) {
            if (keys[index]) {
              tmpRecord[key] = keys[index]
              mapKey.push(keys[index])
            }
          })

          if (mapKey.length > 0 && map[mapKey.join('|')]) {
            // found a record no update needed, because we only got the id...
            return
          }

          record = tmpRecord
          fromKeys = true
        }

        primaryKeys.forEach(function(key) {
          if (record[key]) mapKey.push(record[key])
        })

        if (mapKey.length > 0 && map[mapKey.join('|')]) {
          // found a record for update!
          map[mapKey.join('|')].set(record)
          return
        }

        const originalInput = record
        // convert object to a record
        if (self.options.polymorph) {
          if (record.model && !(record instanceof record.model))
            throw new Error(
              'Record/Model instance expected in polymorphic relation!'
            )
        } else {
          if (!(record instanceof self.model)) record = self.model.new(record)
        }

        record.__chainedModel = self

        if (fromKeys) {
          record._exists()
        } else {
          if (mapKey.length > 0 && mapKey.length === primaryKeys.length) {
            record._exists()
            if (!(originalInput instanceof self.model)) {
              // set changes. if for example the record is not loaded, but we now have the primary keys. Only the given fields are changes.
              // all fields that are not present in the original input, must not be changed, because we dont now their value.
              Object.keys(originalInput).forEach(function(key) {
                // ignore primary keys
                if (primaryKeys.indexOf(key) === -1) {
                  record.changes[key] = [undefined, originalInput[key]]
                }
              })
            }
          }
        }

        // a new one
        self.push(record)

        if (relation && parentRecord) {
          if (record && typeof relation.add === 'function') {
            relation.add.call(self, parentRecord, record)
          }
        }
      }
    })

    return self
  }