Grind comes packaged with grind-support
which is a collection of helpers you can use within your app.
As grind-support
comes with grind-framework
, there’s no need to explicitly add it to your package.json
file.
FS
includes a fully promised based implementation of Node’s fs module. On Node 8+ Platforms, FS
takes advantage Node’s promisify
utility while falling back to a manual implementation on older platforms.
In additional to the standard methods provided by fs
, the FS
class includes the following additional functionality:
A promise based implementation of mkdirp.
Alias of mkdirp
.
The touch
method allows you to update the timestamp of a file.
pathname
— The path to touchtime
— Optionally specify a time to set, defaulting to the current time.
A promise based implementation of recursive-readdir.
Inflect provides an instance of the i package.
The merge
function recursively merges objects & arrays, returning a new object:
lhs
— The object or array to merge intorhs
— The object or array to merge from, any values in bothlhs
andrhs
will be overwritten byrhs
.
const merged =
The merged
variable will now be the following object:
get
allows you to get values from nested object by using a key path.
object
— Target object to querykeyPath
— The key path to find the value forfallback
— Optional value to fallback to if the key path doesn’t exist.
Obj// True
has
allows you to check if a value exists within a nested object by using a key path.
object
— Target object to checkkeyPath
— The key path to see if there’s a value for
Obj// TrueObj// false
has
allows you to set a value within a nested object by using a key path.
object
— Target object to updatekeyPath
— The key path to set a value onvalue
— The value to set
Obj
filter
allows you to filter an object by key or value.
object
— Target object to filterfilter
— A callback function used to test if a key/value should be included.
Obj// Results in `{ a: false, b: true }` with `c` being filtered out
only
allows you to return an object containing only the whitelisted keys
object
— Target object to filterkeys
— An array or set of keys to allow
Obj// Results in `{ a: false, c: false }` with `b` being excluded
except
is the opposite of only
and allows you to return an object excluding any blacklisted keys
object
— Target object to filterkeys
— An array or set of keys to ignore
Obj// Results in `{ b: true, c: false }` with `a` being excluded
ascii
will convert a string of unicode characters and attempt to convert them to ascii characters and otherwise stripping them if it’s unable to do so.
str
— Target stroptions.charmap
— Override the default charmap to change howascii
converts charactersoptions.lower
— Convert all characters to lowercase if true
Str // `Grind Framework`Str // `c 2017`Str // `25euro`Str // `Emoji`
slug
will first call Str.ascii
to convert any non-ascii characters to their ascii counterparts, strip any non-alphanumberic characters and finally replace any whitespace with a dash.
str
— Target stroptions.charmap
— Override the default charmap to change howascii
converts charactersoptions.separator
— Override the default separator used to replace whitespaceoptions.lower
— Convert all characters to lowercase if true
Str // `grind-framework`Str // `grind_framework`
You can use any of the aforementioned helpers by importing them from the grind-support
package:
Log // Outputs grind-framework
Edit
grind-support
is not directly dependent on Grind, so you can safely use it in non-Grind based projects.