Security News
Introducing the Socket Python SDK
The initial version of the Socket Python SDK is now on PyPI, enabling developers to more easily interact with the Socket REST API in Python projects.
Formulon is a Parser for Salesforce Formulas completely written in ECMA Script 2015. It is the engine behind formulon.io.
Featured on Phil's Tip of the Week
This method will return a object holding value and its metadata
import { parse } from 'formulon'
parse('IF(TRUE, "True String", "False String")')
// {
// type: 'literal',
// value: 'True String',
// dataType: 'text',
// options: { length: 11 }
// }
type
: Metadata from the parser (always literal
)
value
: The value of the result always as a string
dataType
: The type of the return (currently number
, text
, checkbox
, date
, time
, datetime
, geolocation
or null
)
options
: different options per data type
Currently the following data types are supported (naming is taken from the Salesforce Field Types):
Options depend on the data type:
no options
Whenever an error occurs, an according object is returned:
parse('IF(TRUE)')
// {
// type: 'error',
// errorType: 'ArgumentError',
// message: "Incorrect number of parameters for function 'IF()'. Expected 3, received 1",
// function: 'if',
// expected: 3,
// received: 1,
// }
It's possible to specify formulas that contain variables. In that case pass the value of the variable in as a second argument:
parse('IF(Variable__c, "True String", "False String")', {Variable__c: {type: 'literal', dataType: 'checkbox', value: true}})
// {
// type: 'literal',
// value: 'True String',
// dataType: 'text',
// options: { length: 11 }
// }
You'll have to provide the variable in the form:
{
type: 'literal',
value: <the actual value as a JS type>,
dataType: <the salesforce field type specified above>,
options: <salesforce field options>
}
Utility function that returns a list of used variables
extract('IF(Variable__c, Variable__c, AnotherVariable__c)')
// [ 'Variable__c', 'AnotherVariable__c' ]
Return the abstract syntax tree built from the formula.
ast('IF(Variable__c, "True String", "False String")')
// {
// "type": "callExpression",
// "id": "if",
// "arguments": [
// {
// "type": "identifier",
// "name": "Variable__c"
// },
// {
// "type": "literal",
// "value": "True String",
// "dataType": "text",
// "options": {
// "length": 11
// }
// },
// {
// "type": "literal",
// "value": "False String",
// "dataType": "text",
// "options": {
// "length": 12
// }
// }
// ]
// }
Formulon exists thanks to the following people who have contributed.
FAQs
Salesforce Formula Parser
The npm package formulon receives a total of 154 weekly downloads. As such, formulon popularity was classified as not popular.
We found that formulon demonstrated a healthy version release cadence and project activity because the last version was released less than 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
The initial version of the Socket Python SDK is now on PyPI, enabling developers to more easily interact with the Socket REST API in Python projects.
Security News
Floating dependency ranges in npm can introduce instability and security risks into your project by allowing unverified or incompatible versions to be installed automatically, leading to unpredictable behavior and potential conflicts.
Security News
A new Rust RFC proposes "Trusted Publishing" for Crates.io, introducing short-lived access tokens via OIDC to improve security and reduce risks associated with long-lived API tokens.