How to format neo4j cypher code

Is there a way / website / sublime plugin, etc., to format the encryption code (make it aligned and neat)?

Same as this javascript site, for example: http://jsbeautifier.org/

+4
source share
1 answer

Until I am perfect, this is what I do. (hope others jump in and improve it)

var Cypher = document.body.innerText
Cypher = Cypher.replace(/(?:\s*(OPTIONAL MATCH|MATCH|WHERE|WITH|RETURN|DETACH DELETE|DELETE|UNWIND|CASE)\s*)/gi, function(match) {
  return '\n' + match.toUpperCase() + ' '
});

Cypher = Cypher.replace(/(?:\s*(AND|NOT|DISTINCT)\s*)/gi, function(match) {
  return ' ' + match.toUpperCase().trim() + ' '
});

Cypher = Cypher.replace(/(?:\s*(\w+)\(\s*)/gi, function(match) {
  return ' ' + match.toUpperCase().trim()
});

document.body.innerText = Cypher
match (n), (n)--(m) where n.car=1 and not n.id="rawr" with n.name return collect(n) as cars
Run codeHide result

( JSFiddle version )

+1
source

Source: https://habr.com/ru/post/1655521/


All Articles