diff --git a/.husky/pre-commit b/.husky/pre-commit deleted file mode 100644 index ece6a97..0000000 --- a/.husky/pre-commit +++ /dev/null @@ -1,5 +0,0 @@ -#!/usr/bin/env sh -. "$(dirname -- "$0")/_/husky.sh" - -stylua --check src/ -selene src/ diff --git a/.vscode/settings.json b/.vscode/settings.json index 52d7ad7..3fd8454 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -9,8 +9,8 @@ "editor.defaultFormatter": "esbenp.prettier-vscode" }, "editor.codeActionsOnSave": { - "source.fixAll": true, - "source.organizeImports": true + "source.fixAll": "explicit", + "source.organizeImports": "explicit" }, "editor.formatOnSave": true, "editor.formatOnPaste": true, diff --git a/package-lock.json b/package-lock.json index 0ef74a7..4c41da5 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,17 +1,16 @@ { "name": "@rbxts/sift", - "version": "0.0.7", + "version": "0.0.9", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@rbxts/sift", - "version": "0.0.7", + "version": "0.0.9", "license": "MIT", "devDependencies": { "@rbxts/compiler-types": "^1.2.3-types.0", "@rbxts/types": "^1.0.515", - "husky": "^8.0.0", "rbxts-transform-debug": "^1.0.0-rc.1", "rbxts-transform-env": "^1.0.0-rc.0", "roblox-ts": "^1.2.7", @@ -383,21 +382,6 @@ "node": ">=10.17.0" } }, - "node_modules/husky": { - "version": "8.0.3", - "resolved": "https://registry.npmjs.org/husky/-/husky-8.0.3.tgz", - "integrity": "sha512-+dQSyqPh4x1hlO1swXBiNb2HzTDN1I2IGLQx1GrBuiqFJfoMrnZWwVmatvSiO+Iz8fBUnf+lekwNo4c2LlXItg==", - "dev": true, - "bin": { - "husky": "lib/bin.js" - }, - "engines": { - "node": ">=14" - }, - "funding": { - "url": "https://github.com/sponsors/typicode" - } - }, "node_modules/is-binary-path": { "version": "2.1.0", "resolved": "https://registry.npmjs.org/is-binary-path/-/is-binary-path-2.1.0.tgz", @@ -1236,12 +1220,6 @@ "integrity": "sha512-B4FFZ6q/T2jhhksgkbEW3HBvWIfDW85snkQgawt07S7J5QXTk6BkNV+0yAeZrM5QpMAdYlocGoljn0sJ/WQkFw==", "dev": true }, - "husky": { - "version": "8.0.3", - "resolved": "https://registry.npmjs.org/husky/-/husky-8.0.3.tgz", - "integrity": "sha512-+dQSyqPh4x1hlO1swXBiNb2HzTDN1I2IGLQx1GrBuiqFJfoMrnZWwVmatvSiO+Iz8fBUnf+lekwNo4c2LlXItg==", - "dev": true - }, "is-binary-path": { "version": "2.1.0", "resolved": "https://registry.npmjs.org/is-binary-path/-/is-binary-path-2.1.0.tgz", diff --git a/package.json b/package.json index 5d506bc..c57a9fe 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@rbxts/sift", - "version": "0.0.8", + "version": "0.0.9", "description": "Immutable data library for Luau", "main": "out/init.lua", "types": "out/index.d.ts", @@ -10,8 +10,7 @@ "scripts": { "build": "rbxtsc --type=package --rojo=''", "watch": "rbxtsc -w", - "prepublishOnly": "npm run build", - "prepare": "husky install" + "prepublishOnly": "npm run build" }, "repository": { "type": "git", @@ -41,8 +40,7 @@ "@rbxts/types": "^1.0.515", "rbxts-transform-debug": "^1.0.0-rc.1", "rbxts-transform-env": "^1.0.0-rc.0", - "typescript": "^4.3.5", "roblox-ts": "^1.2.7", - "husky": "^8.0.0" + "typescript": "^4.3.5" } } diff --git a/src/Dictionary/update.lua b/src/Dictionary/update.lua index 4a5ff6b..1b1dee0 100644 --- a/src/Dictionary/update.lua +++ b/src/Dictionary/update.lua @@ -1,24 +1,15 @@ --!strict local copy = require(script.Parent.copy) -type Callback = (key: K) -> V -type Updater = (value: V, key: K) -> V - -local function call(callback: Callback, key: K) - if type(callback) == "function" then - return callback(key) - end -end - --[=[ @function update @within Dictionary - @param dictionary {[K]: V} -- The dictionary to update. + @param dictionary {[K]: V?} -- The dictionary to update. @param key K -- The key to update. @param updater? (value: V, key: K) -> U -- The updater function. @param callback? (key: K) -> C -- The callback function. - @return {[K]: V & U & C } -- The updated dictionary. + @return {[K]: V | U | C} -- The updated dictionary. Updates a value in a dictionary at the given key. If the value at the given key does not exist, `callback` will be called, and its return value will be used as the value at the given key. @@ -37,20 +28,20 @@ end ``` ]=] local function update( - dictionary: { [K]: V }, + dictionary: { [K]: V? }, key: K, updater: ((value: V, key: K) -> U)?, callback: ((key: K) -> C)? -): { [K]: V & U & C } - local result = copy(dictionary) +): { [K]: V | U | C } + local result: { [K]: any } = copy(dictionary) - if result[key] ~= nil then + if result[key] then if updater then result[key] = updater(result[key], key) end else - if callback then - result[key] = call(callback, key) + if typeof(callback) == "function" then + result[key] = callback(key) end end diff --git a/wally.toml b/wally.toml index dd436fc..06247da 100644 --- a/wally.toml +++ b/wally.toml @@ -1,12 +1,9 @@ [package] name = "csqrl/sift" description = "Immutable data library for Luau" -version = "0.0.8" +version = "0.0.9" license = "MIT" -author = "csqrl (https://csqrl.dev)" registry = "https://github.com/upliftgames/wally-index" -homepage = "https://csqrl.github.io/sift" -repo = "https://github.com/csqrl/sift" realm = "shared" exclude = ["**"] include = ["src", "src/**", "wally.toml", "wally.lock", "default.project.json"]