# Lua (.lua)

Source sample: `lua/plenary-path.lua`

Strategy: `aggressive`

| Tool | Bytes | Cut | Time |
| --- | ---: | ---: | ---: |
| input | 23250 | - | - |
| content-view | 19630 | 15.6% | 0.815 ms |
| applyMinification | 16783 | 27.8% | 0.881 ms |
| sync minify | 16783 | 27.8% | 0.885 ms |
| async minify | 16783 | 27.8% | 0.877 ms |
| symbols | 25967 | -11.7% | 0.184 ms |

## Notes

- aggressive text strategy.

## Before Excerpt

```lua
--- Path.lua
---
--- Goal: Create objects that are extremely similar to Python's `Path` Objects.
--- Reference: https://docs.python.org/3/library/pathlib.html

local bit = require "plenary.bit"
local uv = vim.loop

local F = require "plenary.functional"

local S_IF = {
  -- S_IFDIR  = 0o040000  # directory
  DIR = 0x4000,
  -- S_IFREG  = 0o100000  # regular file
  REG = 0x8000,
}

local path = {}
path.home = vim.loop.os_homedir()

path.sep = (function()
  if jit then
    local os = string.lower(jit.os)
    if os ~= "windows" then
      return "/"
    else
      return "\\"
    end
  else
    return package.config:sub(1, 1)
  end
end)()

path.root = (function()
  if path.sep == "/" then
    return function()
      return "/"
    end
  else
    return function(base)
      base = base or vim.loop.cwd()
      return base:sub(1, 1) .. ":\\"
    end
  end
end)()

path.S_IF = S_IF

local band = function(reg, value)
  return bit.band(reg, value) == reg
end

local concat_paths = function(...)
  return table.concat({ ... }, path.sep)
end

local function is_root(pathname)
  if path.sep == "\\" then
    return string.match(pathname, "^[A-Z]:\\?$")
  end
  return pathname == "/"
end

local _split_by_separator = (funct

... [truncated 21450 chars] ...


    local read_chunk = assert(uv.fs_read(fd, length - #data, offset))
    if #read_chunk == 0 then
      break
    end
    data = data .. read_chunk
    offset = offset + #read_chunk
  end

  assert(uv.fs_close(fd))

  return data
end

function Path:find_upwards(filename)
  local folder = Path:new(self)
  local root = path.root(folder:absolute())

  while true do
    local p = folder:joinpath(filename)
    if p:exists() then
      return p
    end
    if folder:absolute() == root then
      break
    end
    folder = folder:parent()
  end
  return nil
end

return Path

```

## Content-View Excerpt

```lua
local bit = require "plenary.bit"
local uv = vim.loop

local F = require "plenary.functional"

local S_IF = {

  DIR = 0x4000,

  REG = 0x8000,
}

local path = {}
path.home = vim.loop.os_homedir()

path.sep = (function()
  if jit then
    local os = string.lower(jit.os)
    if os ~= "windows" then
      return "/"
    else
      return "\\"
    end
  else
    return package.config:sub(1, 1)
  end
end)()

path.root = (function()
  if path.sep == "/" then
    return function()
      return "/"
    end
  else
    return function(base)
      base = base or vim.loop.cwd()
      return base:sub(1, 1) .. ":\\"
    end
  end
end)()

path.S_IF = S_IF

local band = function(reg, value)
  return bit.band(reg, value) == reg
end

local concat_paths = function(...)
  return table.concat({ ... }, path.sep)
end

local function is_root(pathname)
  if path.sep == "\\" then
    return string.match(pathname, "^[A-Z]:\\?$")
  end
  return pathname == "/"
end

local _split_by_separator = (function()
  local formatted = string.format("([^%s]+)", path.sep)
  return function(filepath)
    local t = {}
    for str in string.gmatch(filepath, formatted) do
      table.insert(t, str)
    end
    return t
  end
end)()

local is_uri =

... [truncated 17830 chars] ...

o
    local read_chunk = assert(uv.fs_read(fd, length - #data, offset))
    if #read_chunk == 0 then
      break
    end
    data = data .. read_chunk
    offset = offset + #read_chunk
  end

  assert(uv.fs_close(fd))

  return data
end

function Path:find_upwards(filename)
  local folder = Path:new(self)
  local root = path.root(folder:absolute())

  while true do
    local p = folder:joinpath(filename)
    if p:exists() then
      return p
    end
    if folder:absolute() == root then
      break
    end
    folder = folder:parent()
  end
  return nil
end

return Path
```

## Apply Minification Excerpt

```lua
local bit = require "plenary.bit" local uv = vim.loop local F = require "plenary.functional" local S_IF ={DIR = 0x4000,REG = 0x8000,}local path ={}path.home = vim.loop.os_homedir() path.sep = (function() if jit then local os = string.lower(jit.os) if os ~= "windows" then return "/" else return "\\" end else return package.config:sub(1,1) end end)() path.root = (function() if path.sep == "/" then return function() return "/" end else return function(base) base = base or vim.loop.cwd() return base:sub(1,1) .. ":\\" end end end)() path.S_IF = S_IF local band = function(reg,value) return bit.band(reg,value) == reg end local concat_paths = function(...) return table.concat({...},path.sep) end local function is_root(pathname) if path.sep == "\\" then return string.match(pathname,"^[A-Z]:\\?$") end return pathname == "/" end local _split_by_separator = (function() local formatted = string.format("([^%s]+)",path.sep) return function(filepath) local t ={}for str in string.gmatch(filepath,formatted) do table.insert(t,str) end return t end end)() local is_uri = function(filename) return string.match(filename,"^%a[%w+-.]*://") ~= nil end local is_absolute = function(filename,sep) if sep == "\\" then return string.mat

... [truncated 14983 chars] ...

e + offset if offset< 0 then offset = 0 end end local data = "" while #data< length do local read_chunk = assert(uv.fs_read(fd,length - #data,offset)) if #read_chunk == 0 then break end data = data .. read_chunk offset = offset + #read_chunk end assert(uv.fs_close(fd)) return data end function Path:find_upwards(filename) local folder = Path:new(self) local root = path.root(folder:absolute()) while true do local p = folder:joinpath(filename) if p:exists() then return p end if folder:absolute() == root then break end folder = folder:parent() end return nil end return Path
```

## Sync Minify Excerpt

```lua
local bit = require "plenary.bit" local uv = vim.loop local F = require "plenary.functional" local S_IF ={DIR = 0x4000,REG = 0x8000,}local path ={}path.home = vim.loop.os_homedir() path.sep = (function() if jit then local os = string.lower(jit.os) if os ~= "windows" then return "/" else return "\\" end else return package.config:sub(1,1) end end)() path.root = (function() if path.sep == "/" then return function() return "/" end else return function(base) base = base or vim.loop.cwd() return base:sub(1,1) .. ":\\" end end end)() path.S_IF = S_IF local band = function(reg,value) return bit.band(reg,value) == reg end local concat_paths = function(...) return table.concat({...},path.sep) end local function is_root(pathname) if path.sep == "\\" then return string.match(pathname,"^[A-Z]:\\?$") end return pathname == "/" end local _split_by_separator = (function() local formatted = string.format("([^%s]+)",path.sep) return function(filepath) local t ={}for str in string.gmatch(filepath,formatted) do table.insert(t,str) end return t end end)() local is_uri = function(filename) return string.match(filename,"^%a[%w+-.]*://") ~= nil end local is_absolute = function(filename,sep) if sep == "\\" then return string.mat

... [truncated 14983 chars] ...

e + offset if offset< 0 then offset = 0 end end local data = "" while #data< length do local read_chunk = assert(uv.fs_read(fd,length - #data,offset)) if #read_chunk == 0 then break end data = data .. read_chunk offset = offset + #read_chunk end assert(uv.fs_close(fd)) return data end function Path:find_upwards(filename) local folder = Path:new(self) local root = path.root(folder:absolute()) while true do local p = folder:joinpath(filename) if p:exists() then return p end if folder:absolute() == root then break end folder = folder:parent() end return nil end return Path
```

## Async Minify Excerpt

```lua
local bit = require "plenary.bit" local uv = vim.loop local F = require "plenary.functional" local S_IF ={DIR = 0x4000,REG = 0x8000,}local path ={}path.home = vim.loop.os_homedir() path.sep = (function() if jit then local os = string.lower(jit.os) if os ~= "windows" then return "/" else return "\\" end else return package.config:sub(1,1) end end)() path.root = (function() if path.sep == "/" then return function() return "/" end else return function(base) base = base or vim.loop.cwd() return base:sub(1,1) .. ":\\" end end end)() path.S_IF = S_IF local band = function(reg,value) return bit.band(reg,value) == reg end local concat_paths = function(...) return table.concat({...},path.sep) end local function is_root(pathname) if path.sep == "\\" then return string.match(pathname,"^[A-Z]:\\?$") end return pathname == "/" end local _split_by_separator = (function() local formatted = string.format("([^%s]+)",path.sep) return function(filepath) local t ={}for str in string.gmatch(filepath,formatted) do table.insert(t,str) end return t end end)() local is_uri = function(filename) return string.match(filename,"^%a[%w+-.]*://") ~= nil end local is_absolute = function(filename,sep) if sep == "\\" then return string.mat

... [truncated 14983 chars] ...

e + offset if offset< 0 then offset = 0 end end local data = "" while #data< length do local read_chunk = assert(uv.fs_read(fd,length - #data,offset)) if #read_chunk == 0 then break end data = data .. read_chunk offset = offset + #read_chunk end assert(uv.fs_close(fd)) return data end function Path:find_upwards(filename) local folder = Path:new(self) local root = path.root(folder:absolute()) while true do local p = folder:joinpath(filename) if p:exists() then return p end if folder:absolute() == root then break end folder = folder:parent() end return nil end return Path
```

## Symbols

```txt
  1| --- Path.lua
  2| ---
  3| --- Goal: Create objects that are extremely similar to Python's `Path` Objects.
  4| --- Reference: https://docs.python.org/3/library/pathlib.html
  6| local bit = require "plenary.bit"
  7| local uv = vim.loop
  9| local F = require "plenary.functional"
 11| local S_IF = {
 16| }
 18| local path = {}
 19| path.home = vim.loop.os_homedir()
 21| path.sep = (function()
 22|   if jit then
 23|     local os = string.lower(jit.os)
 24|     if os ~= "windows" then
 25|       return "/"
 26|     else
 27|       return "\\"
 28|     end
 29|   else
 30|     return package.config:sub(1, 1)
 31|   end
 32| end)()
 34| path.root = (function()
 35|   if path.sep == "/" then
 36|     return function()
 37|       return "/"
 38|     end
 39|   else
 40|     return function(base)
 41|       base = base or vim.loop.cwd()
 42|       return base:sub(1, 1) .. ":\\"
 43|     end
 44|   end
 45| end)()
 47| path.S_IF = S_IF
 49| local band = function(reg, value)
 50|   return bit.band(reg, value) == reg
 51| end
 53| local concat_paths = function(...)
 54|   return table.concat({ ... }, path.sep)
 55| end
 57| local function is_root(pathname)
 58|   if path.sep == "\\" then
 59|     return string.match(pathname, "^[A-Z]:\\?$")
 60|   end
 61|   return pathname == "/"
 62| end
 64| local _split_by_separator = (function()
 65|   local formatted = string.format("([^%s]+)", path.sep)
 66|   return function(filepath)
 67|     local t = {}
 68|     for str in string.gmatch(filepath, formatted) do
 69|       table.insert(t, str)
 70|     end
 71|     return t
 72|   end
 73| end)()
 75| local is_uri = function(filename)
 76|   return string.match(filename, "^%a[%w+-.]*://") ~= nil
 77| end
 79| local is_absolute = function(filename, s

... [truncated 23367 chars] ...

read
910|     if offset < 0 then
911|       offset = 0
912|     end
913|   end
915|   local data = ""
916|   while #data < length do
917|     local read_chunk = assert(uv.fs_read(fd, length - #data, offset))
918|     if #read_chunk == 0 then
919|       break
920|     end
921|     data = data .. read_chunk
922|     offset = offset + #read_chunk
923|   end
925|   assert(uv.fs_close(fd))
927|   return data
928| end
930| function Path:find_upwards(filename)
931|   local folder = Path:new(self)
932|   local root = path.root(folder:absolute())
934|   while true do
935|     local p = folder:joinpath(filename)
936|     if p:exists() then
937|       return p
938|     end
939|     if folder:absolute() == root then
940|       break
941|     end
942|     folder = folder:parent()
943|   end
944|   return nil
945| end
947| return Path
```
