ms-rb 0.1.0 → 0.1.1

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.
Files changed (5) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +135 -20
  3. data/lib/ms/rb/version.rb +1 -1
  4. data/lib/ms.rb +4 -4
  5. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ffe1320c11560d697c6e1aa26a894216d56b1d91108baad876199cea9bed541f
4
- data.tar.gz: 2738fdca6efb992e16f28b6f224c5ce51778ccf2b357b30f6288e852e762004f
3
+ metadata.gz: f6d761b6b9a5ff849e3c44d81391ad5e1eeb00c1c6acf0799c9204fc0bfae982
4
+ data.tar.gz: a3b9380fd07100958cfeb2a2a4923426c9a26abddd15a4968345526ca325b20c
5
5
  SHA512:
6
- metadata.gz: 59922299e4267e9c62b32674e617d78bf088ebcca40a41e5c7d809228de1c01a1a1bacc4fd52f0b392f461909d7956e6dade28b1614cd6e7e39bb78af7700983
7
- data.tar.gz: dea00fa6c4271b7da95c1472ecaa4729c399847fa4022ec450a140f97b43bcf21b50e98ac6be2365397b12da5f64d02bb1d9de4fcbeb9b440764b10351ed7bee
6
+ metadata.gz: b53326c6b08843126fb30ea50a429e13751ecde1e87f7e20bb06125b82965f73f725d9a2c4a2681b9b17f5669886915941b46bf2d37d642087d9ca19063b6bbc
7
+ data.tar.gz: c1d4085bcaee66e094febb257aa246c3fc5163d91f38866d690f3fc5d30c7a3219e750793cf1267c757fbd5b6f2da6ca1ec5176b4ca5230c7afd11a8cf1a8c33
data/README.md CHANGED
@@ -1,39 +1,154 @@
1
1
  # ms-rb
2
2
 
3
- Ruby port of the popular [JavaScript library **ms** (by Vercel)](https://github.com/vercel/ms).
4
- Convert human-readable durations like `"2h"`, `"1.5d"`, `"3w"`, `"500ms"`
5
- **into milliseconds and back.**
3
+ [![Gem Version](https://badge.fury.io/rb/ms-rb.svg)](https://badge.fury.io/rb/ms-rb)
4
+ ![Build Status](https://github.com/armiiller/ms-rb/actions/workflows/ci.yml/badge.svg)
5
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](LICENSE)
6
+
7
+ A Ruby port of the popular [`ms`](https://github.com/vercel/ms) library from Vercel.
8
+
9
+ Convert human-friendly time strings like `"1h"`, `"2 days"`, `"3w"`, `"1.5mo"` into milliseconds — and convert milliseconds back into strings.
10
+
11
+ This gem aims to match the behavior of Vercel/ms, including:
12
+
13
+ - `ms("1h") -> 3600000`
14
+ - `ms(3600000) -> "1h"`
15
+ - Strict and non-strict parsing
16
+ - Long and short formatting
17
+ - Floating-point and negative values
18
+ - Full unit support (ms, s, m, h, d, w, mo, y)
19
+
20
+ ---
6
21
 
7
22
  ## Installation
8
23
 
24
+ Add to your Gemfile:
25
+
26
+ ```ruby
27
+ gem "ms-rb"
28
+ ```
29
+
30
+ Or install directly:
31
+
9
32
  ```bash
10
33
  gem install ms-rb
11
34
  ```
12
- Or add this line to your application's Gemfile:
35
+
36
+ Then require it:
13
37
 
14
38
  ```ruby
15
- gem 'ms-rb'
39
+ require "ms"
16
40
  ```
17
41
 
42
+ ---
43
+
18
44
  ## Usage
19
45
 
46
+ The main entrypoint is:
47
+
20
48
  ```ruby
21
- require "ms/rb"
49
+ Ms.ms(value, long: false)
50
+ ```
51
+
52
+ ### Parse a duration string → milliseconds
22
53
 
23
- Ms::Rb.ms("2h") # => 7200000
24
- Ms::Rb.parse("3d") # => 259200000
25
- Ms::Rb.format(1500) # => "2s"
26
- Ms::Rb.format(1500, long: true)
54
+ ```ruby
55
+ Ms.ms("2h") # => 7200000
56
+ Ms.ms("1.5d") # => 129600000
57
+ Ms.ms("3 weeks") # => 1814400000
58
+ Ms.ms("-10ms") # => -10
59
+ Ms.ms("1 s") # => 1000
60
+ ```
61
+
62
+ ### Format milliseconds → duration string
63
+
64
+ Short form:
65
+
66
+ ```ruby
67
+ Ms.ms(3600000) # => "1h"
68
+ Ms.ms(5400000) # => "2h"
69
+ ```
70
+
71
+ Long form:
72
+
73
+ ```ruby
74
+ Ms.ms(3600000, long: true) # => "1 hour"
75
+ Ms.ms(5400000, long: true) # => "2 hours"
76
+ ```
77
+
78
+ ### Strict parsing
79
+
80
+ ```ruby
81
+ Ms.parse_strict("1h") # => 3600000
82
+ Ms.parse_strict("foo") # => NaN
27
83
  ```
28
84
 
29
- Supports:
30
- - years (y)
31
- - months (mo)
32
- - weeks (w)
33
- - days (d)
34
- - hours (h)
35
- - minutes (m)
36
- - seconds (s)
37
- - milliseconds (ms)
85
+ ---
86
+
87
+ ## Supported Units
88
+
89
+ | Unit(s) | Meaning |
90
+ |----------------------------------------|--------------|
91
+ | `ms`, `msec`, `millisecond`, `milliseconds` | Milliseconds |
92
+ | `s`, `sec`, `second`, `seconds` | Seconds |
93
+ | `m`, `min`, `minute`, `minutes` | Minutes |
94
+ | `h`, `hr`, `hour`, `hours` | Hours |
95
+ | `d`, `day`, `days` | Days |
96
+ | `w`, `week`, `weeks` | Weeks |
97
+ | `mo`, `month`, `months` | Months |
98
+ | `y`, `yr`, `year`, `years` | Years |
99
+
100
+ Supports floats, negative values, and mixed case:
101
+
102
+ ```ruby
103
+ Ms.ms("1.5H") # => 5400000
104
+ Ms.ms("-.5h") # => -1800000
105
+ Ms.ms("53 YeArS") # => 1672552800000
106
+ ```
107
+
108
+ ---
109
+
110
+ ## API
111
+
112
+ ### `Ms.ms(value, long: false)`
113
+
114
+ Main entrypoint. Accepts:
115
+
116
+ - `String` → returns milliseconds (`Integer` or `Float`)
117
+ - `Numeric` → returns formatted string (`"1h"` or `"1 hour"`)
118
+
119
+ Example:
120
+
121
+ ```ruby
122
+ Ms.ms("2h") # => 7200000
123
+ Ms.ms(7200000) # => "2h"
124
+ Ms.ms(7200000, long: true) # => "2 hours"
125
+ ```
126
+
127
+ ### `Ms.parse(string)`
128
+
129
+ Non-strict parser.
130
+ Returns `NaN` for invalid input.
131
+
132
+ ### `Ms.parse_strict(string)`
133
+
134
+ Strict parser.
135
+ Raises on invalid input types, returns `NaN` for malformed strings.
136
+
137
+ ### `Ms.format(ms, long: false)`
138
+
139
+ Formats milliseconds directly.
140
+
141
+ ---
142
+
143
+ ## Testing
144
+
145
+ ```bash
146
+ bundle install
147
+ bundle exec rake test
148
+ ```
149
+
150
+ ---
151
+
152
+ ## License
38
153
 
39
- Follows the same parsing and formatting rules as the JavaScript library.
154
+ MIT © Austin Miller
data/lib/ms/rb/version.rb CHANGED
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Ms
4
4
  module Rb
5
- VERSION = "0.1.0"
5
+ VERSION = "0.1.1"
6
6
  end
7
7
  end
data/lib/ms.rb CHANGED
@@ -6,8 +6,8 @@ require_relative "ms/rb"
6
6
  module Ms
7
7
  module_function
8
8
 
9
- def ms(value, options = {})
10
- Rb.ms(value, options)
9
+ def ms(value, **options)
10
+ Rb.ms(value, **options)
11
11
  end
12
12
 
13
13
  def parse(str)
@@ -18,7 +18,7 @@ module Ms
18
18
  Rb.parse_strict(str)
19
19
  end
20
20
 
21
- def format(ms, options = {})
22
- Rb.format(ms, options)
21
+ def format(ms, **options)
22
+ Rb.format(ms, **options)
23
23
  end
24
24
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ms-rb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Austin Miller
8
8
  bindir: exe
9
9
  cert_chain: []
10
- date: 2025-11-30 00:00:00.000000000 Z
10
+ date: 2025-12-01 00:00:00.000000000 Z
11
11
  dependencies: []
12
12
  description: Parse and format durations like '2h', '1.5d', '3w', '500ms' into milliseconds
13
13
  and back.