
Security News
Browserslist-rs Gets Major Refactor, Cutting Binary Size by Over 1MB
Browserslist-rs now uses static data to reduce binary size by over 1MB, improving memory use and performance for Rust-based frontend tools.
keystone-storage-namefunctions
Advanced tools
Simple functions for generating filenames.
Bundled with KeystoneJS
contentHashFilename
Calculate the filename from the sha1 hash of the file
contentsoriginalFilename
Return the original filename provided in the file objectrandomFilename
Generate a random filenameprototypeMethods
Two methods are included to help reduce code repetition in adapters that can be
added to the adapter prototype
when you want to handle filename generation:
getFilename
- used to generate a filename for a given file
objectretryFilename
- used to retry a number of times when the whenExists
option value is "retry"
(see below)These methods both depend on a fileExists(filename, callback)
method being
implemented on the adapter, and an options
object on the adapter instance
with the following keys:
options.generateFilename
- a method to generate the filename, e.g. from
this packageoptions.whenExists
- one of "overwrite"
, "error"
or "retry"
options.retryAttempts
- the maximum number of retry attempts when the
whenExists
option value is "retry"
Use them like this:
var prototypeMethods = require('keystone-storage-namefunctions/prototypeMethods');
Adapter.prototype.getFilename = prototypeMethods.getFilename;
Adapter.prototype.retryFilename = prototypeMethods.retryFilename;
Adapter.prototype.fileExists = function (filename, callback) {
var result = false; // replace with actual logic
callback(null, result);
}
Adapter.prototype.uploadFile = function (file, callback) {
this.getFilename(file, function (err, filename) {
// move the file into place
});
};
ensureCallback
utilityThe ensureCallback
method is also included, to standardise sync filename
method call signatures. Use it like this:
var ensureCallback = require('keystone-storage-namefunctions/ensureCallback');
function originalFilename (file, index) {
return file.originalname;
}
var asyncOriginalFilename = ensureCallback(originalFilename);
asyncOriginalFilename(file, index, function (err, result) {
// result === file.originalname
});
Licensed under The MIT License. Copyright (c) 2016 Jed Watson
FAQs
Simple functions for generating filenames
The npm package keystone-storage-namefunctions receives a total of 898 weekly downloads. As such, keystone-storage-namefunctions popularity was classified as not popular.
We found that keystone-storage-namefunctions 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
Browserslist-rs now uses static data to reduce binary size by over 1MB, improving memory use and performance for Rust-based frontend tools.
Research
Security News
Eight new malicious Firefox extensions impersonate games, steal OAuth tokens, hijack sessions, and exploit browser permissions to spy on users.
Security News
The official Go SDK for the Model Context Protocol is in development, with a stable, production-ready release expected by August 2025.