helper.ts 820 B

1234567891011121314151617181920
  1. /**
  2. * Copyright (c) 2019 mol* contributors, licensed under MIT, See LICENSE file for more info.
  3. *
  4. * @author Alexander Rose <alexander.rose@weirdbyte.de>
  5. */
  6. export type Import = { save?: string, file?: string }
  7. export function parseImportGet(s: string): Import[] {
  8. // [{'save':hi_ang_Fox_coeffs 'file':templ_attr.cif} {'save':hi_ang_Fox_c0 'file':templ_enum.cif}]
  9. // [{"file":'templ_enum.cif' "save":'H_M_ref'}]
  10. return s.trim().substring(2, s.length - 2).split(/}[ \n\t]*{/g).map(s => {
  11. const save = s.match(/('save'|"save"):([^ \t\n]+)/);
  12. const file = s.match(/('file'|"file"):([^ \t\n]+)/);
  13. return {
  14. save: save ? save[0].substr(7).replace(/['"]/g, '') : undefined,
  15. file: file ? file[0].substr(7).replace(/['"]/g, '') : undefined
  16. };
  17. });
  18. }