prototypes
Advanced tools
Comparing version 0.0.1 to 0.0.2
@@ -10,8 +10,8 @@ 'use strict'; | ||
// requires | ||
var stringLib = require('./lib/string.js'); | ||
require('./lib/string.js'); | ||
var objectLib = require('./lib/object.js'); | ||
// exports | ||
objectLib.overwriteObject(exports, stringLib); | ||
objectLib.overwriteObject(exports, objectLib); | ||
@@ -46,3 +46,3 @@ 'use strict'; | ||
/** | ||
* Overwrite properties with the given object. | ||
* Overwrite properties in the original with the given object. | ||
*/ | ||
@@ -49,0 +49,0 @@ exports.overwriteObject = function(original, overwriter) |
{ | ||
"name": "prototypes", | ||
"version": "0.0.1", | ||
"version": "0.0.2", | ||
"description": "Some common prototypes for node.js.", | ||
@@ -5,0 +5,0 @@ "homepage": "https://github.com/alexfernandez/prototypes", |
113
README.md
@@ -0,1 +1,3 @@ | ||
[![Build Status](https://secure.travis-ci.org/alexfernandez/prototypes.png)](http://travis-ci.org/alexfernandez/prototypes) | ||
# prototypes | ||
@@ -5,1 +7,112 @@ | ||
## Installation | ||
Simply install using npm: | ||
npm install prototypes | ||
Or add to the dependencies of your project in your `package.json`. | ||
## Usage | ||
This package adds some useful prototypes to String. | ||
To use in your package, you just have to require prototypes: | ||
require('prototypes'); | ||
You do not need to assign the result to any variable, and in fact JSHint | ||
(and similar code checkers) may complain about an unused variable if you | ||
do this: | ||
var prototypes = require('prototypes'); | ||
This last form is required if you use any of the exported object functions. | ||
## String Prototypes | ||
The following string prototypes are provided. | ||
### startsWith(str) | ||
Check that the current string starts with the given substring. Example: | ||
'pepitus'.startsWith('pep'); | ||
\=> true | ||
### endsWith(str) | ||
Check that the current string ends with the given substring. Example: | ||
'pepitus'.startsWith('tus'); | ||
\=> true | ||
### substringUpTo(str) | ||
Return the piece of string until the argument is found. Example: | ||
'hi.there'.substringUpTo('.'); | ||
\=> 'hi' | ||
### substringUpToLast(str) | ||
Return the piece of string until the last occurrence of the argument. Example: | ||
'hi.there.you'.substringUpToLast('.'); | ||
\=> 'hi.there' | ||
### substringFrom(str) | ||
Return the piece of string starting with the argument; empty string if not found. | ||
Example: | ||
'hi.there'.substringFrom('.'); | ||
\=> 'there' | ||
### contains(str) | ||
Find out if the string contains the argument at any position. | ||
Example: | ||
'abcde'.contains('bcd'); | ||
\=> true | ||
### replaceAll(str) | ||
Replace all occurrences of a string with the replacement. | ||
Example: | ||
'pepitus'.replaceAll('p', 'c'); | ||
\=> 'cecitus' | ||
### repeat(number) | ||
Repeat the given string a few times. | ||
Example: | ||
'ab'.repeat(3); | ||
\=> 'ababab' | ||
## Object Functions | ||
For objects it is not wise to overwrite `Object.prototype`, since it will | ||
probably break all code that does not check for hasOwnProperty(). | ||
See [MSDN help](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/hasOwnProperty). | ||
Therefore a few utility functions are provided. | ||
### countProperties(object) | ||
Count the number of properties in an object. | ||
Does not count inherited properties: uses hasOwnProperty(). | ||
Example: | ||
prototypes.countProperties({a: 'a'}); | ||
\=> 1 | ||
### overwriteObject(original, overwrite) | ||
Overwrite properties in the original with the given object. | ||
Example: | ||
prototypes.overwriteObject({a: 'a'}, {b: 'b'}); | ||
\=> {a: 'a', b: 'b'} | ||
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
12593
10
118