Giter Site home page Giter Site logo

zerg000000 / rewrite-edn Goto Github PK

View Code? Open in Web Editor NEW

This project forked from borkdude/rewrite-edn

0.0 1.0 0.0 54 KB

Utility lib on top of rewrite-clj with common operations to update EDN while preserving whitespace and comments.

License: Eclipse Public License 1.0

Clojure 100.00%

rewrite-edn's Introduction

rewrite-edn

Clojars Project bb compatible

Utility lib on top of rewrite-clj with common operations to update EDN while preserving whitespace and comments.

API

See docstrings in the borkdude.rewrite-edn namespace for details.

Currently implemented:

  • parse-string
  • sexpr
  • get
  • keys
  • assoc
  • assoc-in
  • update
  • update-in
  • dissoc
  • map-keys
  • conj

Examples

Given deps.edn:

{:deps {foo {:mvn/version "0.1.0"}
        bar {:mvn/version "0.2.0"}
        ;; here's a comment and the next dep is ignored:
        #_baz #_{:mvn/version "0.3.0"}}}

and this script:

(require '[borkdude.rewrite-edn :as r])

(def edn-string (slurp "deps.edn"))

(def nodes (r/parse-string edn-string))

Add dependency

(println (str (r/assoc-in nodes [:deps 'my-other-dep] {:mvn/version "0.1.2"})))
{:deps {foo {:mvn/version "0.1.0"}
        bar {:mvn/version "0.2.0"}
        ;; here's a comment and the next dep is ignored:
        #_baz #_{:mvn/version "0.3.0"}
        my-other-dep {:mvn/version "0.1.2"}}}

Fully qualify dep symbols

(defn qualify-sym-node [sym-node]
  (let [sym (r/sexpr sym-node)]
    (if (or (not (symbol? sym))
            (qualified-symbol? sym))
      sym-node
      (symbol (str sym) (str sym)))))

(def updated-nodes (r/update nodes :deps #(r/map-keys qualify-sym-node %)))
(println (str updated-nodes))
{:deps {foo/foo {:mvn/version "0.1.0"}
        bar/bar {:mvn/version "0.2.0"}
        ;; here's a comment and the next dep is ignored:
        #_baz #_{:mvn/version "0.3.0"}}}

Also see examples.

License

Copyright © 2021 Michiel Borkent

Distributed under the EPL License, same as Clojure. See LICENSE.

rewrite-edn's People

Contributors

borkdude avatar kwrooijen avatar laurio avatar logseq-cldwalker avatar lread avatar rfhayashi avatar tiensonqin avatar witek avatar zerg000000 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.