Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

castor-load-custom

Package Overview
Dependencies
Maintainers
2
Versions
15
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

castor-load-custom

custom loader for castor

  • 1.1.2
  • unpublished
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
0
Maintainers
2
Weekly downloads
 
Created
Source

Customizable loader for castor

Create, transform, compute new fields and more ... see castor-load

You can create new fields in each document, by tweaking the ad hoc JSON configuration file (the one located besides the data directory you give to castor, or the one you give in parameters).

customFields

All the settings concerning custom fields are put in customFields key in that configuration file.

If you want ot create a fields.title key in your documents, add:

"customFields": {
  "title" : {
    "path" : "content.json.Ti"
  }
}

The path key points to a location inside the original document, using the dot notation.

There are many options (keys like path) you can use, see Options.

Note: the generated fields are truncated at 250 characters (if they are of string type).

Multivalued fields

Maybe your fields are multivalued, for example, if you load csv files.

For example, in a Keywords columns, you have such values:

Dashboard; Nodejs; Github
Web; Dashboard; Statistics

The direct way, is to point to content.json.keywords, but that will distinguish the Dashboard from the first row to the one from the second row. Moreover, they will be bound to other keywords on the same row.

The solution is to add a custom field in the JSON configuration file:

"customFields" : {
  "Keywords" :  {
    "path" : "content.json.Keywords",
    "separator" : ";"
  }
},

Options

TODO

path

Dotted notation to a field within the original document. Required (with the exception of compute)

Ex:

"customFields" : {
  "doi" : {
    "path" : "content.json.doi"
  }
}

label

Label (in UTF-8, without any constraint): the name of the field to display in pages of the application. Optional

Ex:

"customFields" : {
  "doi" : {
    "label" : "Document Object Identifier"
  }
}

Values can be multiform:

  • array of objects: [{ "lang" : "XX", "$t": "The label" }]
  • object: { "en" : "Hello", "fr": "Bonjour" }
  • string

default

Default value, used when the field has no value (for example when the path is not present in the document). Optional

Ex:

"customFields" : {
  "title" : {
    "default" : "No title given"
  }
}

glue

When the already computed field is an array, and that glue is set, each value of the array is joined in a string, using glue between every value. Optional

transform

Apply any stringjs chain to the field's value. Optional

Ex:

"customFields" : {
  "slug" : {
    "path" : "content.json.title"
    "transform" : "slugify()"
  }
}

textizer

Apply any stringjs chain to the field's value, then add the result to the fulltext index of the document. Optional

Ex:

"customFields" : {
  "title" : {
    "path" : "content.json.title"
    "textizer" : "toString()"
  }
}

Ex:

"customFields" : {
  "Keywords" : {
    "path" : "content.json.Kw"
    "textizer" : "ensureRight(' ')"
  }
}

Note: for fulltext search to work, you have to enable it in mongodb. For that, add to your mongodb.conf (maybe located in /etc/mongodb.conf):

setParameter=textSearchEnabled=true

separator

Split the fields' value into an array, depending on the separator. Optional

Ex:

"customFields" : {
  "Keywords" :  {
    "path" : "content.json.Keywords",
    "separator" : ";"
  }
},

type

Transtype the custom field value, in order to be used with another type than string by compute, or used by a filter... (values: boolean, string, text, number, date). Optional

Ex:

"customFields" : {
  "Year" :  {
    "path" : "content.json.Py",
    "type" : "number"
  }
},

pattern

Mask (or pattern) used to validate the variable. Optional

Values depend on type:

  • REGEX for text and string
  • date format for date

compute

Compute a funex expression, on the already generated customFields. You can access to the customFields.Year simply using Year.

Ex:

"customFields" : {
  "Authors" :  {
    "path" : "content.json.Af",
    "separator" : ";"
  }
  "AuthorNb" : {
    "compute" : "Authors.length"
  }
},

visible

Set it to true to indicate that this custom field should appear whenever the theme needs to display custom fields. Optional (default value: false)

Ex:

"customFields" : {
  "Authors" :  {
    "path" : "content.json.Af"
    "visible" : true
  }
  "authors" : {
    "path" : "content.json.Af"
    "separator" : ";"
  }
},

Keywords

FAQs

Package last updated on 15 Oct 2014

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc