{"version":3,"file":"sdf-creator.min.js","sources":["../src/index.js"],"sourcesContent":["/**\n * Converts an array of objects containing molfile to a SDF\n * @param {*} molecules\n * @param {object} [options={}] - options to create the SDF\n * @param {boolean} [options.strict=false] - throw errors in no molfile\n * @param {string} [options.molfilePropertyName=\"molfile\"] - contains the name of the property containing the molfile\n * @param {RegExp} [options.filter=/.*\\/] - regular expression containing a filter for the properties to add\n * @param {string} [options.eol='\\n'] - string to use as end-of-line delimiter\n * @returns {object}\n */\n\nexport function create(molecules, options = {}) {\n  let {\n    molfilePropertyName = 'molfile',\n    eol = '\\n',\n    filter = /.*/,\n    strict = false,\n  } = options;\n\n  let emptyMolfile =\n    'empty.mol\\n  Spectrum generator\\n\\n  0  0  0  0  0  0  0  0  0  0999 V2000\\nM  END\\n';\n\n  let start = Date.now();\n  let sdf = createSDF(molecules, filter);\n\n  function normaliseMolfile(molfile) {\n    if (!molfile) {\n      if (strict) throw new Error('Array containing emtpy molfiles');\n      molfile = emptyMolfile;\n    }\n    let molfileEOL = '\\n';\n    if (molfile.includes('\\r\\n')) {\n      molfileEOL = '\\r\\n';\n    } else if (molfile.includes('\\r')) {\n      molfileEOL = '\\r';\n    }\n    let lines = molfile.replace(/[\\r\\n]+$/, '').split(molfileEOL);\n    return lines.join(eol);\n  }\n\n  function createSDF(molecules, filter) {\n    let result = [];\n    for (let i = 0; i < molecules.length; i++) {\n      let molecule = molecules[i];\n      result.push(normaliseMolfile(molecule[molfilePropertyName]));\n      for (let key in molecule) {\n        if (\n          key !== molfilePropertyName &&\n          (!filter || key.match(filter)) &&\n          molecule[key]\n        ) {\n          result.push(`>  <${key}>`, molecule[key] + eol);\n        }\n      }\n      result.push('$$$$');\n    }\n    return result.join(eol);\n  }\n\n  return {\n    time: Date.now() - start,\n    sdf,\n  };\n}\n"],"names":["molecules","options","molfilePropertyName","eol","filter","strict","start","Date","now","sdf","result","i","length","molecule","push","normaliseMolfile","key","match","join","createSDF","molfile","Error","molfileEOL","includes","replace","split","time"],"mappings":"2PAWO,SAAgBA,EAAWC,EAAU,IAC1C,IAAIC,oBACFA,EAAsB,UAASC,IAC/BA,EAAM,KAAIC,OACVA,EAAS,KAAIC,OACbA,GAAS,GACPJ,EAKAK,EAAQC,KAAKC,MACbC,EAiBJ,SAAmBT,EAAWI,GAC5B,IAAIM,EAAS,GACb,IAAK,IAAIC,EAAI,EAAGA,EAAIX,EAAUY,OAAQD,IAAK,CACzC,IAAIE,EAAWb,EAAUW,GACzBD,EAAOI,KAAKC,EAAiBF,EAASX,KACtC,IAAK,IAAIc,KAAOH,EAEZG,IAAQd,GACNE,IAAUY,EAAIC,MAAMb,KACtBS,EAASG,IAETN,EAAOI,KAAK,OAAOE,KAAQH,EAASG,GAAOb,GAG/CO,EAAOI,KAAK,OACd,CACA,OAAOJ,EAAOQ,KAAKf,EACrB,CAlCUgB,CAAUnB,EAAWI,GAE/B,SAASW,EAAiBK,GACxB,IAAKA,EAAS,CACZ,GAAIf,EAAQ,MAAM,IAAIgB,MAAM,mCAC5BD,EARF,sFASA,CACA,IAAIE,EAAa,KAOjB,OANIF,EAAQG,SAAS,QACnBD,EAAa,OACJF,EAAQG,SAAS,QAC1BD,EAAa,MAEHF,EAAQI,QAAQ,WAAY,IAAIC,MAAMH,GACrCJ,KAAKf,EACpB,CAqBA,MAAO,CACLuB,KAAMnB,KAAKC,MAAQF,EACnBG,MAEJ"}