Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Tableware is a tiny gem for making it easier to define data in a text table. Table rows are parsed into either arrays or hashes.
For example:
stats = ' Hero | Value | Hours Played
------------------------------------------
Phara | 10 | 22
Mercy | 9 | 11
Winston | 3 | 2 '
Tableware.arrays(stats)
# => [
['Phara', '10', '22'],
['Mercy', '9', '11'],
['Winston', '3', '2']
]
Tableware.hashes(stats)
#=> [
{ hero: 'Phara', value: '10', hours_played: 22 },
{ hero: 'Mercy', value: '9', hours_played: 11 },
{ hero: 'Winston', value: '3', hours_played: 2 }
]
Writing test data or a matrix of permissions in a big hash or nested array is fine, but it can be a pain to format and work with, especially for larger data sets or with items of very different lengths.
Tableware lets you use a more human friendly format so that you can more easily scan and understand the data.
The downside is that everything is treated as a string, so you may need to do some .to_i
ing to convert things back into the type you're expecting. However, this is a one-time cost and optimising for reading code is a good idea.
This isn't always going to be better than defining your data in another format, but it is another option. Or perhaps you just like Cucumber scenario outlines and want something similar in rspec!
You can focus a single row, to help with debugging, by prepending a line with >
.
For example:
words = ' Foo | Bar
> Yay | Woo
Zip | Zap '
Tableware.arrays(words)
#=> [ ['Yay', 'Woo'] ]
Running multiple rows cannot be achieved with prepending >
. Instead, use Enum#select (or reject
) to decide which lines to process. For the the previous example, you could achieve the same result using select as follows:
words = ' Foo | Bar
Yay | Woo
Zip | Zap '
Tableware.arrays(words).select{ |row| row.first == 'Yay' }
#=> [ ['Yay', 'Woo'] ]
This gem has been created as a quick experiment to see if or how often this feature could be useful. If you find it useful, please like it or better yet, extend it!
Add this line to your application's Gemfile:
gem 'tableware'
And then execute:
$ bundle
Or install it yourself as:
$ gem install tableware
Tableware accepts text tables following these rules:
|
character-
or =
characters|
characters on a row are optional; | A | B |
is the same as A | B
Tableware provides two main methods for getting your data back out of the table:
Tableware.arrays
returns an array of arraysTableware.hashes
returns an array of hashes, where the keys come from the headings rowBoth of these can be seen in use in the example at the top of this README.
Bug reports and pull requests are welcome on GitHub at https://github.com/AdamWhittingham/tableware. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the Contributor Covenant code of conduct.
The gem is available as open source under the terms of the MIT License.
FAQs
Unknown package
We found that tableware demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.