-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Rewriting the "Custom functions" section of node-sass document #17
Comments
Introduction of Sass functions from the official document Docs of api function of libSass |
Draft of the PR
|
|
ajhsu
changed the title
Rewriting the document of functions section of node-sass
Rewriting the "Custom functions" section of node-sass document
Oct 6, 2017
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
functions (>= v3.0.0) - experimental
This is an experimental LibSass feature. Use with caution.
// Mention about internal functions
Like these useful functions Sass provided out of box, you can implement your own functions as well.
functions
is anObject
that holds a collection of custom functions that may be invoked by the sass files being compiled.Function Signature (String)
Function signature is a plain JavaScript string that should be written in following function declaration syxtax:
"function-name($param1, $param2, $param3)"
For example:
"custom-url($path)": function (path) { }
So that you can call custom function within your Sass files:
background-image: custom-url('/images/example.jpg');
Since function signatures are also part of SassScript, few things should be remind:
Callback (Function)
Callback may take zero or more input parameters and must return a value either synchronously (
return ...;
) or asynchronously (done();
). Those parameters will be instances of one of the constructors contained in therequire('node-sass').types
hash. The return value must be of one of these types as well. See the list of available types below:types.Number(value [, unit = ""])
getValue()
/setValue(value)
: gets / sets the numerical portion of the numbergetUnit()
/setUnit(unit)
: gets / sets the unit portion of the numbertypes.String(value)
getValue()
/setValue(value)
: gets / sets the enclosed stringtypes.Color(r, g, b [, a = 1.0]) or types.Color(argb)
getR()
/setR(value)
: red component (integer from0
to255
)getG()
/setG(value)
: green component (integer from0
to255
)getB()
/setB(value)
: blue component (integer from0
to255
)getA()
/setA(value)
: alpha component (number from0
to1.0
)Example:
types.Boolean(value)
getValue()
: gets the enclosed booleantypes.Boolean.TRUE
: Singleton instance oftypes.Boolean
that holds "true"types.Boolean.FALSE
: Singleton instance oftypes.Boolean
that holds "false"types.List(length [, commaSeparator = true])
getValue(index)
/setValue(index, value)
:value
must itself be an instance of one of the constructors insass.types
.getSeparator()
/setSeparator(isComma)
: whether to use commas as a separatorgetLength()
types.Map(length)
getKey(index)
/setKey(index, value)
getValue(index)
/setValue(index, value)
getLength()
types.Null()
types.Null.NULL
: Singleton instance oftypes.Null
.Example
The text was updated successfully, but these errors were encountered: