Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local object = {}
- local select = ""
- local callback = function() end --catch the error of 'callback is a nil value'
- local getBy = function(parent, check, by, extra)
- local iterate;
- iterate = function(parent, check, by, extra)
- for index, value in pairs(parent:GetChildren()) do
- if by == "class" then
- if value.ClassName:lower() == check:lower() then
- table.insert(object, value)
- end
- elseif by == "name" then
- if value.Name:lower() == check:lower() then
- table.insert(object, value)
- end
- elseif by == "property" then
- if pcall(function() return value[check] end) then
- local kind = type(value[check])
- if value[check] == (kind == "string" and tostring(extra) or kind == "number" and tonumber(extra) or extra) then
- table.insert(object, value)
- end
- end
- elseif by == "all" then
- table.insert(object, value)
- end
- iterate(value, check, by, extra)
- end
- end
- iterate(parent, check, by, extra)
- end
- local loop = function(lqCallback, userCallback, ...)
- for index, value in pairs(object) do
- if lqCallback then
- lqCallback(index, value)
- end
- if userCallback then
- userCallback(index, value, ...)
- end
- end
- return lq
- end
- local removeElement = function(array, element)
- for index, value in ipairs(array) do
- if value == element then
- table.remove(array, index)
- end
- end
- end
- local warn = function(warning, selector)
- return "WARNING: " .. warning .. " ( " .. selector .. " ) "
- end
- local lq;
- lq = {
- each = function(callback)
- return loop(nil, callback)
- end,
- dest = function(callback)
- return loop(function(_, value) value:Destroy() end, callback)
- end,
- val = function(key)
- if not key and #object == 1 and object[1]:FindFirstChild("LQ_SAVE_KEY") then
- return object[1]["LQ_SAVE_KEY"].Value
- elseif not key then
- return warn("Cannot get the value of multiple items!", select)
- end
- return loop(function(_, value)
- if value:FindFirstChild("LQ_SAVE_KEY") then
- value["LQ_SAVE_KEY"].Value = key
- else
- local save = Instance.new("StringValue", value)
- save.Name = "LQ_SAVE_KEY"
- save.Value = key
- end
- end)
- end,
- color = function(color)
- local colors = {
- blue = "Bright blue",
- red = "Bright red",
- green = "Bright green",
- orange = "Bright orange",
- yellow = "Bright yellow",
- purple = "Bright purple",
- white = "White",
- black = "Black"
- }
- return loop(function(_, value)
- if value:IsA("BasePart") then
- value.BrickColor = BrickColor.new(colors[color:lower()] or color)
- end
- end)
- end,
- attr = function(property, set)
- if type(property) == "table" then
- return loop(function(_, value)
- for property, apply in pairs(property) do
- pcall(function() value[property] = apply end)
- end
- end)
- elseif set then
- return loop(function(_, value)
- pcall(function() value[property] = set end)
- end)
- elseif pcall(function() return object[1][property] and not object[1]:FindFirstChild(property) end) then
- return object[1][property]
- end
- end,
- listen = function(event, callback)
- local events = {
- change = "Changed", newplayer = "PlayerAdded"
- }
- return loop(function(_, value)
- pcall(function() value[events[event:lower()] or event]:connect(callback) end)
- end)
- end,
- rand = function()
- return object[math.random(#object)]
- end,
- indexOf = function(search)
- local ret = false
- if type(object) == "string" then
- ret = object:find(search)
- else
- loop(function(index, value)
- if value == search then
- ret = index
- end
- end)
- end
- return ret
- end,
- insert = function(...)
- for _, value in ipairs({...}) do
- table.insert(object, value)
- end
- return lq
- end,
- rid = function(...)
- for index, value in ipairs(object) do
- for _, check in ipairs({...}) do
- if check == value then
- table.remove(object, index)
- end
- end
- end
- return lq
- end,
- concat = function(split)
- return table.concat(object, split)
- end,
- greatest = function()
- return math.max(unpack(object))
- end,
- least = function()
- return math.min(unpack(object))
- end,
- raw = function()
- return object
- end
- }
- local ret = function(selector, parent)
- object = {}
- select = selector
- parent = parent or Workspace
- if type(selector) == "string" then
- local matched;
- selector:gsub("%.(.-)/", function(pattern)
- matched = true
- getBy(parent, pattern, "class")
- end):gsub("#(.-)/", function(pattern)
- matched = true
- getBy(parent, pattern, "name")
- end):gsub("%?([%a%d]+)=(.-)/", function(patternOne, patternTwo)
- matched = true
- getBy(parent, patternOne, "property", patternTwo)
- end):gsub("&(.-)/", function(pattern)
- matched = true
- if pattern:lower() == "direct" then
- for _, v in ipairs(parent:GetChildren()) do
- table.insert(object, v)
- end
- elseif pattern:lower() == "all" then
- getBy(parent, nil, "all")
- end
- end):gsub("%?([%a%d]+)!=(.-)/", function(patternOne, patternTwo)
- matched = true
- for _, v in pairs(object) do
- pcall(function()
- if v[patternOne] == patternTwo then
- removeElement(object, v)
- end
- end)
- end
- end)
- if not matched then
- object = selector
- end
- elseif type(selector) == "table" then
- object = selector
- else
- object = {selector}
- end
- return lq
- end
- return ret
Advertisement
Add Comment
Please, Sign In to add comment