Joi,将空字符串转换为null

时间:2019-12-14 03:59:57

标签: node.js joi

我有以下规则:_RemoteTraceback: ''' Traceback (most recent call last): File "/var/hadoop_vol/adyen_pyspark/venv/lib/python3.5/site-packages/joblib/externals/loky/process_executor.py", line 624, in _queue_management_worker result_item = result_reader.recv() File "/usr/local/python35/lib/python3.5/multiprocessing/connection.py", line 251, in recv return ForkingPickler.loads(buf.getbuffer()) TypeError: __init__() takes 1 positional argument but 2 were given '''

我以为这条规则会将空字符串Joi.string().empty("").default(null)转换为null,但事实并非如此。

如何获得所需的行为?

1 个答案:

答案 0 :(得分:4)

我看不出有什么问题。我从提供的模式中获得了所需的行为:

for x in len(df.columns):
   if 'Client' in df.loc[x,'Columnn']:
      df.loc[x,'Client'] = str(df.loc[x,'Column']).split('Client: ')[1]
      if 'Order Num' in df.loc[x,'Client']:
         df.loc[x,'Client'] = str(df.loc[x,'Client']).split('Order Num: ')[0]
      if 'Account From' in df.loc[x,'Client']:
         df.loc[x,'Client'] = str(df.loc[x,'Client']).split('Account From: ')[0]
      if 'Account to' in df.loc[x,'Client']:
         df.loc[x,'Client'] = str(df.loc[x,'Client']).split('Account to: ')[0]
   else:
      df.loc[x,'Client'] = ''

输出:

const Joi = require('@hapi/joi');

const joiSchema = Joi.string().empty('').default(null);

const { error, value } = joiSchema.validate();
console.log(`error: ${error}`, `value: ${value}`);

确保您使用的是最新版本。在RunKit上检查工作代码:https://runkit.com/rvypandey/5e387545896365001a90a87b