Helper that transforms input values to acceptable defaults for database columns.
359978
function _transformToSafeValue(input, column){
  var out = input;
  var datatype = column.sql_type;
  var nullable = column.nullable;
  if( input === '' ){
    //empty string.
    if(datatype==='datetime'|| datatype==='timestamp' ||_.startsWith(datatype, 'int') || _.startsWith(datatype, 'num') || _.startsWith(datatype, 'dec')){
      if(nullable){
        out = null;
      } else {
        throw new Error(column.column + ' is not permitted to be empty.')
      }
    }

  } else if( !_.isNil(input) ) {
    //not null, not undefined
    if(datatype==='datetime'|| datatype==='timestamp'){
      out = moment(input).format('YYYY-MM-DD HH:mm:ss');
    }
  }
  return out;
}
766945
def normalize_field(field)
      default_value = if field.default?
                        { default: field.default }
                      else
                        {}
                      end
      super.merge(default_value)
    end
602384
def standardize_input_data(data):
    
    if type(data) == bytes:
        data = data.decode('utf-8')
    if type(data) == list:
        data = [
            el.decode('utf-8') if type(data) == bytes else el
            for el in data
        ]
    return data
1267692
function convertRawBoolean(rawColumnValue, column, context)
{
  var ret;

  if ((rawColumnValue === '1') || (rawColumnValue === 'TRUE'))
  {
    ret = true;
  }
  else if ((rawColumnValue === '0') || (rawColumnValue === 'FALSE'))
  {
    ret = false;
  }

  return ret;
}
963065
def transform(self, col):
        
        out = pd.DataFrame(index=col.index)
        out[self.col_name] = col.fillna(self.default_value)
        out[self.new_name] = (pd.notnull(col) * 1).astype(int)
        return out
576533
def _normalize_utf8_keys(kwargs):
  """"""
  if any(type(key) is binary_type for key in kwargs.keys()):
    # This is to preserve the original dict type for kwargs.
    dict_type = type(kwargs)
    return dict_type([(text_type(k), v) for k, v in kwargs.items()])
  return kwargs
1353556
def _normalize_entity(value):
  """"""
  if ndb is not None and isinstance(value, ndb.Model):
    return None
  if getattr(value, "_populate_internal_entity", None):
    return value._populate_internal_entity()
  return value
86818
def to_simple(self, value, **options):  # nolint
        "  "

        # (string, unicode)
        if isinstance(value, basestring):
            return smart_unicode(value)

        # (int, long, float, real, complex, decimal)
        if isinstance(value, Number):
            return float(str(value)) if isinstance(value, Decimal) else value

        # (datetime, data, time)
        if isinstance(value, (datetime, date, time)):
            return self.to_simple_datetime(value)

        # (dict, ordereddict, mutable mapping)
        if isinstance(value, collections.MutableMapping):
            return dict(
                (k, self.to_simple(v, **options)) for k, v in value.items())

        # (tuple, list, set, iterators)
        if isinstance(value, collections.Iterable):
            return [self.to_simple(o, **options) for o in value]

        # (None, True, False)
        if value is None or value is True or value is False:
            return value

        if hasattr(value, 'to_simple') and not inspect.isclass(value):
            return self.to_simple(value.to_simple(self), **options)

        if isinstance(value, Model):
            return self.to_simple_model(value, **options)

        return str(value)
74219
def transform_arguments(arguments, prev_values, inputs)
      arguments = arguments.replace_values_from_previous(prev_values)
      arguments.each do |arg_name, arg_values|
        arguments[arg_name] = {} unless arguments[arg_name].is_a?(Hash)
        arguments[arg_name]['value'] = ''
        if inputs.key?(arg_name)
          arguments[arg_name]['value'] = inputs[arg_name]
        elsif arg_values.is_a?(Hash) && arg_values.key?('default')
          arguments[arg_name]['value'] = arg_values['default']
        end
      end
    end
1131047
def _parse_columns(self):
    
        '''  '''
        
    # construct column list
        column_map = {}
        for key, value in self.model.keyMap.items():
            record_key = key[1:]
            if record_key:
                if self.item_key.findall(record_key):
                    pass
                else:
                    if value['value_datatype'] == 'map':
                        continue
                    datatype = value['value_datatype']
                    if value['value_datatype'] == 'number':
                        datatype = 'float'
                        if 'integer_data' in value.keys():
                            if value['integer_data']:
                                datatype = 'integer'
                    replace_key = ''
                    if 'field_metadata' in value.keys():
                        if 'replace_key' in value['field_metadata'].keys():
                            if isinstance(value['field_metadata']['replace_key'], str):
                                replace_key = value['field_metadata']['replace_key']
                    max_length = None
                    if 'max_length' in value.keys():
                        max_length = value['max_length']
                    column_map[record_key] = (record_key, datatype, replace_key, max_length)
        
        return column_map
906509
function standardizeCols(columns) {

	/**
	 * Gets the default column name
	 */
	function getDefaultFormatter(colName) {
		return function(o) {
			return o[colName];
		};
	}

	/**
	 * Gets the default column sorter
	 */
	function getDefaultSorter(colName) {
		return function(a, b, dir){

			var 
				firstRec = dir == 'asc' ? a : b,
				secondRec = dir == 'asc' ? b : a,

				fA = firstRec[colName].toLowerCase(),
				fB = secondRec[colName].toLowerCase();

			// Handle numbers
			if (fA<fB) return -1
			if (fA>fB) return +1
			return 0
		};
	}


	for (var i in columns) {
		var column = columns[i];

		if (typeof column == "string") {
			column = {name: column};
		}

		column.dir = column.sortDir || 'asc';
		column.formatter = column.formatter || getDefaultFormatter(column.key || column.name);
		column.sorter = column.sorter || getDefaultSorter(column.key || column.name);

		columns[i] = column;
	}
	return columns;
}
1090996
function () {
            var values = this.__opts.values, ret = [];
            if (isArray(values)) {
                ret.push(values.length === 0 ? " DEFAULT VALUES" : " VALUES " + this.literal(values));
            } else if (isInstanceOf(values, Dataset)) {
                ret.push(" " + this._subselectSql(values));
            } else if (isInstanceOf(values, LiteralString)) {
                ret.push(" " + values.toString(this));
            } else {
                throw new QueryError("Unsupported INSERT values type, should be an array or dataset");
            }
            return ret.join("");
        }
665016
def normalize(s, replace_spaces=True):
    
    whitelist = (' -' + string.ascii_letters + string.digits)

    if type(s) == six.binary_type:
        s = six.text_type(s, 'utf-8', 'ignore')

    table = {}
    for ch in [ch for ch in s if ch not in whitelist]:
        if ch not in table:
            try:
                replacement = unicodedata.normalize('NFKD', ch)[0]
                if replacement in whitelist:
                    table[ord(ch)] = replacement
                else:
                    table[ord(ch)] = u'_'
            except:
                table[ord(ch)] = u'_'

    if replace_spaces:
        return s.translate(table).replace(u'_', u'').replace(' ', '_')
    else:
        return s.translate(table).replace(u'_', u'')
272041
def normalize_params(params):
    """"""
    # Collect a set of all fields
    fields = set()
    for p in params:
        fields.update(p)
    fields = sorted(fields)

    params2 = list(pluck(fields, params, MISSING))
    # Non-basic types (including MISSING) are unique to their id
    tokens = [
        tuple(x if isinstance(x, (int, float, str)) else id(x) for x in p)
        for p in params2
    ]

    return fields, tokens, params2
174749
def normalize_value(values)
      Array.wrap(values).map do |value|
        value.is_a?(String) ? value.gsub("\n", "") : value
      end
    end
1324278
def converts_values(self):
        """"""
        return self.convert_value is not Formatter.convert_value or \
               self.convert_column is not Formatter.convert_column
390935
def _normalize_key(value):
  """"""
  if ndb is not None and isinstance(value, (ndb.Model, ndb.Key)):
    return None
  if getattr(value, "key", None):
    return value.key()
  elif isinstance(value, basestring):
    return datastore.Key(value)
  else:
    return value