Skip to content

Commit

Permalink
feat(underscore)!: update to v1.13.6 (#470)
Browse files Browse the repository at this point in the history
Update underscore.js to v1.13.6.

BREAKING CHANGE: This changes the behaviour for the following underscore
functions, please see underscore.js documentation for details.
* .template
* .keys
* .after
* .range
* .reduce
* .reduceRight
* .reduceLeft

Fixes #110
  • Loading branch information
stevenh authored Nov 29, 2022
1 parent 4617108 commit 8d121dc
Show file tree
Hide file tree
Showing 13 changed files with 139 additions and 3,568 deletions.
22 changes: 22 additions & 0 deletions underscore/LICENSE.underscorejs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
Copyright (c) 2009-2022 Jeremy Ashkenas, Julian Gonggrijp, and DocumentCloud and Investigative Reporters & Editors

Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
files (the "Software"), to deal in the Software without
restriction, including without limitation the rights to use,
copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following
conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
11 changes: 0 additions & 11 deletions underscore/Makefile

This file was deleted.

52 changes: 4 additions & 48 deletions underscore/README.markdown
Original file line number Diff line number Diff line change
@@ -1,53 +1,9 @@
# underscore
--
import "github.com/robertkrimen/otto/underscore"

Package underscore contains the source for the JavaScript utility-belt library.
[![Reference](https://pkg.go.dev/badge/github.com/robertkrimen/otto/underscore.svg)](https://pkg.go.dev/github.com/robertkrimen/otto/underscore) [![License](https://img.shields.io/badge/MIT-blue.svg)](https://opensource.org/licenses/MIT)

import (
_ "github.com/robertkrimen/otto/underscore"
)
// Every Otto runtime will now include underscore
To update the version of underscore run:

http://underscorejs.org

https://github.com/documentcloud/underscore

By importing this package, you'll automatically load underscore every time you
create a new Otto runtime.

To prevent this behavior, you can do the following:

import (
"github.com/robertkrimen/otto/underscore"
)

func init() {
underscore.Disable()
}

## Usage

#### func Disable

```go
func Disable()
```shell
go generate
```
Disable underscore runtime inclusion.

#### func Enable

```go
func Enable()
```
Enable underscore runtime inclusion.

#### func Source

```go
func Source() string
```
Source returns the underscore source.

--
**godocdown** http://github.com/robertkrimen/godocdown
65 changes: 65 additions & 0 deletions underscore/download.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
//go:build generate

package main

import (
"context"
"flag"
"fmt"
"io"
"log"
"net/http"
"os"
"time"
)

var (
url = flag.String("url", "", "url to read from")
output = flag.String("output", "", "output file to write the result too")
)

func download(url, output string) (err error) {
ctx, cancel := context.WithTimeout(context.Background(), time.Second*10)
defer cancel()

req, err := http.NewRequestWithContext(ctx, http.MethodGet, url, nil)
if err != nil {
return fmt.Errorf("new request failed: %w", err)
}

resp, err := http.DefaultClient.Do(req)
if err != nil {
return fmt.Errorf("request failed: %w", err)
}
defer resp.Body.Close()

var f *os.File
if output != "" {
if f, err = os.Create(output); err != nil {
return fmt.Errorf("create file %q failed: %w", output, err)
}

defer f.Close()
} else {
f = os.Stdout
}

if _, err := io.Copy(f, resp.Body); err != nil {
return fmt.Errorf("body save: %w", err)
}

return nil
}

func main() {
flag.Parse()

switch {
case len(*url) == 0:
log.Fatal("missing required --url parameter")
}

if err := download(*url, *output); err != nil {
log.Fatal(err)
}
}
4 changes: 4 additions & 0 deletions underscore/generate.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package underscore

//go:generate go run download.go --url https://underscorejs.org/underscore-min.js --output underscore-min.js
//go:generate go run download.go --url https://github.com/raw/jashkenas/underscore/master/LICENSE --output LICENSE.underscorejs
3,463 changes: 0 additions & 3,463 deletions underscore/source.go

This file was deleted.

6 changes: 6 additions & 0 deletions underscore/underscore-min.js

Large diffs are not rendered by default.

52 changes: 27 additions & 25 deletions underscore/underscore.go
Original file line number Diff line number Diff line change
@@ -1,33 +1,35 @@
/*
Package underscore contains the source for the JavaScript utility-belt library.
import (
_ "github.com/robertkrimen/otto/underscore"
)
// Every Otto runtime will now include underscore
http://underscorejs.org
https://github.com/documentcloud/underscore
By importing this package, you'll automatically load underscore every time you create a new Otto runtime.
To prevent this behavior, you can do the following:
import (
"github.com/robertkrimen/otto/underscore"
)
func init() {
underscore.Disable()
}
*/
// Package underscore contains the source for the JavaScript utility-belt library.
//
// import (
// _ "github.com/robertkrimen/otto/underscore"
// )
//
// Every Otto runtime will now include [underscore] for more information see the [underscore docs]
//
// By importing this package, you'll automatically load underscore every time you create a new Otto runtime.
//
// To prevent this behavior, you can do the following:
//
// import (
// "github.com/robertkrimen/otto/underscore"
// )
//
// func init() {
// underscore.Disable()
// }
//
// [underscore]: http://underscorejs.org
// [underscore docs]: https://github.com/documentcloud/underscore
package underscore

import (
_ "embed"

"github.com/robertkrimen/otto/registry"
)

//go:embed underscore-min.js
var underscore string
var entry *registry.Entry = registry.Register(Source)

// Enable underscore runtime inclusion.
Expand All @@ -42,5 +44,5 @@ func Disable() {

// Source returns the underscore source.
func Source() string {
return string(underscore())
return underscore
}
2 changes: 1 addition & 1 deletion underscore_arrays_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ func Test_underscore_arrays_15(t *testing.T) {
equal(_.range(0).join(''), '', 'range with 0 as a first argument generates an empty array');
equal(_.range(4).join(' '), '0 1 2 3', 'range with a single positive argument generates an array of elements 0,1,2,...,n-1');
equal(_.range(5, 8).join(' '), '5 6 7', 'range with two arguments a & b, a<b generates an array of elements a,a+1,a+2,...,b-2,b-1');
equal(_.range(8, 5).join(''), '', 'range with two arguments a & b, b<a generates an empty array');
equal(_.range(8, 5).join(' '), '8 7 6', 'range with two arguments a & b, b<a generates an array of elements 8,..6');
equal(_.range(3, 10, 3).join(' '), '3 6 9', 'range with three arguments a & b & c, c < b-a, a < b generates an array of elements a,a+c,a+2c,...,b - (multiplier of a) < c');
equal(_.range(3, 10, 15).join(''), '3', 'range with three arguments a & b & c, c > b-a, a < b generates an array with a single element, equal to a');
equal(_.range(12, 7, -2).join(' '), '12 10 8', 'range with three arguments a & b & c, a > b, c < 0 generates an array of elements a,a-c,a-2c and ends with the number not less than b');
Expand Down
4 changes: 2 additions & 2 deletions underscore_collections_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ func Test_underscore_collections_2(t *testing.T) {
ok(_.reduce(null, function(){}, 138) === 138, 'handles a null (with initial value) properly');
equal(_.reduce([], function(){}, undefined), undefined, 'undefined can be passed as a special case');
raises(function() { _.reduce([], function(){}); }, TypeError, 'throws an error for empty arrays with no initial value');
equal(_.reduce([], function(){}), undefined, 'undefined is the default case');
});
`)
})
Expand Down Expand Up @@ -151,7 +151,7 @@ func Test_underscore_collections_3(t *testing.T) {
ok(_.reduceRight(null, function(){}, 138) === 138, 'handles a null (with initial value) properly');
equal(_.reduceRight([], function(){}, undefined), undefined, 'undefined can be passed as a special case');
raises(function() { _.reduceRight([], function(){}); }, TypeError, 'throws an error for empty arrays with no initial value');
equal(_.reduceRight([], function(){}), undefined, 'undefined for empty array and no initial value');
// Assert that the correct arguments are being passed.
Expand Down
12 changes: 1 addition & 11 deletions underscore_functions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,16 +82,6 @@ func Test_underscore_functions_2(t *testing.T) {
curly.sayHi = moe.sayHi;
equal(curly.getName(), 'name: curly', 'unbound function is bound to current object');
equal(curly.sayHi(), 'hi: moe', 'bound function is still bound to original object');
curly = {name : 'curly'};
moe = {
name : 'moe',
getName : function() { return 'name: ' + this.name; },
sayHi : function() { return 'hi: ' + this.name; }
};
_.bindAll(moe);
curly.sayHi = moe.sayHi;
equal(curly.sayHi(), 'hi: moe', 'calling bindAll with no arguments binds all functions to the object');
});
`)
})
Expand Down Expand Up @@ -201,7 +191,7 @@ func Test_underscore_functions_7(t *testing.T) {
equal(testAfter(5, 5), 1, "after(N) should fire after being called N times");
equal(testAfter(5, 4), 0, "after(N) should not fire unless called N times");
equal(testAfter(0, 0), 1, "after(0) should fire immediately");
equal(testAfter(0, 1), 1, "after(0) should fire immediately");
});
`)
})
Expand Down
10 changes: 5 additions & 5 deletions underscore_objects_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ func Test_underscore_objects_0(t *testing.T) {
// the test above is not safe because it relies on for-in enumeration order
var a = []; a[1] = 0;
equal(_.keys(a).join(', '), '1', 'is not fooled by sparse arrays; see issue #95');
raises(function() { _.keys(null); }, TypeError, 'throws an error for <null> values');
raises(function() { _.keys(void 0); }, TypeError, 'throws an error for <undefined> values');
raises(function() { _.keys(1); }, TypeError, 'throws an error for number primitives');
raises(function() { _.keys('a'); }, TypeError, 'throws an error for string primitives');
raises(function() { _.keys(true); }, TypeError, 'throws an error for boolean primitives');
equal(_.keys(null).join(''), '', 'empty array for <null> values');
equal(_.keys(void 0).join(''), '', 'empty array for <undefined> values');
equal(_.keys(1).join(''), '', 'empty array for number primitives');
equal(_.keys('a').join(''), '', 'empty array for string primitives');
equal(_.keys(true).join(''), '', 'empty array for boolean primitives');
});
`)
})
Expand Down
4 changes: 2 additions & 2 deletions underscore_utility_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ func Test_underscore_utility_11(t *testing.T) {
strictEqual(_.result(obj, 'x'), 'x');
strictEqual(_.result(obj, 'y'), 'x');
strictEqual(_.result(obj, 'z'), undefined);
strictEqual(_.result(null, 'x'), null);
strictEqual(_.result(null, 'x'), undefined);
});
`)
})
Expand All @@ -320,7 +320,7 @@ func Test_underscore_utility_12(t *testing.T) {
test('_.templateSettings.variable', function() {
var s = '<%=data.x%>';
var data = {x: 'x'};
strictEqual(_.template(s, data, {variable: 'data'}), 'x');
strictEqual(_.template(s, {variable: 'data'})(data), 'x');
_.templateSettings.variable = 'data';
strictEqual(_.template(s)(data), 'x');
});
Expand Down

0 comments on commit 8d121dc

Please sign in to comment.