Code Monkey home page Code Monkey logo

cljs-uuid's Introduction

cljs-uuid

Micro clojure and clojurescript portability lib for uuid creation

usage

  • clojars [cljs-uuid "0.0.1"]
  • clojars [cljs-uuid "0.0.2"] : includes equivalent API in clojure for portability
  • clojars [cljs-uuid "0.0.3"] :
  • added make-random to use in place of make-v4 (deprecated).
  • added cljs parsing of #<UUID ...> issue #1
  • clojars [cljs-uuid "0.0.4"] :
  • updated similar to #2
  • uses cljs.core.UUID
  • removed no longer relevant print methods
  • only relevant fn is now make-random

As of version 0.0.2 you can use the lib in clojure as well as cljs. In clj, underneath, java.util.UUID is used.

see: https://github.com/davesann/cljs-uuid/blob/master/test/main.cljs

(ns test.main
  (:require
    [cljs-uuid.core :as uuid]
    [cljs.reader :as reader]))

(defn log [msg x]
  (do (js/console.log (pr-str {:msg msg :data x}))
    x ))

(log "Starting Test" nil)

(let [id1 (uuid/make-random)
      id2 (uuid/make-random)
      id1-str    (str id1)
      id2-str    (str id2)
      id1-pr-str (pr-str id1)
      id1-reread (reader/read-string id1-str)
      ]
  (log "id1 str"    id1-str)
  (log "id1 pr-str" id1-pr-str)
  (log "id2 str"    id2-str)
  (log "(= id1 id1)" (= id1 id1))
  (log "(not= id1 id2)" (not= id1 id2))
  
  (log "(reader/read-string id1-str)" id1-reread)
  (log "(= id1 id1-reread)" (= id1 id1-reread))
  
  (js/console.log id1)
  (js/console.log id1-reread)
  )

TODO

consider use of 'window.crypto.getRandomValues' when available

License

Copyright (C) 2012 Dave Sann

Distributed under the Eclipse Public License, the same as Clojure.

cljs-uuid's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

cljs-uuid's Issues

Wrong number of args (1) passed to UUID

WARNING: Wrong number of args (1) passed to UUID at line 16 file:/Volumes/DataRAID/Users/sean/.m2/repository/cljs-uuid/cljs-uuid/0.0.4/cljs-uuid-0.0.4.jar!/cljs_uuid/core.cljs

I'm using:

[cljs-uuid "0.0.4"]
and
[org.clojure/clojurescript "0.0-3308"]

duplicate UUID - uuid_generate_v4() / make-random

I have a duplicate UUID key while testing for insertion in a db table.

org.postgresql.util.PSQLException: ERROR: duplicate key value violates unique constraint "users_pkey" Detail: Key (id)=(6b540cda-ba85-464e-9c68-72235f1452fa) already exists.

The UUID key above was generated using cljs-uuid.core/make-random. The similar inserted key in the table is the only key in the table. The already inserted UUID was generated with uuid_generate_v4() function from uuid-ossp module in postgresql.

I think this problem problem occurred after upgrading to the latest version of cljs-uuid from an older version of the same library.

Using:
[cljs-uuid "0.0.4"]
Mac OS X 10.6.8

Current version doesn't work with new cljs.core/UUID

Hi Dave,

I needed a random-uuid generator that works with the current clojurescript version.
Your current version didn't work with the updated cljs-version as of 11/27/12...

I took the liberty to copy part of your code to make it work (thanks!):
https://gist.github.com/4159427

As cljs.core/UUID defines a deftype with interface implementations, much of the pr-str and read-string can be left to the cljs.core/UUID implementation.

A random UUID generator for cljs will benefit the cljs-community!

If you will update your version, I'd be happy to use yours in the future.
If not, I will (reluctantly) maintain my version and make it available via github/clojars.

Thank, FrankS.

cljs code should support reading UUIDs printed with pr-str

The Clojure side can read either #<UUID ...> or #uuid "...". The Clojurescript can only read the #uuid "..." syntax.

There should either be a way to print UUIDs on the Clojure side in the cljs-readable syntax OR the Clojurescript side should be able to read both syntaxes.

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.