utils.d.ts 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. import type { FunctionNode, WordNode, Node } from 'postcss-value-parser';
  2. export declare function turnToRad(turn: number): number;
  3. export declare function degToRad(deg: number): number;
  4. export declare function gradToRad(grad: number): number;
  5. export declare function radToDeg(rad: number): number;
  6. export declare function gradToDeg(grad: number): number;
  7. export declare function turnToDeg(turn: number): number;
  8. declare const toRad: {
  9. turn: typeof turnToRad;
  10. deg: typeof degToRad;
  11. grad: typeof gradToRad;
  12. };
  13. declare const toDeg: {
  14. grad: typeof gradToDeg;
  15. turn: typeof turnToDeg;
  16. rad: typeof radToDeg;
  17. };
  18. export declare function filterOnlyWords(node: Node): boolean;
  19. /**
  20. * Try to compute a calculation from a Node.
  21. *
  22. * This validates that the calculation has a valid order which is:
  23. * - `{Number} {Operation} {Number} ...`
  24. *
  25. * Only basic arithmetic operations are allowed, and it has to be separate words
  26. * similarly to how CSS calc works:
  27. *
  28. * - `sin(3.14159 * 2)` -> is valid
  29. * - `sin(3.14159*2)` -> is not valid
  30. *
  31. *
  32. * @param {FunctionNode} nodes Nodes to be parsed
  33. * @param {Boolean} ignoreUnit Whether units are ignored or converted to radians
  34. * @return {FunctionNode} Returns the node, if it managed to calculate, it will
  35. * simplify inner nodes.
  36. * @see https://www.w3.org/TR/css-values-4/#trig-funcs
  37. */
  38. export declare function computeCalculation(nodes: Node[], ignoreUnit?: boolean): Node[];
  39. export declare function functionNodeToWordNode(fn: FunctionNode): WordNode;
  40. /**
  41. * Formats a number that's intended to be put into CSS.
  42. *
  43. * Due to processing of Number(number.toFixed(decimals)) this will get
  44. * rid of ending zeroes, usually helping with the rounding which is the
  45. * intended effect.
  46. *
  47. * For example, converting 4.71238898038469 radians into deg leads to
  48. * 270.000000000669786 which is going to result as 270 unless a
  49. * precision of 10 is chosen.
  50. *
  51. * @param {Number} number Number to be formatted
  52. * @param {Number} decimals Precision of decimals, CSS doesn't usually handle further than 5.
  53. */
  54. export declare function formatResultingNumber(number: number, decimals: number): string;
  55. export declare function parseNumber(value: string): false | {
  56. number: any;
  57. unit: string;
  58. };
  59. declare type validateNodeReturn = [WordNode, number] | undefined;
  60. export declare function validateNode(node: FunctionNode, parseUnit?: boolean): validateNodeReturn;
  61. export { toRad, toDeg };