Merge pull request #26 from martinlindhe/mustparse

add MustParse(), which returns an UUID or panics
diff --git a/README.md b/README.md
index 21205ea..9d92c11 100644
--- a/README.md
+++ b/README.md
@@ -1,7 +1,3 @@
-**This package is currently in development and the API may not be stable.**
-
-The API will become stable with v1.
-
 # uuid ![build status](https://travis-ci.org/google/uuid.svg?branch=master)
 The uuid package generates and inspects UUIDs based on
 [RFC 4122](http://tools.ietf.org/html/rfc4122)
diff --git a/hash.go b/hash.go
index 4fc5a77..b174616 100644
--- a/hash.go
+++ b/hash.go
@@ -27,7 +27,7 @@
 func NewHash(h hash.Hash, space UUID, data []byte, version int) UUID {
 	h.Reset()
 	h.Write(space[:])
-	h.Write([]byte(data))
+	h.Write(data)
 	s := h.Sum(nil)
 	var uuid UUID
 	copy(uuid[:], s)
diff --git a/marshal.go b/marshal.go
index 84bbc58..7f9e0c6 100644
--- a/marshal.go
+++ b/marshal.go
@@ -15,8 +15,6 @@
 
 // UnmarshalText implements encoding.TextUnmarshaler.
 func (uuid *UUID) UnmarshalText(data []byte) error {
-	// See comment in ParseBytes why we do this.
-	// id, err := ParseBytes(data)
 	id, err := ParseBytes(data)
 	if err == nil {
 		*uuid = id
diff --git a/node.go b/node.go
index f2c2765..3e4e90d 100644
--- a/node.go
+++ b/node.go
@@ -5,16 +5,14 @@
 package uuid
 
 import (
-	"net"
 	"sync"
 )
 
 var (
-	nodeMu     sync.Mutex
-	interfaces []net.Interface // cached list of interfaces
-	ifname     string          // name of interface being used
-	nodeID     [6]byte         // hardware for version 1 UUIDs
-	zeroID     [6]byte         // nodeID with only 0's
+	nodeMu sync.Mutex
+	ifname string  // name of interface being used
+	nodeID [6]byte // hardware for version 1 UUIDs
+	zeroID [6]byte // nodeID with only 0's
 )
 
 // NodeInterface returns the name of the interface from which the NodeID was
@@ -39,20 +37,11 @@
 }
 
 func setNodeInterface(name string) bool {
-	if interfaces == nil {
-		var err error
-		interfaces, err = net.Interfaces()
-		if err != nil && name != "" {
-			return false
-		}
-	}
-
-	for _, ifs := range interfaces {
-		if len(ifs.HardwareAddr) >= 6 && (name == "" || name == ifs.Name) {
-			copy(nodeID[:], ifs.HardwareAddr)
-			ifname = ifs.Name
-			return true
-		}
+	iname, addr := getHardwareInterface(name) // null implementation for js
+	if iname != "" && addr != nil {
+		ifname = iname
+		copy(nodeID[:], addr)
+		return true
 	}
 
 	// We found no interfaces with a valid hardware address.  If name
diff --git a/node_js.go b/node_js.go
new file mode 100644
index 0000000..24b78ed
--- /dev/null
+++ b/node_js.go
@@ -0,0 +1,12 @@
+// Copyright 2017 Google Inc.  All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+// +build js
+
+package uuid
+
+// getHardwareInterface returns nil values for the JS version of the code.
+// This remvoves the "net" dependency, because it is not used in the browser.
+// Using the "net" library inflates the size of the transpiled JS code by 673k bytes.
+func getHardwareInterface(name string) (string, []byte) { return "", nil }
diff --git a/node_net.go b/node_net.go
new file mode 100644
index 0000000..0cbbcdd
--- /dev/null
+++ b/node_net.go
@@ -0,0 +1,33 @@
+// Copyright 2017 Google Inc.  All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+// +build !js
+
+package uuid
+
+import "net"
+
+var interfaces []net.Interface // cached list of interfaces
+
+// getHardwareInterface returns the name and hardware address of interface name.
+// If name is "" then the name and hardware address of one of the system's
+// interfaces is returned.  If no interfaces are found (name does not exist or
+// there are no interfaces) then "", nil is returned.
+//
+// Only addresses of at least 6 bytes are returned.
+func getHardwareInterface(name string) (string, []byte) {
+	if interfaces == nil {
+		var err error
+		interfaces, err = net.Interfaces()
+		if err != nil {
+			return "", nil
+		}
+	}
+	for _, ifs := range interfaces {
+		if len(ifs.HardwareAddr) >= 6 && (name == "" || name == ifs.Name) {
+			return ifs.Name, ifs.HardwareAddr
+		}
+	}
+	return "", nil
+}
diff --git a/seq_test.go b/seq_test.go
index 853a4aa..4f6c549 100644
--- a/seq_test.go
+++ b/seq_test.go
@@ -16,7 +16,7 @@
 
 // TestClockSeqRace tests for a particular race condition of returning two
 // identical Version1 UUIDs.  The duration of 1 minute was chosen as the race
-// condition, before being fixed, nearly always occured in under 30 seconds.
+// condition, before being fixed, nearly always occurred in under 30 seconds.
 func TestClockSeqRace(t *testing.T) {
 	if !*regressions {
 		t.Skip("skipping regression tests")
diff --git a/sql_test.go b/sql_test.go
index 4fbd01b..1803dfd 100644
--- a/sql_test.go
+++ b/sql_test.go
@@ -10,9 +10,9 @@
 )
 
 func TestScan(t *testing.T) {
-	var stringTest string = "f47ac10b-58cc-0372-8567-0e02b2c3d479"
-	var badTypeTest int = 6
-	var invalidTest string = "f47ac10b-58cc-0372-8567-0e02b2c3d4"
+	stringTest := "f47ac10b-58cc-0372-8567-0e02b2c3d479"
+	badTypeTest := 6
+	invalidTest := "f47ac10b-58cc-0372-8567-0e02b2c3d4"
 
 	byteTest := make([]byte, 16)
 	byteTestUUID := Must(Parse(stringTest))
diff --git a/time.go b/time.go
index fd7fe0a..e6ef06c 100644
--- a/time.go
+++ b/time.go
@@ -86,7 +86,7 @@
 	return int(clockSeq & 0x3fff)
 }
 
-// SetClockSeq sets the clock sequence to the lower 14 bits of seq.  Setting to
+// SetClockSequence sets the clock sequence to the lower 14 bits of seq.  Setting to
 // -1 causes a new sequence to be generated.
 func SetClockSequence(seq int) {
 	defer timeMu.Unlock()
@@ -100,9 +100,9 @@
 		randomBits(b[:]) // clock sequence
 		seq = int(b[0])<<8 | int(b[1])
 	}
-	old_seq := clockSeq
+	oldSeq := clockSeq
 	clockSeq = uint16(seq&0x3fff) | 0x8000 // Set our variant
-	if old_seq != clockSeq {
+	if oldSeq != clockSeq {
 		lasttime = 0
 	}
 }
diff --git a/uuid.go b/uuid.go
index cea4241..b8d756d 100644
--- a/uuid.go
+++ b/uuid.go
@@ -58,11 +58,11 @@
 		14, 16,
 		19, 21,
 		24, 26, 28, 30, 32, 34} {
-		if v, ok := xtob(s[x], s[x+1]); !ok {
+		v, ok := xtob(s[x], s[x+1])
+		if !ok {
 			return uuid, errors.New("invalid UUID format")
-		} else {
-			uuid[i] = v
 		}
+		uuid[i] = v
 	}
 	return uuid, nil
 }
@@ -88,11 +88,11 @@
 		14, 16,
 		19, 21,
 		24, 26, 28, 30, 32, 34} {
-		if v, ok := xtob(b[x], b[x+1]); !ok {
+		v, ok := xtob(b[x], b[x+1])
+		if !ok {
 			return uuid, errors.New("invalid UUID format")
-		} else {
-			uuid[i] = v
 		}
+		uuid[i] = v
 	}
 	return uuid, nil
 }
diff --git a/uuid_test.go b/uuid_test.go
index 3ecd8c2..c0a89f4 100644
--- a/uuid_test.go
+++ b/uuid_test.go
@@ -8,6 +8,7 @@
 	"bytes"
 	"fmt"
 	"os"
+	"runtime"
 	"strings"
 	"testing"
 	"time"
@@ -305,7 +306,7 @@
 	case t1 > t2 && q1 == q2:
 		t.Error("time reversed")
 	case t1 < t2 && q1 != q2:
-		t.Error("clock sequence chaned unexpectedly")
+		t.Error("clock sequence changed unexpectedly")
 	}
 }
 
@@ -321,8 +322,10 @@
 	if !SetNodeInterface("") {
 		t.Error("SetNodeInterface failed")
 	}
-	if ni := NodeInterface(); ni == "" {
-		t.Error("NodeInterface returned an empty string")
+	if runtime.GOARCH != "js" {
+		if ni := NodeInterface(); ni == "" {
+			t.Error("NodeInterface returned an empty string")
+		}
 	}
 
 	ni := NodeID()
@@ -347,7 +350,7 @@
 	}
 
 	if ni := NodeInterface(); ni != "user" {
-		t.Errorf("got inteface %q, want %q", ni, "user")
+		t.Errorf("got interface %q, want %q", ni, "user")
 	}
 }
 
@@ -391,8 +394,10 @@
 	nid := []byte{1, 2, 3, 4, 5, 6}
 	SetNodeInterface("")
 	s := NodeInterface()
-	if s == "" || s == "user" {
-		t.Errorf("NodeInterface %q after SetInteface", s)
+	if runtime.GOARCH != "js" {
+		if s == "" || s == "user" {
+			t.Errorf("NodeInterface %q after SetInterface", s)
+		}
 	}
 	node1 := NodeID()
 	if node1 == nil {
@@ -443,7 +448,7 @@
 type badRand struct{}
 
 func (r badRand) Read(buf []byte) (int, error) {
-	for i, _ := range buf {
+	for i := range buf {
 		buf[i] = byte(i)
 	}
 	return len(buf), nil
@@ -454,13 +459,13 @@
 	uuid1 := New()
 	uuid2 := New()
 	if uuid1 != uuid2 {
-		t.Errorf("execpted duplicates, got %q and %q", uuid1, uuid2)
+		t.Errorf("expected duplicates, got %q and %q", uuid1, uuid2)
 	}
 	SetRand(nil)
 	uuid1 = New()
 	uuid2 = New()
 	if uuid1 == uuid2 {
-		t.Errorf("unexecpted duplicates, got %q", uuid1)
+		t.Errorf("unexpected duplicates, got %q", uuid1)
 	}
 }
 
diff --git a/version4.go b/version4.go
index 74c4e6c..84af91c 100644
--- a/version4.go
+++ b/version4.go
@@ -14,7 +14,7 @@
 	return Must(NewRandom())
 }
 
-// NewRandom returns a Random (Version 4) UUID or panics.
+// NewRandom returns a Random (Version 4) UUID.
 //
 // The strength of the UUIDs is based on the strength of the crypto/rand
 // package.