Crescent.js logoCrescent.jsv1.0.3
Reference

API Reference

A complete reference for every Crescent.js method.

Convention

Core methods are called on the crescent instance, database methods on crescent.db, and authentication methods on crescent.auth.

page()

Creates a new page container.

js
const page = crescent.page({
  page_id: 'home',
  page_title: 'Home',
  page_description: 'Home page',
  size: { height: 900, width: 1440 }
});
PropertyTypeRequiredDescription
page_idstringyesUnique identifier
page_titlestringnoBrowser tab title
page_descriptionstringnoMeta description
sizeobjectyes{ height, width } in pixels

object()

Creates a container for layers.

js
crescent.object({
  object_id: 'header',
  size: { height: 80, width: 600 },
  page_position: { x: 0, y: 0 }
});
PropertyTypeRequiredDescription
object_idstringyesUnique identifier
sizeobjectyes{ height, width }
page_positionobjectnoCartesian { x, y }
page_indexnumbernoStacking order on the page
bg_layerstringnoLayer rendered behind the object
object_enabledbooleannoWhether the object renders (default true)

layer()

Creates a visual element. Requires layer_type and layer_id.

js
crescent.layer({
  layer_type: 'text',
  layer_id: 'title',
  text: 'Hello',
  size: 32,
  colour: '0,0,0'
});
PropertyTypeRequiredDescription
layer_typestringyestext, image, shape, input
layer_idstringyesUnique identifier
textstringnoText content (text and shape layers)
sizenumber | objectnoFont size for text, or { height, width } for image/shape/input
colourstringnoColour as 'r,g,b' (text and shape layers)
image_locationstringnoImage URL (image layers)
layer_verticesnumbernoNumber of sides, e.g. 4 for a rectangle (shape layers)
input_methodstringnoInput style, e.g. 'text box' (input layers)

function()

Defines a reusable backend function.

js
crescent.function({
  function_id: 'add',
  params: ['a', 'b'],
  body: function (a, b) {
    return a + b;
  }
});

crescent.get_function('add').call(2, 3); // 5
PropertyTypeRequiredDescription
function_idstringyesUnique identifier
paramsstring[]noArgument names
bodyfunctionyesExecutes when called

api_make()

Creates an HTTP server with endpoints.

js
const api = crescent.api_make({
  api_id: 'main',
  port: 3000
});

api.add_endpoint('GET', '/users', function (req, res) {
  res.writeHead(200, { 'Content-Type': 'application/json' });
  res.end(JSON.stringify({ users: [] }));
});

api.start();
MethodDescription
add_endpoint(method, path, handler)Registers a route. method is GET, POST, PUT, or DELETE; handler receives Node.js req and res
start()Starts listening on the configured port

api_call()

Makes an outgoing HTTP request.

js
const request = crescent.api_call({
  api_call_id: 'fetch_users',
  url: 'https://api.example.com/users',
  method: 'GET'
});

request.call().then(function (data) {
  console.log(data);
});

Database Methods

Called on crescent.db. Data is stored in collections.

MethodDescription
create(collection)Creates a new collection
insert(collection, doc)Inserts a record and returns it with its _id
insert_many(collection, docs)Inserts multiple records at once
find(collection, query)Returns all records matching a query
find_one(collection, query)Returns the first record matching a query
find_by_id(collection, id)Finds a record by _id
update(collection, query, updates)Updates all records matching a query
update_one(collection, query, updates)Updates the first record matching a query
delete(collection, query)Deletes all records matching a query

Auth Methods

Called on crescent.auth.

MethodDescription
signup().register(username, email, password)Creates a new user account
login().authenticate(username, password)Validates credentials, returns the user, a session token, and a cookie header
login().verify_session(token)Verifies a session token
password.hash(password)Returns { hash, salt }
password.verify(password, hash, salt)Checks a password against a stored hash
password.check_strength(password)Returns a strength score and label
oauth().add_provider(name, config)Configures an OAuth provider
oauth().get_authorize_url(provider)Builds the authorization URL for a provider

Page Methods

MethodDescription
add_object(object)Adds an object to the page
set_object_position(object_id, x, y)Sets an object's cartesian position
render()Renders the page into the DOM

Next Steps