[Class] biga.ahk (166 utility methods)

Post your working scripts, libraries and tools for AHK v1.1 and older
User avatar
Chunjee
Posts: 1400
Joined: 18 Apr 2014, 19:05
Contact:

Re: [Class] biga.ahk (utilities mirroring Lodash)

Post by Chunjee » 05 Nov 2019, 16:22

v0.13.0 is now available on npm and github. .pick (docs)

Code: Select all

A := new biga()
object := {"a": 1, "b": "2", "c": 3}
A.pick(object, ["a", "c"])
; => {"a": 1, "c": 3}

User avatar
Chunjee
Posts: 1400
Joined: 18 Apr 2014, 19:05
Contact:

Re: [Class] biga.ahk (utilities mirroring Lodash)

Post by Chunjee » 13 Nov 2019, 06:46

0.14.0 is now on npm. Added some math and number methods.

.clamp Clamps number within the inclusive lower and upper bounds. (docs)

Code: Select all

A.clamp(10, -5, 5)
; => 5

.inRange Checks if n is between start and up to, but not including, end. (docs)

Code: Select all

A.inRange(4, 0, 8)
; => true

A.inRange(4, 0, 2)
; => false

.random Produces a random number between the inclusive lower and upper bounds. (docs)

Code: Select all

A.random(0, 5)
; => an integer between 0 and 5

A.random(5)
; => an integer between 0 and 5

A.random(1.2, 5.2)
; => a floating-point number between 1.2 and 5.2

Helgef
Posts: 4709
Joined: 17 Jul 2016, 01:02
Contact:

Re: [Class] biga.ahk (utilities mirroring Lodash)

Post by Helgef » 13 Nov 2019, 09:35

Well done, great documentation :clap: .

Thanks for sharing, cheers.

Edit, you don't need to force an expression for return statements, eg, you can omit the % in return % -1 + 0.

User avatar
Chunjee
Posts: 1400
Joined: 18 Apr 2014, 19:05
Contact:

Re: [Class] biga.ahk (utilities mirroring Lodash)

Post by Chunjee » 13 Nov 2019, 10:22

Hmm you're right. I've removed them all.

docsify made the documentation really easy and looks great out of the box. Highly recommended.

User avatar
Chunjee
Posts: 1400
Joined: 18 Apr 2014, 19:05
Contact:

Re: [Class] biga.ahk (utilities mirroring Lodash)

Post by Chunjee » 20 Nov 2019, 09:44

found a bunch of bugs with .shuffle, .sample, .sampleSize, and .uniq when using arrays with keys that are not incremental. Fixed in v0.18.1


ardent246
Posts: 7
Joined: 22 Nov 2019, 16:35

Re: [Class] biga.ahk (utilities mirroring Lodash)

Post by ardent246 » 29 Nov 2019, 22:19

I'm sorry, I'm sure I'm doing something stupid, but I cannot use this wonderful looking library.

I installed via NPM and tried running the example code but I am getting a "call to nonexistent function" error for the "max" function on the following line (1008):

sum := format("{:." max(n_dec_char, param_precision) + 1 "f}", param_number + offset)

Are there some dependencies I do not have? Thanks for your help and work on this, and your patience in answering what I'm sure is a silly question.

User avatar
Chunjee
Posts: 1400
Joined: 18 Apr 2014, 19:05
Contact:

Re: [Class] biga.ahk (utilities mirroring Lodash)

Post by Chunjee » 30 Nov 2019, 11:19

ardent246 wrote:
29 Nov 2019, 22:19
I installed via NPM and tried running the example code but I am getting a "call to nonexistent function" error for the "max" function on the following line (1008):

sum := format("{:." max(n_dec_char, param_precision) + 1 "f}", param_number + offset)
Max() is a built-in ahk function that was added in v1.1.27

I will update biga.ahk documentation on this or code around it. Readme currently says "AutoHotkey v1.1.05 or higher is required" which is apparently not exactly accurate.

In short, you need to update ahk itself. Tomorrow I'll see if I can cleanly eliminate use of Max()

User avatar
Chunjee
Posts: 1400
Joined: 18 Apr 2014, 19:05
Contact:

Re: [Class] biga.ahk (utilities mirroring Lodash)

Post by Chunjee » 01 Dec 2019, 08:54

v0.19.2 is now on npm and relies on it's own .max method instead of the ahk built in. This brings the ahk version requirement back down to about where it was before.

https://github.com/biga-ahk/biga.ahk/commit/0ec28cf3e4387e0e676ee702fcf9223d6841820f

User avatar
Chunjee
Posts: 1400
Joined: 18 Apr 2014, 19:05
Contact:

Re: [Class] biga.ahk (utilities mirroring Lodash)

Post by Chunjee » 31 Dec 2019, 10:06

v0.20.0 is now on npm and github.

The new addition is .findLastIndex and some improvements to .findIndex

User avatar
Chunjee
Posts: 1400
Joined: 18 Apr 2014, 19:05
Contact:

Re: [Class] biga.ahk (utilities mirroring Lodash)

Post by Chunjee » 07 Jan 2020, 09:48

In javascript the concept of null and undefined exist. The closest thing in ahk is "" which is what .min and .max were returning. I thought returning false might be more appropriate and made the change. However, after thinking about it for a few days and looking at .isUndefined, I believe "" was the most correct return. That change will be reverted soon and anything that would normally return undefined or null in Lodash will be returned as "" in biga.ahk


User avatar
Chunjee
Posts: 1400
Joined: 18 Apr 2014, 19:05
Contact:

Re: [Class] biga.ahk (utilities mirroring Lodash)

Post by Chunjee » 15 Jan 2020, 13:31

v0.21.0 adds the following:
.kebabCase
.lowerCase
.snakeCase
.upperCase

User avatar
Chunjee
Posts: 1400
Joined: 18 Apr 2014, 19:05
Contact:

Re: [Class] biga.ahk (utilities mirroring Lodash)

Post by Chunjee » 27 Jan 2020, 07:54

.keyBy was added. https://biga-ahk.github.io/biga.ahk/#/?id=keyby
Creates an object composed of keys generated from the results of running each element of collection through iteratee. The corresponding value of each key is the last element responsible for generating the key. The iteratee is invoked with one argument: (value).

Code: Select all

array := [ {"dir": "left", "code": 97}
    , {"dir": "right", "code": 100}]
A.keyBy(array, Func("keyByFunc1"))
; => {"left": {"dir": "left", "code": 97}, "right": {"dir": "right", "code": 100}}

keyByFunc1(value)
{
    return value.dir
}
Last edited by Chunjee on 12 May 2020, 21:48, edited 1 time in total.

User avatar
Chunjee
Posts: 1400
Joined: 18 Apr 2014, 19:05
Contact:

Re: [Class] biga.ahk (utilities mirroring Lodash)

Post by Chunjee » 03 Feb 2020, 13:42

.slice was added. https://biga-ahk.github.io/biga.ahk/#/?id=slice

Code: Select all

A.slice([1, 2, 3], 1, 2)
; => [1, 2]

A.slice([1, 2, 3], 1)
; => [1, 2, 3]

A.slice([1, 2, 3], 5)
; => []

A.slice("fred")
; => ["f", "r", "e", "d"]

A.slice(100)
; => ["1", "0", "0"]

User avatar
Chunjee
Posts: 1400
Joined: 18 Apr 2014, 19:05
Contact:

Re: [Class] biga.ahk (utilities mirroring Lodash)

Post by Chunjee » 26 Feb 2020, 09:03

latest version is now v0.24.0

.flatten was added https://biga-ahk.github.io/biga.ahk/#/?id=flatten
Flattens array a single level deep.

Code: Select all

A.flatten([1, [2, [3, [4]], 5]])
; => [1, 2, [3, [4]], 5]
A.flatten([[1, 2, 3], [4, 5, 6]])
; => [1, 2, 3, 4, 5, 6]

if someone wants to make a recursive .flattenDeep, that would make a very cool addition.

User avatar
Chunjee
Posts: 1400
Joined: 18 Apr 2014, 19:05
Contact:

Re: [Class] biga.ahk (utilities mirroring Lodash)

Post by Chunjee » 01 Mar 2020, 10:38

v0.24.1 fixes some bugs with .trim, .trimStart, .trimEnd, and .parseInt

User avatar
Chunjee
Posts: 1400
Joined: 18 Apr 2014, 19:05
Contact:

Re: [Class] biga.ahk (utilities mirroring Lodash)

Post by Chunjee » 01 Apr 2020, 13:02

v0.24.3 fixes some missing functionality of .sortBy

Sorting non-associative arrays didn't work. Now it does.

Code: Select all

A.sortBy([3, 4, 2, 9, 4, 2])
; => [2, 2, 3, 4, 4, 9]

A.sortBy(["100", "333", "987", "54", "1", "0", "-263", "543"])
; => ["-263", "0", "1", "54", "100", "333", "543", "987"]

A.sortBy(["b", "f", "e", "c", "d", "a", "h", "g"])
; => ["a", "b", "c", "d", "e", "f", "g", "h"]

User avatar
Chunjee
Posts: 1400
Joined: 18 Apr 2014, 19:05
Contact:

Re: [Class] biga.ahk (utilities mirroring Lodash)

Post by Chunjee » 06 Apr 2020, 12:05

v0.25.0 adds .endsWith
docs

Code: Select all

A.endsWith("abc", "c")
; => true

A.endsWith("abc", "b")
; => false

A.endsWith("abc", "b", 2)
; => true

User avatar
Chunjee
Posts: 1400
Joined: 18 Apr 2014, 19:05
Contact:

Re: [Class] biga.ahk (utilities mirroring Lodash)

Post by Chunjee » 22 Apr 2020, 07:50

Ran into a nice use case yesterday for .filter and .difference
I had a bunch of objects getting into my array that I wanted to remove, The way I used to deal with this would be to loop the entire array and have a bunch of if statements to catch any offending objects and remove them. This gets even more complicated when I want to allow the enduser to define the blacklist in a config file. I know I can use .filter to find all the objects that DO match the properties, but I want those matches taken OUT of the array. Ah! Once found we can remove them with .difference

Was able to complete the feature in basically two very clear lines instead of a longwinded loop that would probably take me a little while to bugtest and predict all the scenarios the enduser might dream up.
For this example I've omitted many of the object properties, the thing to note about this is that you don't need to make a perfect match with .filter, it can make matches with partial information.

Code: Select all

Tracks := [
    , { group: "Australia", trackname: "Australia", note: "[...]" }
    , { group: "Sweden", trackname: "Skive", note: "[...]" }
    , { group: "Sweden", trackname: "Aby", note: "[...]" },
    , { group: "Sweden", trackname: "Bro", note: "[...]" } ]


removableTracks := A.filter(Tracks, {group: "Sweden", trackname: "Skive"}) 
; => [{ group: "Sweden", trackname: "Skive", note: "[...]" }]
Tracks := A.difference(Tracks, removableTracks)
/* => 
    [ { group: "Australia", trackname: "Australia", note: "[...]" }
    , { group: "Sweden", trackname: "Aby", note: "[...]" },
    , { group: "Sweden", trackname: "Bro", note: "[...]" } ]
*/

Post Reply

Return to “Scripts and Functions (v1)”