-
Notifications
You must be signed in to change notification settings - Fork 1
vitals.get
Adam Smith edited this page Mar 3, 2016
·
11 revisions
Method | Section | Alias |
---|---|---|
get | base | |
get.keys | base | |
get.keys.byKey | base | |
get.keys.byValue | base | get.keys.byVal |
get.indexes | base | get.ii |
get.values | base | get.vals |
get.file | fs | |
get.dirpaths | fs | |
get.filepaths | fs |
Gets keys, indexes, values, or substrings from an object, array, or string.
Params
-
source
!(Object|function|Array|string)
If no val param is defined this method will return the following values (per source type):
- object: array of own keys
- array: array of indexes
- string: an error (i.e. a val is required for string sources)
-
val
*=
For a `RegExp` val and object/string source this method will return the following values (per source type):
- object: an array of source values where the key [matches](https://github.com/imaginate/vitals/wiki/vitals.has#haspattern) the val
- string: an array of substrings that [match](https://github.com/imaginate/vitals/wiki/vitals.has#haspattern) the val
Otherwise this method will return the following values (per source type):
- object: an array of source keys where the `value === val`
- array: an array of source indexes where the `value === val`
- string: an array of starting indexes where `substring === String(val)`
Returns !Array
Gets an array of keys from an object.
Params
-
source
(!Object|function)
If no val param is defined this method will return an array of all an object's own keys.
-
val
*=
This method will return an array of source keys where the key [matches](https://github.com/imaginate/vitals/wiki/vitals.has#haspattern) the val if the val is a `RegExp`. Otherwise this method will return an array of source keys where the `value === String(val)`.
Returns !Array
Gets an array of keys from an object that match a pattern.
Params
-
source
(!Object|function)
-
pattern
*
If pattern is not a `RegExp` or string it is converted to a string.
Returns !Array
Gets an array of keys from an object where the value === val
.
Params
-
source
(!Object|function)
-
val
*
Returns !Array
Gets an array of indexes from an array or string by value/pattern.
Params
-
source
(!Object|string)
If no val param is defined this method will return an array of all an array's indexes or throw an error if the source is a string.
-
val
*=
This method returns the indexes by one of the following (per source type):
- array: Return an array of indexes where the `value === val`.
- string: A non-regex val is converted to a string and then an array of starting indexes that [match](https://github.com/imaginate/vitals/wiki/vitals.has#haspattern) the val are returned.
Returns !Array
Gets an array of values/substrings from an object or string.
Params
-
source
(!Object|function|string)
If no val param is defined this method will return an array of all the object's values or an error if the source is a string.
-
val
*=
If the val is not a `RegExp` or string it is converted to a string. This method will return the following values (per source type):
- object: an array of source values where the key [matches](https://github.com/imaginate/vitals/wiki/vitals.has#haspattern) the val
- string: an array of substrings that [match](https://github.com/imaginate/vitals/wiki/vitals.has#haspattern) the val
Returns !Array
Gets the contents of a file.
Params
-
filepath
string
-
opts
(boolean|Object)=
A boolean value sets opts.buffer.
- **opts.buffer** <i>` boolean= `</i>
default value: ` false `
If `true` a buffer is returned.
- **opts.encoding** <i>` string= `</i>
default value: ` "utf8" `
- **opts.eol** <i>` ?string= `</i>
default value: ` "LF" `
The end of line character to use when normalizing the result. If opts.eol is `null` or opts.buffer is `true` no normalization is completed. Optional values:
- `"LF"`
- `"CR"`
- `"CRLF"`
Returns (!Buffer|string)
Gets all of the directory paths in a directory.
Params
-
dirpath
string
Must be a valid directory.
-
opts
(boolean|Object)=
A boolean value sets opts.deep.
- **opts.deep** <i>` boolean= `</i>
default value: ` false `
Whether to include sub directories.
- **opts.recursive** <i>` boolean= `</i>
Alias for opts.deep.
- **opts.base** <i>` boolean= `</i>
default value: ` false `
Whether to append the base dirpath to the results.
- **opts.basepath** <i>` boolean= `</i>
Alias for opts.base.
- **opts.validDirs** <i>` (RegExp|Array<string>|?string)= `</i>
If string use `"|"` to separate valid directory names.
- **opts.invalidDirs** <i>` (RegExp|Array<string>|?string)= `</i>
If string use `"|"` to separate invalid directory names.
Returns !Array
Gets all of the file paths in a directory.
Params
-
dirpath
string
Must be a valid directory.
-
opts
(boolean|Object)=
A boolean value sets opts.deep.
- **opts.deep** <i>` boolean= `</i>
default value: ` false `
Whether to include sub-directory files.
- **opts.recursive** <i>` boolean= `</i>
Alias for opts.deep.
- **opts.base** <i>` boolean= `</i>
default value: ` false `
Whether to append the base dirpath to the results.
- **opts.basepath** <i>` boolean= `</i>
Alias for opts.base.
- **opts.validDirs** <i>` (RegExp|Array<string>|?string)= `</i>
- **opts.validExts** <i>` (RegExp|Array<string>|?string)= `</i>
[.]ext
- **opts.validNames** <i>` (RegExp|Array<string>|?string)= `</i>
filename
- **opts.validFiles** <i>` (RegExp|Array<string>|?string)= `</i>
filename.ext
- **opts.invalidDirs** <i>` (RegExp|Array<string>|?string)= `</i>
- **opts.invalidExts** <i>` (RegExp|Array<string>|?string)= `</i>
[.]ext
- **opts.invalidNames** <i>` (RegExp|Array<string>|?string)= `</i>
filename
- **opts.invalidFiles** <i>` (RegExp|Array<string>|?string)= `</i>
filename.ext
Returns !Array
-- Happy Developing,