Giter Club home page Giter Club logo

jscpp's Introduction

JSCPP

I'm a JavaScript programmer. I don't like C++ (especially when I can't use C++11). Sadly, I have to use it for school. I come from a world of "performance be damned" and high-level APIs, not a C-like background. I wanted to like C++, I really did.

Because I'm not allowed to use code I didn't write, I couldn't use things like Boost -- I had to roll my own.

After three years of dealing with C++, I was fed up. Before returning for my final semesters, I decided to write a library that made C++ a little more familiar.

Goals

  • replicate significant parts of the JavaScript standard library in C++ for familiarity
  • ignore regexes and functional stuff (no forEach, for example) -- we're not trying to turn C++ into JavaScript
  • performance is not important
  • aimed at small projects for school, not for your big C++ project
  • don't overload == to be like == in JavaScript; make it like ===
  • each component should be independent -- Array.join shouldn't return my string, it should return an std::string

Pull requests are welcome!

Supported stuff

Array

from JavaScript

  • concat(Array) (only takes an array, unlike JavaScript)
  • indexOf(item)
  • join([string])
  • lastIndexOf(item)
  • length() (method, not a property)
  • pop()
  • push(item) (only takes one argument, unlike JavaScript)
  • reverse() (doesn't return the array, unlike JavaScript)
  • shift()
  • slice() (TODO)
  • sort() (TODO)
  • splice(index, howMany) (always takes two arguments, unlike JavaScript)
  • toString()
  • unshift(item) (only takes one argument, unlike JavaScript)

new stuff

  • contains(item) (alias of indexOf(item) != -1)
  • first() (get the first element)
  • isEmpty() (alias of length() == 0)
  • last() (get the last element)
  • size() (alias of length)
  • toStdVector() (returns a std::vector)

String

from JavaScript

  • operators: ==, +, +=, [] (not for assignment), !, <, >, <=, =>, ~
  • charAt(index)
  • charCodeAt(index)
  • concat(string)
  • contains(string) (strings only)
  • endsWith(string) (strings only)
  • String::fromCharCode(number) (only takes one argument, unlike JavaScript)
  • indexOf(string) (strings only)
  • lastIndexOf(string) (strings only)
  • length() (method, not a property)
  • replace(original, new) (strings only. Try replaceAll for global replace)
  • slice(beginSlice, [endSlice])
  • split (TODO)
  • startsWith(string)
  • substr (TODO)
  • substring (TODO)
  • toLowerCase()
  • toUpperCase()
  • trim()
  • trimLeft()
  • trimRight()

new stuff

  • isEmpty() (shorthand for length() == 0)
  • repeat(amount) (repeat a string)
  • replaceAll(original, new) (same API as replace but global)
  • size() (alias of length)
  • toStdString() (convert to std::string)

Math

from JavaScript

  • E, LN2, LN10, LOG2E, LOG10E, PI, SQRT1_2, SQRT2
  • abs(value)
  • acos(value), asin(value), atan(value), atan2(x, y)
  • ceil(value), floor(value)
  • exp(value)
  • log(value)
  • max(a, b), min(a, b) (only takes 2 arguments; not 100% compliant)
  • pow(base, exponent)
  • random()
  • round(value)
  • sin(value), cos(value), tan(value)
  • sqrt(value)

new stuff

  • sign(value) (returns 0, -1, or 1)

Utils

from JavaScript

  • parseInt(string) (alias of atoi; not 100% compliant with JavaScript)

Usage

For usage, see test.cpp. It aims to serve as example and test.

jscpp's People

Contributors

evanhahn avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.