Skip to content
Adam Smith edited this page Mar 3, 2016 · 11 revisions

vitals.get npm version

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

get

Gets keys, indexes, values, or substrings from an object, array, or string.

Examples

Params

  1. 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)
  1. 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

get.keys

Gets an array of keys from an object.

Examples

Params

  1. source (!Object|function)
If no val param is defined this method will return an array of all an object's own keys.
  1. 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

get.keys.byKey

Gets an array of keys from an object that match a pattern.

Examples

Params

  1. source (!Object|function)
  2. pattern *
If pattern is not a `RegExp` or string it is converted to a string.

Returns !Array

get.keys.byValue

Gets an array of keys from an object where the value === val.

Examples

Params

  1. source (!Object|function)
  2. val *

Returns !Array

get.indexes

Gets an array of indexes from an array or string by value/pattern.

Examples

Params

  1. 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.
  1. 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

get.values

Gets an array of values/substrings from an object or string.

Examples

Params

  1. 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.
  1. 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

get.file

Gets the contents of a file.

Examples

Params

  1. filepath string
  2. 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)

get.dirpaths

Gets all of the directory paths in a directory.

Examples

Params

  1. dirpath string
Must be a valid directory.
  1. 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

get.filepaths

Gets all of the file paths in a directory.

Examples

Params

  1. dirpath string
Must be a valid directory.
  1. 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,

Algorithm IV Logo

Clone this wiki locally