Security News
tea.xyz Spam Plagues npm and RubyGems Package Registries
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
ksuid
Advanced tools
Readme
A Node.js implementation of Segment's KSUID library.
You may also be interested in ksuid-cli
.
$ npm install ksuid
Require the module:
const KSUID = require('ksuid')
You can create a new instance synchronously:
const ksuidFromSync = KSUID.randomSync()
Or asynchronously:
const ksuidFromAsync = await KSUID.random()
You can also specify a specific time, either in milliseconds or as a Date
object:
const ksuidFromDate = KSUID.randomSync(new Date("2014-05-25T16:53:20Z"))
const ksuidFromMillisecondsAsync = await KSUID.random(1401036800000)
Or you can compose it using a timestamp and a 16-byte payload:
const crypto = require('crypto')
const yesterdayInMs = Date.now() - 86400 * 1000
const payload = crypto.randomBytes(16)
const yesterdayKSUID = KSUID.fromParts(yesterdayInMs, payload)
You can parse a valid string-encoded KSUID:
const maxKsuid = KSUID.parse('aWgEPTl1tmebfsQzFP4bxwgy80V')
Finally, you can create a KSUID from a 20-byte buffer:
const fromBuffer = new KSUID(buffer)
Once the KSUID has been created, use it:
ksuidFromSync.string // The KSUID encoded as a fixed-length string
ksuidFromSync.raw // The KSUID as a 20-byte buffer
ksuidFromSync.date // The timestamp portion of the KSUID, as a `Date` object
ksuidFromSync.timestamp // The raw timestamp portion of the KSUID, as a number
ksuidFromSync.payload // A Buffer containing the 16-byte payload of the KSUID (typically a random value)
You can compare KSUIDs:
todayKSUID.compare(yesterdayKSUID) // 1
todayKSUID.compare(todayKSUID) // 0
yesterdayKSUID.compare(todayKSUID) // -1
And check for equality:
todayKSUID.equals(todayKSUID) // true
todayKSUID.equals(yesterdayKSUID) // false
You can check whether a particular buffer is a valid KSUID:
KSUID.isValid(buffer) // Boolean
FAQs
Node.js implementation of K-Sortable Globally Unique IDs
The npm package ksuid receives a total of 149,590 weekly downloads. As such, ksuid popularity was classified as popular.
We found that ksuid 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.
Security News
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
Security News
As cyber threats become more autonomous, AI-powered defenses are crucial for businesses to stay ahead of attackers who can exploit software vulnerabilities at scale.
Security News
UnitedHealth Group disclosed that the ransomware attack on Change Healthcare compromised protected health information for millions in the U.S., with estimated costs to the company expected to reach $1 billion.