typescript-to-lua 1.13.2 → 1.13.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/LuaLib.d.ts CHANGED
@@ -55,6 +55,7 @@ export declare enum LuaLibFeature {
55
55
  NumberIsFinite = "NumberIsFinite",
56
56
  NumberIsNaN = "NumberIsNaN",
57
57
  NumberToString = "NumberToString",
58
+ NumberToFixed = "NumberToFixed",
58
59
  ObjectAssign = "ObjectAssign",
59
60
  ObjectDefineProperty = "ObjectDefineProperty",
60
61
  ObjectEntries = "ObjectEntries",
package/dist/LuaLib.js CHANGED
@@ -60,6 +60,7 @@ var LuaLibFeature;
60
60
  LuaLibFeature["NumberIsFinite"] = "NumberIsFinite";
61
61
  LuaLibFeature["NumberIsNaN"] = "NumberIsNaN";
62
62
  LuaLibFeature["NumberToString"] = "NumberToString";
63
+ LuaLibFeature["NumberToFixed"] = "NumberToFixed";
63
64
  LuaLibFeature["ObjectAssign"] = "ObjectAssign";
64
65
  LuaLibFeature["ObjectDefineProperty"] = "ObjectDefineProperty";
65
66
  LuaLibFeature["ObjectEntries"] = "ObjectEntries";
@@ -0,0 +1,13 @@
1
+ local function __TS__NumberToFixed(self, fractionDigits)
2
+ if math.abs(self) >= 1e+21 or self ~= self then
3
+ return tostring(self)
4
+ end
5
+ local f = math.floor(fractionDigits or 0)
6
+ if f < 0 or f > 99 then
7
+ error("toFixed() digits argument must be between 0 and 99", 0)
8
+ end
9
+ return string.format(
10
+ ("%." .. tostring(f)) .. "f",
11
+ self
12
+ )
13
+ end
@@ -1498,6 +1498,20 @@ do
1498
1498
  end
1499
1499
  end
1500
1500
 
1501
+ local function __TS__NumberToFixed(self, fractionDigits)
1502
+ if math.abs(self) >= 1e+21 or self ~= self then
1503
+ return tostring(self)
1504
+ end
1505
+ local f = math.floor(fractionDigits or 0)
1506
+ if f < 0 or f > 99 then
1507
+ error("toFixed() digits argument must be between 0 and 99", 0)
1508
+ end
1509
+ return string.format(
1510
+ ("%." .. tostring(f)) .. "f",
1511
+ self
1512
+ )
1513
+ end
1514
+
1501
1515
  local function __TS__ObjectDefineProperty(target, key, desc)
1502
1516
  local luaKey = type(key) == "number" and key + 1 or key
1503
1517
  local value = rawget(target, luaKey)
@@ -2467,6 +2481,7 @@ return {
2467
2481
  __TS__NumberIsFinite = __TS__NumberIsFinite,
2468
2482
  __TS__NumberIsNaN = __TS__NumberIsNaN,
2469
2483
  __TS__NumberToString = __TS__NumberToString,
2484
+ __TS__NumberToFixed = __TS__NumberToFixed,
2470
2485
  __TS__ObjectAssign = __TS__ObjectAssign,
2471
2486
  __TS__ObjectDefineProperty = __TS__ObjectDefineProperty,
2472
2487
  __TS__ObjectEntries = __TS__ObjectEntries,
@@ -348,6 +348,11 @@
348
348
  "MathModf"
349
349
  ]
350
350
  },
351
+ "NumberToFixed": {
352
+ "exports": [
353
+ "__TS__NumberToFixed"
354
+ ]
355
+ },
351
356
  "ObjectAssign": {
352
357
  "exports": [
353
358
  "__TS__ObjectAssign"
@@ -0,0 +1,13 @@
1
+ local function __TS__NumberToFixed(self, fractionDigits)
2
+ if math.abs(self) >= 1e+21 or self ~= self then
3
+ return tostring(self)
4
+ end
5
+ local f = math.floor(fractionDigits or 0)
6
+ if f < 0 or f > 99 then
7
+ error("toFixed() digits argument must be between 0 and 99", 0)
8
+ end
9
+ return string.format(
10
+ ("%." .. tostring(f)) .. "f",
11
+ self
12
+ )
13
+ end
@@ -1440,6 +1440,20 @@ do
1440
1440
  end
1441
1441
  end
1442
1442
 
1443
+ local function __TS__NumberToFixed(self, fractionDigits)
1444
+ if math.abs(self) >= 1e+21 or self ~= self then
1445
+ return tostring(self)
1446
+ end
1447
+ local f = math.floor(fractionDigits or 0)
1448
+ if f < 0 or f > 99 then
1449
+ error("toFixed() digits argument must be between 0 and 99", 0)
1450
+ end
1451
+ return string.format(
1452
+ ("%." .. tostring(f)) .. "f",
1453
+ self
1454
+ )
1455
+ end
1456
+
1443
1457
  local function __TS__ObjectDefineProperty(target, key, desc)
1444
1458
  local luaKey = type(key) == "number" and key + 1 or key
1445
1459
  local value = rawget(target, luaKey)
@@ -2412,6 +2426,7 @@ return {
2412
2426
  __TS__NumberIsFinite = __TS__NumberIsFinite,
2413
2427
  __TS__NumberIsNaN = __TS__NumberIsNaN,
2414
2428
  __TS__NumberToString = __TS__NumberToString,
2429
+ __TS__NumberToFixed = __TS__NumberToFixed,
2415
2430
  __TS__ObjectAssign = __TS__ObjectAssign,
2416
2431
  __TS__ObjectDefineProperty = __TS__ObjectDefineProperty,
2417
2432
  __TS__ObjectEntries = __TS__ObjectEntries,
@@ -348,6 +348,11 @@
348
348
  "MathModf"
349
349
  ]
350
350
  },
351
+ "NumberToFixed": {
352
+ "exports": [
353
+ "__TS__NumberToFixed"
354
+ ]
355
+ },
351
356
  "ObjectAssign": {
352
357
  "exports": [
353
358
  "__TS__ObjectAssign"
@@ -15,6 +15,8 @@ function transformNumberPrototypeCall(context, node, calledMethod) {
15
15
  return params.length === 0
16
16
  ? lua.createCallExpression(lua.createIdentifier("tostring"), [caller], node)
17
17
  : (0, lualib_1.transformLuaLibFunction)(context, lualib_1.LuaLibFeature.NumberToString, node, caller, ...params);
18
+ case "toFixed":
19
+ return (0, lualib_1.transformLuaLibFunction)(context, lualib_1.LuaLibFeature.NumberToFixed, node, caller, ...params);
18
20
  default:
19
21
  context.diagnostics.push((0, diagnostics_1.unsupportedProperty)(calledMethod.name, "number", expressionName));
20
22
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "typescript-to-lua",
3
- "version": "1.13.2",
3
+ "version": "1.13.3",
4
4
  "description": "A generic TypeScript to Lua transpiler. Write your code in TypeScript and publish Lua!",
5
5
  "repository": "https://github.com/TypeScriptToLua/TypeScriptToLua",
6
6
  "homepage": "https://typescripttolua.github.io/",